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
11use super::api_types::{rpc_methods, *};
12use super::session_events::SessionMode;
13use crate::session::Session;
14use crate::{Client, Error};
15
16/// Typed view over the [`Client`]'s server-level RPC namespace.
17#[derive(Clone, Copy)]
18pub struct ClientRpc<'a> {
19    pub(crate) client: &'a Client,
20}
21
22impl<'a> ClientRpc<'a> {
23    /// `account.*` sub-namespace.
24    pub fn account(&self) -> ClientRpcAccount<'a> {
25        ClientRpcAccount {
26            client: self.client,
27        }
28    }
29
30    /// `mcp.*` sub-namespace.
31    pub fn mcp(&self) -> ClientRpcMcp<'a> {
32        ClientRpcMcp {
33            client: self.client,
34        }
35    }
36
37    /// `models.*` sub-namespace.
38    pub fn models(&self) -> ClientRpcModels<'a> {
39        ClientRpcModels {
40            client: self.client,
41        }
42    }
43
44    /// `secrets.*` sub-namespace.
45    pub fn secrets(&self) -> ClientRpcSecrets<'a> {
46        ClientRpcSecrets {
47            client: self.client,
48        }
49    }
50
51    /// `sessionFs.*` sub-namespace.
52    pub fn session_fs(&self) -> ClientRpcSessionFs<'a> {
53        ClientRpcSessionFs {
54            client: self.client,
55        }
56    }
57
58    /// `sessions.*` sub-namespace.
59    pub fn sessions(&self) -> ClientRpcSessions<'a> {
60        ClientRpcSessions {
61            client: self.client,
62        }
63    }
64
65    /// `skills.*` sub-namespace.
66    pub fn skills(&self) -> ClientRpcSkills<'a> {
67        ClientRpcSkills {
68            client: self.client,
69        }
70    }
71
72    /// `tools.*` sub-namespace.
73    pub fn tools(&self) -> ClientRpcTools<'a> {
74        ClientRpcTools {
75            client: self.client,
76        }
77    }
78
79    /// Checks server responsiveness and returns protocol information.
80    ///
81    /// Wire method: `ping`.
82    ///
83    /// # Parameters
84    ///
85    /// * `params` - Optional message to echo back to the caller.
86    ///
87    /// # Returns
88    ///
89    /// Server liveness response, including the echoed message, current server timestamp, and protocol version.
90    pub async fn ping(&self, params: PingRequest) -> Result<PingResult, Error> {
91        let wire_params = serde_json::to_value(params)?;
92        let _value = self
93            .client
94            .call(rpc_methods::PING, Some(wire_params))
95            .await?;
96        Ok(serde_json::from_value(_value)?)
97    }
98
99    /// Performs the SDK server connection handshake and validates the optional connection token.
100    ///
101    /// Wire method: `connect`.
102    ///
103    /// # Parameters
104    ///
105    /// * `params` - Optional connection token presented by the SDK client during the handshake.
106    ///
107    /// # Returns
108    ///
109    /// Handshake result reporting the server's protocol version and package version on success.
110    pub async fn connect(&self, params: ConnectRequest) -> Result<ConnectResult, Error> {
111        let wire_params = serde_json::to_value(params)?;
112        let _value = self
113            .client
114            .call(rpc_methods::CONNECT, Some(wire_params))
115            .await?;
116        Ok(serde_json::from_value(_value)?)
117    }
118}
119
120/// `account.*` RPCs.
121#[derive(Clone, Copy)]
122pub struct ClientRpcAccount<'a> {
123    pub(crate) client: &'a Client,
124}
125
126impl<'a> ClientRpcAccount<'a> {
127    /// Gets Copilot quota usage for the authenticated user or supplied GitHub token.
128    ///
129    /// Wire method: `account.getQuota`.
130    ///
131    /// # Returns
132    ///
133    /// Quota usage snapshots for the resolved user, keyed by quota type.
134    pub async fn get_quota(&self) -> Result<AccountGetQuotaResult, Error> {
135        let wire_params = serde_json::json!({});
136        let _value = self
137            .client
138            .call(rpc_methods::ACCOUNT_GETQUOTA, Some(wire_params))
139            .await?;
140        Ok(serde_json::from_value(_value)?)
141    }
142
143    /// Gets Copilot quota usage for the authenticated user or supplied GitHub token.
144    ///
145    /// Wire method: `account.getQuota`.
146    ///
147    /// # Parameters
148    ///
149    /// * `params` - Optional GitHub token used to look up quota for a specific user instead of the global auth context.
150    ///
151    /// # Returns
152    ///
153    /// Quota usage snapshots for the resolved user, keyed by quota type.
154    pub async fn get_quota_with_params(
155        &self,
156        params: AccountGetQuotaRequest,
157    ) -> Result<AccountGetQuotaResult, Error> {
158        let wire_params = serde_json::to_value(params)?;
159        let _value = self
160            .client
161            .call(rpc_methods::ACCOUNT_GETQUOTA, Some(wire_params))
162            .await?;
163        Ok(serde_json::from_value(_value)?)
164    }
165}
166
167/// `mcp.*` RPCs.
168#[derive(Clone, Copy)]
169pub struct ClientRpcMcp<'a> {
170    pub(crate) client: &'a Client,
171}
172
173impl<'a> ClientRpcMcp<'a> {
174    /// `mcp.config.*` sub-namespace.
175    pub fn config(&self) -> ClientRpcMcpConfig<'a> {
176        ClientRpcMcpConfig {
177            client: self.client,
178        }
179    }
180
181    /// Discovers MCP servers from user, workspace, plugin, and builtin sources.
182    ///
183    /// Wire method: `mcp.discover`.
184    ///
185    /// # Parameters
186    ///
187    /// * `params` - Optional working directory used as context for MCP server discovery.
188    ///
189    /// # Returns
190    ///
191    /// MCP servers discovered from user, workspace, plugin, and built-in sources.
192    pub async fn discover(&self, params: McpDiscoverRequest) -> Result<McpDiscoverResult, Error> {
193        let wire_params = serde_json::to_value(params)?;
194        let _value = self
195            .client
196            .call(rpc_methods::MCP_DISCOVER, Some(wire_params))
197            .await?;
198        Ok(serde_json::from_value(_value)?)
199    }
200}
201
202/// `mcp.config.*` RPCs.
203#[derive(Clone, Copy)]
204pub struct ClientRpcMcpConfig<'a> {
205    pub(crate) client: &'a Client,
206}
207
208impl<'a> ClientRpcMcpConfig<'a> {
209    /// Lists MCP servers from user configuration.
210    ///
211    /// Wire method: `mcp.config.list`.
212    ///
213    /// # Returns
214    ///
215    /// User-configured MCP servers, keyed by server name.
216    pub async fn list(&self) -> Result<McpConfigList, Error> {
217        let wire_params = serde_json::json!({});
218        let _value = self
219            .client
220            .call(rpc_methods::MCP_CONFIG_LIST, Some(wire_params))
221            .await?;
222        Ok(serde_json::from_value(_value)?)
223    }
224
225    /// Adds an MCP server to user configuration.
226    ///
227    /// Wire method: `mcp.config.add`.
228    ///
229    /// # Parameters
230    ///
231    /// * `params` - MCP server name and configuration to add to user configuration.
232    pub async fn add(&self, params: McpConfigAddRequest) -> Result<(), Error> {
233        let wire_params = serde_json::to_value(params)?;
234        let _value = self
235            .client
236            .call(rpc_methods::MCP_CONFIG_ADD, Some(wire_params))
237            .await?;
238        Ok(())
239    }
240
241    /// Updates an MCP server in user configuration.
242    ///
243    /// Wire method: `mcp.config.update`.
244    ///
245    /// # Parameters
246    ///
247    /// * `params` - MCP server name and replacement configuration to write to user configuration.
248    pub async fn update(&self, params: McpConfigUpdateRequest) -> Result<(), Error> {
249        let wire_params = serde_json::to_value(params)?;
250        let _value = self
251            .client
252            .call(rpc_methods::MCP_CONFIG_UPDATE, Some(wire_params))
253            .await?;
254        Ok(())
255    }
256
257    /// Removes an MCP server from user configuration.
258    ///
259    /// Wire method: `mcp.config.remove`.
260    ///
261    /// # Parameters
262    ///
263    /// * `params` - MCP server name to remove from user configuration.
264    pub async fn remove(&self, params: McpConfigRemoveRequest) -> Result<(), Error> {
265        let wire_params = serde_json::to_value(params)?;
266        let _value = self
267            .client
268            .call(rpc_methods::MCP_CONFIG_REMOVE, Some(wire_params))
269            .await?;
270        Ok(())
271    }
272
273    /// Enables MCP servers in user configuration for new sessions.
274    ///
275    /// Wire method: `mcp.config.enable`.
276    ///
277    /// # Parameters
278    ///
279    /// * `params` - MCP server names to enable for new sessions.
280    pub async fn enable(&self, params: McpConfigEnableRequest) -> Result<(), Error> {
281        let wire_params = serde_json::to_value(params)?;
282        let _value = self
283            .client
284            .call(rpc_methods::MCP_CONFIG_ENABLE, Some(wire_params))
285            .await?;
286        Ok(())
287    }
288
289    /// Disables MCP servers in user configuration for new sessions.
290    ///
291    /// Wire method: `mcp.config.disable`.
292    ///
293    /// # Parameters
294    ///
295    /// * `params` - MCP server names to disable for new sessions.
296    pub async fn disable(&self, params: McpConfigDisableRequest) -> Result<(), Error> {
297        let wire_params = serde_json::to_value(params)?;
298        let _value = self
299            .client
300            .call(rpc_methods::MCP_CONFIG_DISABLE, Some(wire_params))
301            .await?;
302        Ok(())
303    }
304}
305
306/// `models.*` RPCs.
307#[derive(Clone, Copy)]
308pub struct ClientRpcModels<'a> {
309    pub(crate) client: &'a Client,
310}
311
312impl<'a> ClientRpcModels<'a> {
313    /// Lists Copilot models available to the authenticated user.
314    ///
315    /// Wire method: `models.list`.
316    ///
317    /// # Returns
318    ///
319    /// List of Copilot models available to the resolved user, including capabilities and billing metadata.
320    pub async fn list(&self) -> Result<ModelList, Error> {
321        let wire_params = serde_json::json!({});
322        let _value = self
323            .client
324            .call(rpc_methods::MODELS_LIST, Some(wire_params))
325            .await?;
326        Ok(serde_json::from_value(_value)?)
327    }
328
329    /// Lists Copilot models available to the authenticated user.
330    ///
331    /// Wire method: `models.list`.
332    ///
333    /// # Parameters
334    ///
335    /// * `params` - Optional GitHub token used to list models for a specific user instead of the global auth context.
336    ///
337    /// # Returns
338    ///
339    /// List of Copilot models available to the resolved user, including capabilities and billing metadata.
340    pub async fn list_with_params(&self, params: ModelsListRequest) -> Result<ModelList, Error> {
341        let wire_params = serde_json::to_value(params)?;
342        let _value = self
343            .client
344            .call(rpc_methods::MODELS_LIST, Some(wire_params))
345            .await?;
346        Ok(serde_json::from_value(_value)?)
347    }
348}
349
350/// `secrets.*` RPCs.
351#[derive(Clone, Copy)]
352pub struct ClientRpcSecrets<'a> {
353    pub(crate) client: &'a Client,
354}
355
356impl<'a> ClientRpcSecrets<'a> {
357    /// Registers secret values for redaction in session logs and exports. The SDK calls this to inject dynamically generated secret values (e.g., OIDC tokens).
358    ///
359    /// Wire method: `secrets.addFilterValues`.
360    ///
361    /// # Parameters
362    ///
363    /// * `params` - Secret values to add to the redaction filter.
364    ///
365    /// # Returns
366    ///
367    /// Confirmation that the secret values were registered.
368    pub async fn add_filter_values(
369        &self,
370        params: SecretsAddFilterValuesRequest,
371    ) -> Result<SecretsAddFilterValuesResult, Error> {
372        let wire_params = serde_json::to_value(params)?;
373        let _value = self
374            .client
375            .call(rpc_methods::SECRETS_ADDFILTERVALUES, Some(wire_params))
376            .await?;
377        Ok(serde_json::from_value(_value)?)
378    }
379}
380
381/// `sessionFs.*` RPCs.
382#[derive(Clone, Copy)]
383pub struct ClientRpcSessionFs<'a> {
384    pub(crate) client: &'a Client,
385}
386
387impl<'a> ClientRpcSessionFs<'a> {
388    /// Registers an SDK client as the session filesystem provider.
389    ///
390    /// Wire method: `sessionFs.setProvider`.
391    ///
392    /// # Parameters
393    ///
394    /// * `params` - Initial working directory, session-state path layout, and path conventions used to register the calling SDK client as the session filesystem provider.
395    ///
396    /// # Returns
397    ///
398    /// Indicates whether the calling client was registered as the session filesystem provider.
399    pub async fn set_provider(
400        &self,
401        params: SessionFsSetProviderRequest,
402    ) -> Result<SessionFsSetProviderResult, Error> {
403        let wire_params = serde_json::to_value(params)?;
404        let _value = self
405            .client
406            .call(rpc_methods::SESSIONFS_SETPROVIDER, Some(wire_params))
407            .await?;
408        Ok(serde_json::from_value(_value)?)
409    }
410}
411
412/// `sessions.*` RPCs.
413#[derive(Clone, Copy)]
414pub struct ClientRpcSessions<'a> {
415    pub(crate) client: &'a Client,
416}
417
418impl<'a> ClientRpcSessions<'a> {
419    /// Creates a new session by forking persisted history from an existing session.
420    ///
421    /// Wire method: `sessions.fork`.
422    ///
423    /// # Parameters
424    ///
425    /// * `params` - Source session identifier to fork from, optional event-ID boundary, and optional friendly name for the new session.
426    ///
427    /// # Returns
428    ///
429    /// Identifier and optional friendly name assigned to the newly forked session.
430    ///
431    /// <div class="warning">
432    ///
433    /// **Experimental.** This API is part of an experimental wire-protocol surface
434    /// and may change or be removed in future SDK or CLI releases. Pin both the
435    /// SDK and CLI versions if your code depends on it.
436    ///
437    /// </div>
438    pub async fn fork(&self, params: SessionsForkRequest) -> Result<SessionsForkResult, Error> {
439        let wire_params = serde_json::to_value(params)?;
440        let _value = self
441            .client
442            .call(rpc_methods::SESSIONS_FORK, Some(wire_params))
443            .await?;
444        Ok(serde_json::from_value(_value)?)
445    }
446
447    /// Connects to an existing remote session and exposes it as an SDK session.
448    ///
449    /// Wire method: `sessions.connect`.
450    ///
451    /// # Parameters
452    ///
453    /// * `params` - Remote session connection parameters.
454    ///
455    /// # Returns
456    ///
457    /// Remote session connection result.
458    ///
459    /// <div class="warning">
460    ///
461    /// **Experimental.** This API is part of an experimental wire-protocol surface
462    /// and may change or be removed in future SDK or CLI releases. Pin both the
463    /// SDK and CLI versions if your code depends on it.
464    ///
465    /// </div>
466    pub async fn connect(
467        &self,
468        params: ConnectRemoteSessionParams,
469    ) -> Result<RemoteSessionConnectionResult, Error> {
470        let wire_params = serde_json::to_value(params)?;
471        let _value = self
472            .client
473            .call(rpc_methods::SESSIONS_CONNECT, Some(wire_params))
474            .await?;
475        Ok(serde_json::from_value(_value)?)
476    }
477
478    /// Lists persisted sessions, optionally filtered by working-directory context.
479    ///
480    /// Wire method: `sessions.list`.
481    ///
482    /// # Returns
483    ///
484    /// Persisted sessions matching the filter, ordered most-recently-modified first.
485    ///
486    /// <div class="warning">
487    ///
488    /// **Experimental.** This API is part of an experimental wire-protocol surface
489    /// and may change or be removed in future SDK or CLI releases. Pin both the
490    /// SDK and CLI versions if your code depends on it.
491    ///
492    /// </div>
493    pub async fn list(&self) -> Result<SessionList, Error> {
494        let wire_params = serde_json::json!({});
495        let _value = self
496            .client
497            .call(rpc_methods::SESSIONS_LIST, Some(wire_params))
498            .await?;
499        Ok(serde_json::from_value(_value)?)
500    }
501
502    /// Lists persisted sessions, optionally filtered by working-directory context.
503    ///
504    /// Wire method: `sessions.list`.
505    ///
506    /// # Parameters
507    ///
508    /// * `params` - Optional metadata-load limit and context filter applied to the returned sessions.
509    ///
510    /// # Returns
511    ///
512    /// Persisted sessions matching the filter, ordered most-recently-modified first.
513    ///
514    /// <div class="warning">
515    ///
516    /// **Experimental.** This API is part of an experimental wire-protocol surface
517    /// and may change or be removed in future SDK or CLI releases. Pin both the
518    /// SDK and CLI versions if your code depends on it.
519    ///
520    /// </div>
521    pub async fn list_with_params(
522        &self,
523        params: SessionsListRequest,
524    ) -> Result<SessionList, Error> {
525        let wire_params = serde_json::to_value(params)?;
526        let _value = self
527            .client
528            .call(rpc_methods::SESSIONS_LIST, Some(wire_params))
529            .await?;
530        Ok(serde_json::from_value(_value)?)
531    }
532
533    /// Finds the local session bound to a GitHub task ID, if any.
534    ///
535    /// Wire method: `sessions.findByTaskId`.
536    ///
537    /// # Parameters
538    ///
539    /// * `params` - GitHub task ID to look up.
540    ///
541    /// # Returns
542    ///
543    /// ID of the local session bound to the given GitHub task, or omitted when none.
544    ///
545    /// <div class="warning">
546    ///
547    /// **Experimental.** This API is part of an experimental wire-protocol surface
548    /// and may change or be removed in future SDK or CLI releases. Pin both the
549    /// SDK and CLI versions if your code depends on it.
550    ///
551    /// </div>
552    pub async fn find_by_task_id(
553        &self,
554        params: SessionsFindByTaskIDRequest,
555    ) -> Result<SessionsFindByTaskIDResult, Error> {
556        let wire_params = serde_json::to_value(params)?;
557        let _value = self
558            .client
559            .call(rpc_methods::SESSIONS_FINDBYTASKID, Some(wire_params))
560            .await?;
561        Ok(serde_json::from_value(_value)?)
562    }
563
564    /// Resolves a UUID prefix to a unique session ID, if exactly one session matches.
565    ///
566    /// Wire method: `sessions.findByPrefix`.
567    ///
568    /// # Parameters
569    ///
570    /// * `params` - UUID prefix to resolve to a unique session ID.
571    ///
572    /// # Returns
573    ///
574    /// Session ID matching the prefix, omitted when no unique match exists.
575    ///
576    /// <div class="warning">
577    ///
578    /// **Experimental.** This API is part of an experimental wire-protocol surface
579    /// and may change or be removed in future SDK or CLI releases. Pin both the
580    /// SDK and CLI versions if your code depends on it.
581    ///
582    /// </div>
583    pub async fn find_by_prefix(
584        &self,
585        params: SessionsFindByPrefixRequest,
586    ) -> Result<SessionsFindByPrefixResult, Error> {
587        let wire_params = serde_json::to_value(params)?;
588        let _value = self
589            .client
590            .call(rpc_methods::SESSIONS_FINDBYPREFIX, Some(wire_params))
591            .await?;
592        Ok(serde_json::from_value(_value)?)
593    }
594
595    /// Returns the most-relevant prior session for a given working-directory context.
596    ///
597    /// Wire method: `sessions.getLastForContext`.
598    ///
599    /// # Parameters
600    ///
601    /// * `params` - Optional working-directory context used to score session relevance.
602    ///
603    /// # Returns
604    ///
605    /// Most-relevant session ID for the supplied context, or omitted when no sessions exist.
606    ///
607    /// <div class="warning">
608    ///
609    /// **Experimental.** This API is part of an experimental wire-protocol surface
610    /// and may change or be removed in future SDK or CLI releases. Pin both the
611    /// SDK and CLI versions if your code depends on it.
612    ///
613    /// </div>
614    pub async fn get_last_for_context(
615        &self,
616        params: SessionsGetLastForContextRequest,
617    ) -> Result<SessionsGetLastForContextResult, Error> {
618        let wire_params = serde_json::to_value(params)?;
619        let _value = self
620            .client
621            .call(rpc_methods::SESSIONS_GETLASTFORCONTEXT, Some(wire_params))
622            .await?;
623        Ok(serde_json::from_value(_value)?)
624    }
625
626    /// Computes the absolute path to a session's persisted events.jsonl file.
627    ///
628    /// Wire method: `sessions.getEventFilePath`.
629    ///
630    /// # Parameters
631    ///
632    /// * `params` - Session ID whose event-log file path to compute.
633    ///
634    /// # Returns
635    ///
636    /// Absolute path to the session's events.jsonl file on disk.
637    ///
638    /// <div class="warning">
639    ///
640    /// **Experimental.** This API is part of an experimental wire-protocol surface
641    /// and may change or be removed in future SDK or CLI releases. Pin both the
642    /// SDK and CLI versions if your code depends on it.
643    ///
644    /// </div>
645    pub async fn get_event_file_path(
646        &self,
647        params: SessionsGetEventFilePathRequest,
648    ) -> Result<SessionsGetEventFilePathResult, Error> {
649        let wire_params = serde_json::to_value(params)?;
650        let _value = self
651            .client
652            .call(rpc_methods::SESSIONS_GETEVENTFILEPATH, Some(wire_params))
653            .await?;
654        Ok(serde_json::from_value(_value)?)
655    }
656
657    /// Returns the on-disk byte size of each session's workspace directory.
658    ///
659    /// Wire method: `sessions.getSizes`.
660    ///
661    /// # Returns
662    ///
663    /// Map of sessionId -> on-disk size in bytes for each session's workspace directory.
664    ///
665    /// <div class="warning">
666    ///
667    /// **Experimental.** This API is part of an experimental wire-protocol surface
668    /// and may change or be removed in future SDK or CLI releases. Pin both the
669    /// SDK and CLI versions if your code depends on it.
670    ///
671    /// </div>
672    pub async fn get_sizes(&self) -> Result<SessionSizes, Error> {
673        let wire_params = serde_json::json!({});
674        let _value = self
675            .client
676            .call(rpc_methods::SESSIONS_GETSIZES, Some(wire_params))
677            .await?;
678        Ok(serde_json::from_value(_value)?)
679    }
680
681    /// Returns the subset of the supplied session IDs that are currently held by another running process.
682    ///
683    /// Wire method: `sessions.checkInUse`.
684    ///
685    /// # Parameters
686    ///
687    /// * `params` - Session IDs to test for live in-use locks.
688    ///
689    /// # Returns
690    ///
691    /// Session IDs from the input set that are currently in use by another process.
692    ///
693    /// <div class="warning">
694    ///
695    /// **Experimental.** This API is part of an experimental wire-protocol surface
696    /// and may change or be removed in future SDK or CLI releases. Pin both the
697    /// SDK and CLI versions if your code depends on it.
698    ///
699    /// </div>
700    pub async fn check_in_use(
701        &self,
702        params: SessionsCheckInUseRequest,
703    ) -> Result<SessionsCheckInUseResult, Error> {
704        let wire_params = serde_json::to_value(params)?;
705        let _value = self
706            .client
707            .call(rpc_methods::SESSIONS_CHECKINUSE, Some(wire_params))
708            .await?;
709        Ok(serde_json::from_value(_value)?)
710    }
711
712    /// Returns a session's persisted remote-steerable flag, if any has been recorded.
713    ///
714    /// Wire method: `sessions.getPersistedRemoteSteerable`.
715    ///
716    /// # Parameters
717    ///
718    /// * `params` - Session ID to look up the persisted remote-steerable flag for.
719    ///
720    /// # Returns
721    ///
722    /// The session's persisted remote-steerable flag, or omitted when no value has been persisted.
723    ///
724    /// <div class="warning">
725    ///
726    /// **Experimental.** This API is part of an experimental wire-protocol surface
727    /// and may change or be removed in future SDK or CLI releases. Pin both the
728    /// SDK and CLI versions if your code depends on it.
729    ///
730    /// </div>
731    pub async fn get_persisted_remote_steerable(
732        &self,
733        params: SessionsGetPersistedRemoteSteerableRequest,
734    ) -> Result<SessionsGetPersistedRemoteSteerableResult, Error> {
735        let wire_params = serde_json::to_value(params)?;
736        let _value = self
737            .client
738            .call(
739                rpc_methods::SESSIONS_GETPERSISTEDREMOTESTEERABLE,
740                Some(wire_params),
741            )
742            .await?;
743        Ok(serde_json::from_value(_value)?)
744    }
745
746    /// Closes a session: emits shutdown, flushes pending events, releases the in-use lock, and disposes the active session.
747    ///
748    /// Wire method: `sessions.close`.
749    ///
750    /// # Parameters
751    ///
752    /// * `params` - Session ID to close.
753    ///
754    /// # Returns
755    ///
756    /// 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.
757    ///
758    /// <div class="warning">
759    ///
760    /// **Experimental.** This API is part of an experimental wire-protocol surface
761    /// and may change or be removed in future SDK or CLI releases. Pin both the
762    /// SDK and CLI versions if your code depends on it.
763    ///
764    /// </div>
765    pub async fn close(&self, params: SessionsCloseRequest) -> Result<SessionsCloseResult, Error> {
766        let wire_params = serde_json::to_value(params)?;
767        let _value = self
768            .client
769            .call(rpc_methods::SESSIONS_CLOSE, Some(wire_params))
770            .await?;
771        Ok(serde_json::from_value(_value)?)
772    }
773
774    /// Closes, deactivates, and deletes a set of sessions, returning the bytes freed per session.
775    ///
776    /// Wire method: `sessions.bulkDelete`.
777    ///
778    /// # Parameters
779    ///
780    /// * `params` - Session IDs to close, deactivate, and delete from disk.
781    ///
782    /// # Returns
783    ///
784    /// Map of sessionId -> bytes freed by removing the session's workspace directory.
785    ///
786    /// <div class="warning">
787    ///
788    /// **Experimental.** This API is part of an experimental wire-protocol surface
789    /// and may change or be removed in future SDK or CLI releases. Pin both the
790    /// SDK and CLI versions if your code depends on it.
791    ///
792    /// </div>
793    pub async fn bulk_delete(
794        &self,
795        params: SessionsBulkDeleteRequest,
796    ) -> Result<SessionBulkDeleteResult, Error> {
797        let wire_params = serde_json::to_value(params)?;
798        let _value = self
799            .client
800            .call(rpc_methods::SESSIONS_BULKDELETE, Some(wire_params))
801            .await?;
802        Ok(serde_json::from_value(_value)?)
803    }
804
805    /// Deletes sessions older than the given threshold, with optional dry-run and exclusion list.
806    ///
807    /// Wire method: `sessions.pruneOld`.
808    ///
809    /// # Parameters
810    ///
811    /// * `params` - Age threshold and optional flags controlling which old sessions are pruned (or simulated when dryRun is true).
812    ///
813    /// # Returns
814    ///
815    /// Outcome of the prune operation: deleted IDs, dry-run candidates, skipped IDs, total bytes freed, and the dry-run flag.
816    ///
817    /// <div class="warning">
818    ///
819    /// **Experimental.** This API is part of an experimental wire-protocol surface
820    /// and may change or be removed in future SDK or CLI releases. Pin both the
821    /// SDK and CLI versions if your code depends on it.
822    ///
823    /// </div>
824    pub async fn prune_old(
825        &self,
826        params: SessionsPruneOldRequest,
827    ) -> Result<SessionPruneResult, Error> {
828        let wire_params = serde_json::to_value(params)?;
829        let _value = self
830            .client
831            .call(rpc_methods::SESSIONS_PRUNEOLD, Some(wire_params))
832            .await?;
833        Ok(serde_json::from_value(_value)?)
834    }
835
836    /// Flushes a session's pending events to disk.
837    ///
838    /// Wire method: `sessions.save`.
839    ///
840    /// # Parameters
841    ///
842    /// * `params` - Session ID whose pending events should be flushed to disk.
843    ///
844    /// # Returns
845    ///
846    /// Flush a session's pending events to disk. No-op when no writer exists for the session (e.g., already closed).
847    ///
848    /// <div class="warning">
849    ///
850    /// **Experimental.** This API is part of an experimental wire-protocol surface
851    /// and may change or be removed in future SDK or CLI releases. Pin both the
852    /// SDK and CLI versions if your code depends on it.
853    ///
854    /// </div>
855    pub async fn save(&self, params: SessionsSaveRequest) -> Result<SessionsSaveResult, Error> {
856        let wire_params = serde_json::to_value(params)?;
857        let _value = self
858            .client
859            .call(rpc_methods::SESSIONS_SAVE, Some(wire_params))
860            .await?;
861        Ok(serde_json::from_value(_value)?)
862    }
863
864    /// Releases the in-use lock held by this process for a session.
865    ///
866    /// Wire method: `sessions.releaseLock`.
867    ///
868    /// # Parameters
869    ///
870    /// * `params` - Session ID whose in-use lock should be released.
871    ///
872    /// # Returns
873    ///
874    /// 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.
875    ///
876    /// <div class="warning">
877    ///
878    /// **Experimental.** This API is part of an experimental wire-protocol surface
879    /// and may change or be removed in future SDK or CLI releases. Pin both the
880    /// SDK and CLI versions if your code depends on it.
881    ///
882    /// </div>
883    pub async fn release_lock(
884        &self,
885        params: SessionsReleaseLockRequest,
886    ) -> Result<SessionsReleaseLockResult, Error> {
887        let wire_params = serde_json::to_value(params)?;
888        let _value = self
889            .client
890            .call(rpc_methods::SESSIONS_RELEASELOCK, Some(wire_params))
891            .await?;
892        Ok(serde_json::from_value(_value)?)
893    }
894
895    /// Backfills missing summary and context fields on the supplied session metadata records.
896    ///
897    /// Wire method: `sessions.enrichMetadata`.
898    ///
899    /// # Parameters
900    ///
901    /// * `params` - Session metadata records to enrich with summary and context information.
902    ///
903    /// # Returns
904    ///
905    /// The same metadata records, with summary and context fields backfilled where available.
906    ///
907    /// <div class="warning">
908    ///
909    /// **Experimental.** This API is part of an experimental wire-protocol surface
910    /// and may change or be removed in future SDK or CLI releases. Pin both the
911    /// SDK and CLI versions if your code depends on it.
912    ///
913    /// </div>
914    pub async fn enrich_metadata(
915        &self,
916        params: SessionsEnrichMetadataRequest,
917    ) -> Result<SessionEnrichMetadataResult, Error> {
918        let wire_params = serde_json::to_value(params)?;
919        let _value = self
920            .client
921            .call(rpc_methods::SESSIONS_ENRICHMETADATA, Some(wire_params))
922            .await?;
923        Ok(serde_json::from_value(_value)?)
924    }
925
926    /// Reloads user, plugin, and (optionally) repo hooks on the active session.
927    ///
928    /// Wire method: `sessions.reloadPluginHooks`.
929    ///
930    /// # Parameters
931    ///
932    /// * `params` - Active session ID and an optional flag for deferring repo-level hooks until folder trust.
933    ///
934    /// # Returns
935    ///
936    /// 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.
937    ///
938    /// <div class="warning">
939    ///
940    /// **Experimental.** This API is part of an experimental wire-protocol surface
941    /// and may change or be removed in future SDK or CLI releases. Pin both the
942    /// SDK and CLI versions if your code depends on it.
943    ///
944    /// </div>
945    pub async fn reload_plugin_hooks(
946        &self,
947        params: SessionsReloadPluginHooksRequest,
948    ) -> Result<SessionsReloadPluginHooksResult, Error> {
949        let wire_params = serde_json::to_value(params)?;
950        let _value = self
951            .client
952            .call(rpc_methods::SESSIONS_RELOADPLUGINHOOKS, Some(wire_params))
953            .await?;
954        Ok(serde_json::from_value(_value)?)
955    }
956
957    /// Loads previously-deferred repo-level hooks on the active session, returning queued startup prompts.
958    ///
959    /// Wire method: `sessions.loadDeferredRepoHooks`.
960    ///
961    /// # Parameters
962    ///
963    /// * `params` - Active session ID whose deferred repo-level hooks should be loaded.
964    ///
965    /// # Returns
966    ///
967    /// Queued repo-level startup prompts and the total hook command count after loading.
968    ///
969    /// <div class="warning">
970    ///
971    /// **Experimental.** This API is part of an experimental wire-protocol surface
972    /// and may change or be removed in future SDK or CLI releases. Pin both the
973    /// SDK and CLI versions if your code depends on it.
974    ///
975    /// </div>
976    pub async fn load_deferred_repo_hooks(
977        &self,
978        params: SessionsLoadDeferredRepoHooksRequest,
979    ) -> Result<SessionLoadDeferredRepoHooksResult, Error> {
980        let wire_params = serde_json::to_value(params)?;
981        let _value = self
982            .client
983            .call(
984                rpc_methods::SESSIONS_LOADDEFERREDREPOHOOKS,
985                Some(wire_params),
986            )
987            .await?;
988        Ok(serde_json::from_value(_value)?)
989    }
990
991    /// Replaces the manager-wide additional plugins registered with the session manager.
992    ///
993    /// Wire method: `sessions.setAdditionalPlugins`.
994    ///
995    /// # Parameters
996    ///
997    /// * `params` - Manager-wide additional plugins to register; replaces any previously-configured set.
998    ///
999    /// # Returns
1000    ///
1001    /// 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.
1002    ///
1003    /// <div class="warning">
1004    ///
1005    /// **Experimental.** This API is part of an experimental wire-protocol surface
1006    /// and may change or be removed in future SDK or CLI releases. Pin both the
1007    /// SDK and CLI versions if your code depends on it.
1008    ///
1009    /// </div>
1010    pub async fn set_additional_plugins(
1011        &self,
1012        params: SessionsSetAdditionalPluginsRequest,
1013    ) -> Result<SessionsSetAdditionalPluginsResult, Error> {
1014        let wire_params = serde_json::to_value(params)?;
1015        let _value = self
1016            .client
1017            .call(
1018                rpc_methods::SESSIONS_SETADDITIONALPLUGINS,
1019                Some(wire_params),
1020            )
1021            .await?;
1022        Ok(serde_json::from_value(_value)?)
1023    }
1024}
1025
1026/// `skills.*` RPCs.
1027#[derive(Clone, Copy)]
1028pub struct ClientRpcSkills<'a> {
1029    pub(crate) client: &'a Client,
1030}
1031
1032impl<'a> ClientRpcSkills<'a> {
1033    /// `skills.config.*` sub-namespace.
1034    pub fn config(&self) -> ClientRpcSkillsConfig<'a> {
1035        ClientRpcSkillsConfig {
1036            client: self.client,
1037        }
1038    }
1039
1040    /// Discovers skills across global and project sources.
1041    ///
1042    /// Wire method: `skills.discover`.
1043    ///
1044    /// # Parameters
1045    ///
1046    /// * `params` - Optional project paths and additional skill directories to include in discovery.
1047    ///
1048    /// # Returns
1049    ///
1050    /// Skills discovered across global and project sources.
1051    pub async fn discover(&self, params: SkillsDiscoverRequest) -> Result<ServerSkillList, Error> {
1052        let wire_params = serde_json::to_value(params)?;
1053        let _value = self
1054            .client
1055            .call(rpc_methods::SKILLS_DISCOVER, Some(wire_params))
1056            .await?;
1057        Ok(serde_json::from_value(_value)?)
1058    }
1059}
1060
1061/// `skills.config.*` RPCs.
1062#[derive(Clone, Copy)]
1063pub struct ClientRpcSkillsConfig<'a> {
1064    pub(crate) client: &'a Client,
1065}
1066
1067impl<'a> ClientRpcSkillsConfig<'a> {
1068    /// Replaces the global list of disabled skills.
1069    ///
1070    /// Wire method: `skills.config.setDisabledSkills`.
1071    ///
1072    /// # Parameters
1073    ///
1074    /// * `params` - Skill names to mark as disabled in global configuration, replacing any previous list.
1075    pub async fn set_disabled_skills(
1076        &self,
1077        params: SkillsConfigSetDisabledSkillsRequest,
1078    ) -> Result<(), Error> {
1079        let wire_params = serde_json::to_value(params)?;
1080        let _value = self
1081            .client
1082            .call(
1083                rpc_methods::SKILLS_CONFIG_SETDISABLEDSKILLS,
1084                Some(wire_params),
1085            )
1086            .await?;
1087        Ok(())
1088    }
1089}
1090
1091/// `tools.*` RPCs.
1092#[derive(Clone, Copy)]
1093pub struct ClientRpcTools<'a> {
1094    pub(crate) client: &'a Client,
1095}
1096
1097impl<'a> ClientRpcTools<'a> {
1098    /// Lists built-in tools available for a model.
1099    ///
1100    /// Wire method: `tools.list`.
1101    ///
1102    /// # Parameters
1103    ///
1104    /// * `params` - Optional model identifier whose tool overrides should be applied to the listing.
1105    ///
1106    /// # Returns
1107    ///
1108    /// Built-in tools available for the requested model, with their parameters and instructions.
1109    pub async fn list(&self, params: ToolsListRequest) -> Result<ToolList, Error> {
1110        let wire_params = serde_json::to_value(params)?;
1111        let _value = self
1112            .client
1113            .call(rpc_methods::TOOLS_LIST, Some(wire_params))
1114            .await?;
1115        Ok(serde_json::from_value(_value)?)
1116    }
1117}
1118
1119/// Typed view over a [`Session`]'s RPC namespace.
1120#[derive(Clone, Copy)]
1121pub struct SessionRpc<'a> {
1122    pub(crate) session: &'a Session,
1123}
1124
1125impl<'a> SessionRpc<'a> {
1126    /// `session.agent.*` sub-namespace.
1127    pub fn agent(&self) -> SessionRpcAgent<'a> {
1128        SessionRpcAgent {
1129            session: self.session,
1130        }
1131    }
1132
1133    /// `session.auth.*` sub-namespace.
1134    pub fn auth(&self) -> SessionRpcAuth<'a> {
1135        SessionRpcAuth {
1136            session: self.session,
1137        }
1138    }
1139
1140    /// `session.commands.*` sub-namespace.
1141    pub fn commands(&self) -> SessionRpcCommands<'a> {
1142        SessionRpcCommands {
1143            session: self.session,
1144        }
1145    }
1146
1147    /// `session.eventLog.*` sub-namespace.
1148    pub fn event_log(&self) -> SessionRpcEventLog<'a> {
1149        SessionRpcEventLog {
1150            session: self.session,
1151        }
1152    }
1153
1154    /// `session.extensions.*` sub-namespace.
1155    pub fn extensions(&self) -> SessionRpcExtensions<'a> {
1156        SessionRpcExtensions {
1157            session: self.session,
1158        }
1159    }
1160
1161    /// `session.fleet.*` sub-namespace.
1162    pub fn fleet(&self) -> SessionRpcFleet<'a> {
1163        SessionRpcFleet {
1164            session: self.session,
1165        }
1166    }
1167
1168    /// `session.history.*` sub-namespace.
1169    pub fn history(&self) -> SessionRpcHistory<'a> {
1170        SessionRpcHistory {
1171            session: self.session,
1172        }
1173    }
1174
1175    /// `session.instructions.*` sub-namespace.
1176    pub fn instructions(&self) -> SessionRpcInstructions<'a> {
1177        SessionRpcInstructions {
1178            session: self.session,
1179        }
1180    }
1181
1182    /// `session.lsp.*` sub-namespace.
1183    pub fn lsp(&self) -> SessionRpcLsp<'a> {
1184        SessionRpcLsp {
1185            session: self.session,
1186        }
1187    }
1188
1189    /// `session.mcp.*` sub-namespace.
1190    pub fn mcp(&self) -> SessionRpcMcp<'a> {
1191        SessionRpcMcp {
1192            session: self.session,
1193        }
1194    }
1195
1196    /// `session.metadata.*` sub-namespace.
1197    pub fn metadata(&self) -> SessionRpcMetadata<'a> {
1198        SessionRpcMetadata {
1199            session: self.session,
1200        }
1201    }
1202
1203    /// `session.mode.*` sub-namespace.
1204    pub fn mode(&self) -> SessionRpcMode<'a> {
1205        SessionRpcMode {
1206            session: self.session,
1207        }
1208    }
1209
1210    /// `session.model.*` sub-namespace.
1211    pub fn model(&self) -> SessionRpcModel<'a> {
1212        SessionRpcModel {
1213            session: self.session,
1214        }
1215    }
1216
1217    /// `session.name.*` sub-namespace.
1218    pub fn name(&self) -> SessionRpcName<'a> {
1219        SessionRpcName {
1220            session: self.session,
1221        }
1222    }
1223
1224    /// `session.options.*` sub-namespace.
1225    pub fn options(&self) -> SessionRpcOptions<'a> {
1226        SessionRpcOptions {
1227            session: self.session,
1228        }
1229    }
1230
1231    /// `session.permissions.*` sub-namespace.
1232    pub fn permissions(&self) -> SessionRpcPermissions<'a> {
1233        SessionRpcPermissions {
1234            session: self.session,
1235        }
1236    }
1237
1238    /// `session.plan.*` sub-namespace.
1239    pub fn plan(&self) -> SessionRpcPlan<'a> {
1240        SessionRpcPlan {
1241            session: self.session,
1242        }
1243    }
1244
1245    /// `session.plugins.*` sub-namespace.
1246    pub fn plugins(&self) -> SessionRpcPlugins<'a> {
1247        SessionRpcPlugins {
1248            session: self.session,
1249        }
1250    }
1251
1252    /// `session.queue.*` sub-namespace.
1253    pub fn queue(&self) -> SessionRpcQueue<'a> {
1254        SessionRpcQueue {
1255            session: self.session,
1256        }
1257    }
1258
1259    /// `session.remote.*` sub-namespace.
1260    pub fn remote(&self) -> SessionRpcRemote<'a> {
1261        SessionRpcRemote {
1262            session: self.session,
1263        }
1264    }
1265
1266    /// `session.schedule.*` sub-namespace.
1267    pub fn schedule(&self) -> SessionRpcSchedule<'a> {
1268        SessionRpcSchedule {
1269            session: self.session,
1270        }
1271    }
1272
1273    /// `session.shell.*` sub-namespace.
1274    pub fn shell(&self) -> SessionRpcShell<'a> {
1275        SessionRpcShell {
1276            session: self.session,
1277        }
1278    }
1279
1280    /// `session.skills.*` sub-namespace.
1281    pub fn skills(&self) -> SessionRpcSkills<'a> {
1282        SessionRpcSkills {
1283            session: self.session,
1284        }
1285    }
1286
1287    /// `session.tasks.*` sub-namespace.
1288    pub fn tasks(&self) -> SessionRpcTasks<'a> {
1289        SessionRpcTasks {
1290            session: self.session,
1291        }
1292    }
1293
1294    /// `session.telemetry.*` sub-namespace.
1295    pub fn telemetry(&self) -> SessionRpcTelemetry<'a> {
1296        SessionRpcTelemetry {
1297            session: self.session,
1298        }
1299    }
1300
1301    /// `session.tools.*` sub-namespace.
1302    pub fn tools(&self) -> SessionRpcTools<'a> {
1303        SessionRpcTools {
1304            session: self.session,
1305        }
1306    }
1307
1308    /// `session.ui.*` sub-namespace.
1309    pub fn ui(&self) -> SessionRpcUi<'a> {
1310        SessionRpcUi {
1311            session: self.session,
1312        }
1313    }
1314
1315    /// `session.usage.*` sub-namespace.
1316    pub fn usage(&self) -> SessionRpcUsage<'a> {
1317        SessionRpcUsage {
1318            session: self.session,
1319        }
1320    }
1321
1322    /// `session.workspaces.*` sub-namespace.
1323    pub fn workspaces(&self) -> SessionRpcWorkspaces<'a> {
1324        SessionRpcWorkspaces {
1325            session: self.session,
1326        }
1327    }
1328
1329    /// Suspends the session while preserving persisted state for later resume.
1330    ///
1331    /// Wire method: `session.suspend`.
1332    ///
1333    /// <div class="warning">
1334    ///
1335    /// **Experimental.** This API is part of an experimental wire-protocol surface
1336    /// and may change or be removed in future SDK or CLI releases. Pin both the
1337    /// SDK and CLI versions if your code depends on it.
1338    ///
1339    /// </div>
1340    pub async fn suspend(&self) -> Result<(), Error> {
1341        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
1342        let _value = self
1343            .session
1344            .client()
1345            .call(rpc_methods::SESSION_SUSPEND, Some(wire_params))
1346            .await?;
1347        Ok(())
1348    }
1349
1350    /// Sends a user message to the session and returns its message ID.
1351    ///
1352    /// Wire method: `session.send`.
1353    ///
1354    /// # Parameters
1355    ///
1356    /// * `params` - Parameters for sending a user message to the session
1357    ///
1358    /// # Returns
1359    ///
1360    /// Result of sending a user message
1361    ///
1362    /// <div class="warning">
1363    ///
1364    /// **Experimental.** This API is part of an experimental wire-protocol surface
1365    /// and may change or be removed in future SDK or CLI releases. Pin both the
1366    /// SDK and CLI versions if your code depends on it.
1367    ///
1368    /// </div>
1369    pub async fn send(&self, params: SendRequest) -> Result<SendResult, Error> {
1370        let mut wire_params = serde_json::to_value(params)?;
1371        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
1372        let _value = self
1373            .session
1374            .client()
1375            .call(rpc_methods::SESSION_SEND, Some(wire_params))
1376            .await?;
1377        Ok(serde_json::from_value(_value)?)
1378    }
1379
1380    /// Aborts the current agent turn.
1381    ///
1382    /// Wire method: `session.abort`.
1383    ///
1384    /// # Parameters
1385    ///
1386    /// * `params` - Parameters for aborting the current turn
1387    ///
1388    /// # Returns
1389    ///
1390    /// Result of aborting the current turn
1391    ///
1392    /// <div class="warning">
1393    ///
1394    /// **Experimental.** This API is part of an experimental wire-protocol surface
1395    /// and may change or be removed in future SDK or CLI releases. Pin both the
1396    /// SDK and CLI versions if your code depends on it.
1397    ///
1398    /// </div>
1399    pub async fn abort(&self, params: AbortRequest) -> Result<AbortResult, Error> {
1400        let mut wire_params = serde_json::to_value(params)?;
1401        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
1402        let _value = self
1403            .session
1404            .client()
1405            .call(rpc_methods::SESSION_ABORT, Some(wire_params))
1406            .await?;
1407        Ok(serde_json::from_value(_value)?)
1408    }
1409
1410    /// 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.
1411    ///
1412    /// Wire method: `session.shutdown`.
1413    ///
1414    /// # Parameters
1415    ///
1416    /// * `params` - Parameters for shutting down the session
1417    ///
1418    /// <div class="warning">
1419    ///
1420    /// **Experimental.** This API is part of an experimental wire-protocol surface
1421    /// and may change or be removed in future SDK or CLI releases. Pin both the
1422    /// SDK and CLI versions if your code depends on it.
1423    ///
1424    /// </div>
1425    pub async fn shutdown(&self, params: ShutdownRequest) -> Result<(), Error> {
1426        let mut wire_params = serde_json::to_value(params)?;
1427        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
1428        let _value = self
1429            .session
1430            .client()
1431            .call(rpc_methods::SESSION_SHUTDOWN, Some(wire_params))
1432            .await?;
1433        Ok(())
1434    }
1435
1436    /// Emits a user-visible session log event.
1437    ///
1438    /// Wire method: `session.log`.
1439    ///
1440    /// # Parameters
1441    ///
1442    /// * `params` - Message text, optional severity level, persistence flag, optional follow-up URL, and optional tip.
1443    ///
1444    /// # Returns
1445    ///
1446    /// Identifier of the session event that was emitted for the log message.
1447    ///
1448    /// <div class="warning">
1449    ///
1450    /// **Experimental.** This API is part of an experimental wire-protocol surface
1451    /// and may change or be removed in future SDK or CLI releases. Pin both the
1452    /// SDK and CLI versions if your code depends on it.
1453    ///
1454    /// </div>
1455    pub async fn log(&self, params: LogRequest) -> Result<LogResult, Error> {
1456        let mut wire_params = serde_json::to_value(params)?;
1457        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
1458        let _value = self
1459            .session
1460            .client()
1461            .call(rpc_methods::SESSION_LOG, Some(wire_params))
1462            .await?;
1463        Ok(serde_json::from_value(_value)?)
1464    }
1465}
1466
1467/// `session.agent.*` RPCs.
1468#[derive(Clone, Copy)]
1469pub struct SessionRpcAgent<'a> {
1470    pub(crate) session: &'a Session,
1471}
1472
1473impl<'a> SessionRpcAgent<'a> {
1474    /// Lists custom agents available to the session.
1475    ///
1476    /// Wire method: `session.agent.list`.
1477    ///
1478    /// # Returns
1479    ///
1480    /// Custom agents available to the session.
1481    ///
1482    /// <div class="warning">
1483    ///
1484    /// **Experimental.** This API is part of an experimental wire-protocol surface
1485    /// and may change or be removed in future SDK or CLI releases. Pin both the
1486    /// SDK and CLI versions if your code depends on it.
1487    ///
1488    /// </div>
1489    pub async fn list(&self) -> Result<AgentList, Error> {
1490        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
1491        let _value = self
1492            .session
1493            .client()
1494            .call(rpc_methods::SESSION_AGENT_LIST, Some(wire_params))
1495            .await?;
1496        Ok(serde_json::from_value(_value)?)
1497    }
1498
1499    /// Gets the currently selected custom agent for the session.
1500    ///
1501    /// Wire method: `session.agent.getCurrent`.
1502    ///
1503    /// # Returns
1504    ///
1505    /// The currently selected custom agent, or null when using the default agent.
1506    ///
1507    /// <div class="warning">
1508    ///
1509    /// **Experimental.** This API is part of an experimental wire-protocol surface
1510    /// and may change or be removed in future SDK or CLI releases. Pin both the
1511    /// SDK and CLI versions if your code depends on it.
1512    ///
1513    /// </div>
1514    pub async fn get_current(&self) -> Result<AgentGetCurrentResult, Error> {
1515        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
1516        let _value = self
1517            .session
1518            .client()
1519            .call(rpc_methods::SESSION_AGENT_GETCURRENT, Some(wire_params))
1520            .await?;
1521        Ok(serde_json::from_value(_value)?)
1522    }
1523
1524    /// Selects a custom agent for subsequent turns in the session.
1525    ///
1526    /// Wire method: `session.agent.select`.
1527    ///
1528    /// # Parameters
1529    ///
1530    /// * `params` - Name of the custom agent to select for subsequent turns.
1531    ///
1532    /// # Returns
1533    ///
1534    /// The newly selected custom agent.
1535    ///
1536    /// <div class="warning">
1537    ///
1538    /// **Experimental.** This API is part of an experimental wire-protocol surface
1539    /// and may change or be removed in future SDK or CLI releases. Pin both the
1540    /// SDK and CLI versions if your code depends on it.
1541    ///
1542    /// </div>
1543    pub async fn select(&self, params: AgentSelectRequest) -> Result<AgentSelectResult, Error> {
1544        let mut wire_params = serde_json::to_value(params)?;
1545        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
1546        let _value = self
1547            .session
1548            .client()
1549            .call(rpc_methods::SESSION_AGENT_SELECT, Some(wire_params))
1550            .await?;
1551        Ok(serde_json::from_value(_value)?)
1552    }
1553
1554    /// Clears the selected custom agent and returns the session to the default agent.
1555    ///
1556    /// Wire method: `session.agent.deselect`.
1557    ///
1558    /// <div class="warning">
1559    ///
1560    /// **Experimental.** This API is part of an experimental wire-protocol surface
1561    /// and may change or be removed in future SDK or CLI releases. Pin both the
1562    /// SDK and CLI versions if your code depends on it.
1563    ///
1564    /// </div>
1565    pub async fn deselect(&self) -> Result<(), Error> {
1566        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
1567        let _value = self
1568            .session
1569            .client()
1570            .call(rpc_methods::SESSION_AGENT_DESELECT, Some(wire_params))
1571            .await?;
1572        Ok(())
1573    }
1574
1575    /// Reloads custom agent definitions and returns the refreshed list.
1576    ///
1577    /// Wire method: `session.agent.reload`.
1578    ///
1579    /// # Returns
1580    ///
1581    /// Custom agents available to the session after reloading definitions from disk.
1582    ///
1583    /// <div class="warning">
1584    ///
1585    /// **Experimental.** This API is part of an experimental wire-protocol surface
1586    /// and may change or be removed in future SDK or CLI releases. Pin both the
1587    /// SDK and CLI versions if your code depends on it.
1588    ///
1589    /// </div>
1590    pub async fn reload(&self) -> Result<AgentReloadResult, Error> {
1591        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
1592        let _value = self
1593            .session
1594            .client()
1595            .call(rpc_methods::SESSION_AGENT_RELOAD, Some(wire_params))
1596            .await?;
1597        Ok(serde_json::from_value(_value)?)
1598    }
1599}
1600
1601/// `session.auth.*` RPCs.
1602#[derive(Clone, Copy)]
1603pub struct SessionRpcAuth<'a> {
1604    pub(crate) session: &'a Session,
1605}
1606
1607impl<'a> SessionRpcAuth<'a> {
1608    /// Gets authentication status and account metadata for the session.
1609    ///
1610    /// Wire method: `session.auth.getStatus`.
1611    ///
1612    /// # Returns
1613    ///
1614    /// Authentication status and account metadata for the session.
1615    ///
1616    /// <div class="warning">
1617    ///
1618    /// **Experimental.** This API is part of an experimental wire-protocol surface
1619    /// and may change or be removed in future SDK or CLI releases. Pin both the
1620    /// SDK and CLI versions if your code depends on it.
1621    ///
1622    /// </div>
1623    pub async fn get_status(&self) -> Result<SessionAuthStatus, Error> {
1624        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
1625        let _value = self
1626            .session
1627            .client()
1628            .call(rpc_methods::SESSION_AUTH_GETSTATUS, Some(wire_params))
1629            .await?;
1630        Ok(serde_json::from_value(_value)?)
1631    }
1632
1633    /// Updates the session's auth credentials used for outbound model and API requests.
1634    ///
1635    /// Wire method: `session.auth.setCredentials`.
1636    ///
1637    /// # Parameters
1638    ///
1639    /// * `params` - New auth credentials to install on the session. Omit to leave credentials unchanged.
1640    ///
1641    /// # Returns
1642    ///
1643    /// Indicates whether the credential update succeeded.
1644    ///
1645    /// <div class="warning">
1646    ///
1647    /// **Experimental.** This API is part of an experimental wire-protocol surface
1648    /// and may change or be removed in future SDK or CLI releases. Pin both the
1649    /// SDK and CLI versions if your code depends on it.
1650    ///
1651    /// </div>
1652    pub async fn set_credentials(
1653        &self,
1654        params: SessionSetCredentialsParams,
1655    ) -> Result<SessionSetCredentialsResult, Error> {
1656        let mut wire_params = serde_json::to_value(params)?;
1657        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
1658        let _value = self
1659            .session
1660            .client()
1661            .call(rpc_methods::SESSION_AUTH_SETCREDENTIALS, Some(wire_params))
1662            .await?;
1663        Ok(serde_json::from_value(_value)?)
1664    }
1665}
1666
1667/// `session.commands.*` RPCs.
1668#[derive(Clone, Copy)]
1669pub struct SessionRpcCommands<'a> {
1670    pub(crate) session: &'a Session,
1671}
1672
1673impl<'a> SessionRpcCommands<'a> {
1674    /// Lists slash commands available in the session.
1675    ///
1676    /// Wire method: `session.commands.list`.
1677    ///
1678    /// # Returns
1679    ///
1680    /// Slash commands available in the session, after applying any include/exclude filters.
1681    ///
1682    /// <div class="warning">
1683    ///
1684    /// **Experimental.** This API is part of an experimental wire-protocol surface
1685    /// and may change or be removed in future SDK or CLI releases. Pin both the
1686    /// SDK and CLI versions if your code depends on it.
1687    ///
1688    /// </div>
1689    pub async fn list(&self) -> Result<CommandList, Error> {
1690        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
1691        let _value = self
1692            .session
1693            .client()
1694            .call(rpc_methods::SESSION_COMMANDS_LIST, Some(wire_params))
1695            .await?;
1696        Ok(serde_json::from_value(_value)?)
1697    }
1698
1699    /// Lists slash commands available in the session.
1700    ///
1701    /// Wire method: `session.commands.list`.
1702    ///
1703    /// # Parameters
1704    ///
1705    /// * `params` - Optional filters controlling which command sources to include in the listing.
1706    ///
1707    /// # Returns
1708    ///
1709    /// Slash commands available in the session, after applying any include/exclude filters.
1710    ///
1711    /// <div class="warning">
1712    ///
1713    /// **Experimental.** This API is part of an experimental wire-protocol surface
1714    /// and may change or be removed in future SDK or CLI releases. Pin both the
1715    /// SDK and CLI versions if your code depends on it.
1716    ///
1717    /// </div>
1718    pub async fn list_with_params(
1719        &self,
1720        params: CommandsListRequest,
1721    ) -> Result<CommandList, Error> {
1722        let mut wire_params = serde_json::to_value(params)?;
1723        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
1724        let _value = self
1725            .session
1726            .client()
1727            .call(rpc_methods::SESSION_COMMANDS_LIST, Some(wire_params))
1728            .await?;
1729        Ok(serde_json::from_value(_value)?)
1730    }
1731
1732    /// Invokes a slash command in the session.
1733    ///
1734    /// Wire method: `session.commands.invoke`.
1735    ///
1736    /// # Parameters
1737    ///
1738    /// * `params` - Slash command name and optional raw input string to invoke.
1739    ///
1740    /// # Returns
1741    ///
1742    /// Result of invoking the slash command (text output, prompt to send to the agent, or completion).
1743    ///
1744    /// <div class="warning">
1745    ///
1746    /// **Experimental.** This API is part of an experimental wire-protocol surface
1747    /// and may change or be removed in future SDK or CLI releases. Pin both the
1748    /// SDK and CLI versions if your code depends on it.
1749    ///
1750    /// </div>
1751    pub async fn invoke(
1752        &self,
1753        params: CommandsInvokeRequest,
1754    ) -> Result<SlashCommandInvocationResult, Error> {
1755        let mut wire_params = serde_json::to_value(params)?;
1756        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
1757        let _value = self
1758            .session
1759            .client()
1760            .call(rpc_methods::SESSION_COMMANDS_INVOKE, Some(wire_params))
1761            .await?;
1762        Ok(serde_json::from_value(_value)?)
1763    }
1764
1765    /// Reports completion of a pending client-handled slash command.
1766    ///
1767    /// Wire method: `session.commands.handlePendingCommand`.
1768    ///
1769    /// # Parameters
1770    ///
1771    /// * `params` - Pending command request ID and an optional error if the client handler failed.
1772    ///
1773    /// # Returns
1774    ///
1775    /// Indicates whether the pending client-handled command was completed successfully.
1776    ///
1777    /// <div class="warning">
1778    ///
1779    /// **Experimental.** This API is part of an experimental wire-protocol surface
1780    /// and may change or be removed in future SDK or CLI releases. Pin both the
1781    /// SDK and CLI versions if your code depends on it.
1782    ///
1783    /// </div>
1784    pub async fn handle_pending_command(
1785        &self,
1786        params: CommandsHandlePendingCommandRequest,
1787    ) -> Result<CommandsHandlePendingCommandResult, Error> {
1788        let mut wire_params = serde_json::to_value(params)?;
1789        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
1790        let _value = self
1791            .session
1792            .client()
1793            .call(
1794                rpc_methods::SESSION_COMMANDS_HANDLEPENDINGCOMMAND,
1795                Some(wire_params),
1796            )
1797            .await?;
1798        Ok(serde_json::from_value(_value)?)
1799    }
1800
1801    /// Executes a slash command synchronously and returns any error.
1802    ///
1803    /// Wire method: `session.commands.execute`.
1804    ///
1805    /// # Parameters
1806    ///
1807    /// * `params` - Slash command name and argument string to execute synchronously.
1808    ///
1809    /// # Returns
1810    ///
1811    /// Error message produced while executing the command, if any.
1812    ///
1813    /// <div class="warning">
1814    ///
1815    /// **Experimental.** This API is part of an experimental wire-protocol surface
1816    /// and may change or be removed in future SDK or CLI releases. Pin both the
1817    /// SDK and CLI versions if your code depends on it.
1818    ///
1819    /// </div>
1820    pub async fn execute(
1821        &self,
1822        params: ExecuteCommandParams,
1823    ) -> Result<ExecuteCommandResult, Error> {
1824        let mut wire_params = serde_json::to_value(params)?;
1825        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
1826        let _value = self
1827            .session
1828            .client()
1829            .call(rpc_methods::SESSION_COMMANDS_EXECUTE, Some(wire_params))
1830            .await?;
1831        Ok(serde_json::from_value(_value)?)
1832    }
1833
1834    /// Enqueues a slash command for FIFO processing on the local session.
1835    ///
1836    /// Wire method: `session.commands.enqueue`.
1837    ///
1838    /// # Parameters
1839    ///
1840    /// * `params` - Slash-prefixed command string to enqueue for FIFO processing.
1841    ///
1842    /// # Returns
1843    ///
1844    /// Indicates whether the command was accepted into the local execution queue.
1845    ///
1846    /// <div class="warning">
1847    ///
1848    /// **Experimental.** This API is part of an experimental wire-protocol surface
1849    /// and may change or be removed in future SDK or CLI releases. Pin both the
1850    /// SDK and CLI versions if your code depends on it.
1851    ///
1852    /// </div>
1853    pub async fn enqueue(
1854        &self,
1855        params: EnqueueCommandParams,
1856    ) -> Result<EnqueueCommandResult, Error> {
1857        let mut wire_params = serde_json::to_value(params)?;
1858        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
1859        let _value = self
1860            .session
1861            .client()
1862            .call(rpc_methods::SESSION_COMMANDS_ENQUEUE, Some(wire_params))
1863            .await?;
1864        Ok(serde_json::from_value(_value)?)
1865    }
1866
1867    /// Reports whether the host actually executed a queued command and whether to continue processing.
1868    ///
1869    /// Wire method: `session.commands.respondToQueuedCommand`.
1870    ///
1871    /// # Parameters
1872    ///
1873    /// * `params` - Queued-command request ID and the result indicating whether the host executed it (and whether to stop processing further queued commands).
1874    ///
1875    /// # Returns
1876    ///
1877    /// Indicates whether the queued-command response was matched to a pending request.
1878    ///
1879    /// <div class="warning">
1880    ///
1881    /// **Experimental.** This API is part of an experimental wire-protocol surface
1882    /// and may change or be removed in future SDK or CLI releases. Pin both the
1883    /// SDK and CLI versions if your code depends on it.
1884    ///
1885    /// </div>
1886    pub async fn respond_to_queued_command(
1887        &self,
1888        params: CommandsRespondToQueuedCommandRequest,
1889    ) -> Result<CommandsRespondToQueuedCommandResult, Error> {
1890        let mut wire_params = serde_json::to_value(params)?;
1891        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
1892        let _value = self
1893            .session
1894            .client()
1895            .call(
1896                rpc_methods::SESSION_COMMANDS_RESPONDTOQUEUEDCOMMAND,
1897                Some(wire_params),
1898            )
1899            .await?;
1900        Ok(serde_json::from_value(_value)?)
1901    }
1902}
1903
1904/// `session.eventLog.*` RPCs.
1905#[derive(Clone, Copy)]
1906pub struct SessionRpcEventLog<'a> {
1907    pub(crate) session: &'a Session,
1908}
1909
1910impl<'a> SessionRpcEventLog<'a> {
1911    /// Reads a batch of session events from a cursor, optionally waiting for new events.
1912    ///
1913    /// Wire method: `session.eventLog.read`.
1914    ///
1915    /// # Parameters
1916    ///
1917    /// * `params` - Cursor, batch size, and optional long-poll/filter parameters for reading session events.
1918    ///
1919    /// # Returns
1920    ///
1921    /// Batch of session events returned by a read, with cursor and continuation metadata.
1922    ///
1923    /// <div class="warning">
1924    ///
1925    /// **Experimental.** This API is part of an experimental wire-protocol surface
1926    /// and may change or be removed in future SDK or CLI releases. Pin both the
1927    /// SDK and CLI versions if your code depends on it.
1928    ///
1929    /// </div>
1930    pub async fn read(&self, params: EventLogReadRequest) -> Result<EventsReadResult, Error> {
1931        let mut wire_params = serde_json::to_value(params)?;
1932        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
1933        let _value = self
1934            .session
1935            .client()
1936            .call(rpc_methods::SESSION_EVENTLOG_READ, Some(wire_params))
1937            .await?;
1938        Ok(serde_json::from_value(_value)?)
1939    }
1940
1941    /// Returns a snapshot of the current tail cursor without consuming events.
1942    ///
1943    /// Wire method: `session.eventLog.tail`.
1944    ///
1945    /// # Returns
1946    ///
1947    /// 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).
1948    ///
1949    /// <div class="warning">
1950    ///
1951    /// **Experimental.** This API is part of an experimental wire-protocol surface
1952    /// and may change or be removed in future SDK or CLI releases. Pin both the
1953    /// SDK and CLI versions if your code depends on it.
1954    ///
1955    /// </div>
1956    pub async fn tail(&self) -> Result<EventLogTailResult, Error> {
1957        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
1958        let _value = self
1959            .session
1960            .client()
1961            .call(rpc_methods::SESSION_EVENTLOG_TAIL, Some(wire_params))
1962            .await?;
1963        Ok(serde_json::from_value(_value)?)
1964    }
1965
1966    /// Registers consumer interest in an event type for runtime gating purposes.
1967    ///
1968    /// Wire method: `session.eventLog.registerInterest`.
1969    ///
1970    /// # Parameters
1971    ///
1972    /// * `params` - Event type to register consumer interest for, used by runtime gating logic.
1973    ///
1974    /// # Returns
1975    ///
1976    /// Opaque handle representing an event-type interest registration.
1977    ///
1978    /// <div class="warning">
1979    ///
1980    /// **Experimental.** This API is part of an experimental wire-protocol surface
1981    /// and may change or be removed in future SDK or CLI releases. Pin both the
1982    /// SDK and CLI versions if your code depends on it.
1983    ///
1984    /// </div>
1985    pub async fn register_interest(
1986        &self,
1987        params: RegisterEventInterestParams,
1988    ) -> Result<RegisterEventInterestResult, Error> {
1989        let mut wire_params = serde_json::to_value(params)?;
1990        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
1991        let _value = self
1992            .session
1993            .client()
1994            .call(
1995                rpc_methods::SESSION_EVENTLOG_REGISTERINTEREST,
1996                Some(wire_params),
1997            )
1998            .await?;
1999        Ok(serde_json::from_value(_value)?)
2000    }
2001
2002    /// Releases a consumer's previously-registered interest in an event type.
2003    ///
2004    /// Wire method: `session.eventLog.releaseInterest`.
2005    ///
2006    /// # Parameters
2007    ///
2008    /// * `params` - Opaque handle previously returned by `registerInterest` to release.
2009    ///
2010    /// # Returns
2011    ///
2012    /// Indicates whether the operation succeeded.
2013    ///
2014    /// <div class="warning">
2015    ///
2016    /// **Experimental.** This API is part of an experimental wire-protocol surface
2017    /// and may change or be removed in future SDK or CLI releases. Pin both the
2018    /// SDK and CLI versions if your code depends on it.
2019    ///
2020    /// </div>
2021    pub async fn release_interest(
2022        &self,
2023        params: ReleaseEventInterestParams,
2024    ) -> Result<EventLogReleaseInterestResult, Error> {
2025        let mut wire_params = serde_json::to_value(params)?;
2026        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
2027        let _value = self
2028            .session
2029            .client()
2030            .call(
2031                rpc_methods::SESSION_EVENTLOG_RELEASEINTEREST,
2032                Some(wire_params),
2033            )
2034            .await?;
2035        Ok(serde_json::from_value(_value)?)
2036    }
2037}
2038
2039/// `session.extensions.*` RPCs.
2040#[derive(Clone, Copy)]
2041pub struct SessionRpcExtensions<'a> {
2042    pub(crate) session: &'a Session,
2043}
2044
2045impl<'a> SessionRpcExtensions<'a> {
2046    /// Lists extensions discovered for the session and their current status.
2047    ///
2048    /// Wire method: `session.extensions.list`.
2049    ///
2050    /// # Returns
2051    ///
2052    /// Extensions discovered for the session, with their current status.
2053    ///
2054    /// <div class="warning">
2055    ///
2056    /// **Experimental.** This API is part of an experimental wire-protocol surface
2057    /// and may change or be removed in future SDK or CLI releases. Pin both the
2058    /// SDK and CLI versions if your code depends on it.
2059    ///
2060    /// </div>
2061    pub async fn list(&self) -> Result<ExtensionList, Error> {
2062        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
2063        let _value = self
2064            .session
2065            .client()
2066            .call(rpc_methods::SESSION_EXTENSIONS_LIST, Some(wire_params))
2067            .await?;
2068        Ok(serde_json::from_value(_value)?)
2069    }
2070
2071    /// Enables an extension for the session.
2072    ///
2073    /// Wire method: `session.extensions.enable`.
2074    ///
2075    /// # Parameters
2076    ///
2077    /// * `params` - Source-qualified extension identifier to enable for the session.
2078    ///
2079    /// <div class="warning">
2080    ///
2081    /// **Experimental.** This API is part of an experimental wire-protocol surface
2082    /// and may change or be removed in future SDK or CLI releases. Pin both the
2083    /// SDK and CLI versions if your code depends on it.
2084    ///
2085    /// </div>
2086    pub async fn enable(&self, params: ExtensionsEnableRequest) -> Result<(), Error> {
2087        let mut wire_params = serde_json::to_value(params)?;
2088        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
2089        let _value = self
2090            .session
2091            .client()
2092            .call(rpc_methods::SESSION_EXTENSIONS_ENABLE, Some(wire_params))
2093            .await?;
2094        Ok(())
2095    }
2096
2097    /// Disables an extension for the session.
2098    ///
2099    /// Wire method: `session.extensions.disable`.
2100    ///
2101    /// # Parameters
2102    ///
2103    /// * `params` - Source-qualified extension identifier to disable for the session.
2104    ///
2105    /// <div class="warning">
2106    ///
2107    /// **Experimental.** This API is part of an experimental wire-protocol surface
2108    /// and may change or be removed in future SDK or CLI releases. Pin both the
2109    /// SDK and CLI versions if your code depends on it.
2110    ///
2111    /// </div>
2112    pub async fn disable(&self, params: ExtensionsDisableRequest) -> Result<(), Error> {
2113        let mut wire_params = serde_json::to_value(params)?;
2114        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
2115        let _value = self
2116            .session
2117            .client()
2118            .call(rpc_methods::SESSION_EXTENSIONS_DISABLE, Some(wire_params))
2119            .await?;
2120        Ok(())
2121    }
2122
2123    /// Reloads extension definitions and processes for the session.
2124    ///
2125    /// Wire method: `session.extensions.reload`.
2126    ///
2127    /// <div class="warning">
2128    ///
2129    /// **Experimental.** This API is part of an experimental wire-protocol surface
2130    /// and may change or be removed in future SDK or CLI releases. Pin both the
2131    /// SDK and CLI versions if your code depends on it.
2132    ///
2133    /// </div>
2134    pub async fn reload(&self) -> Result<(), Error> {
2135        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
2136        let _value = self
2137            .session
2138            .client()
2139            .call(rpc_methods::SESSION_EXTENSIONS_RELOAD, Some(wire_params))
2140            .await?;
2141        Ok(())
2142    }
2143}
2144
2145/// `session.fleet.*` RPCs.
2146#[derive(Clone, Copy)]
2147pub struct SessionRpcFleet<'a> {
2148    pub(crate) session: &'a Session,
2149}
2150
2151impl<'a> SessionRpcFleet<'a> {
2152    /// Starts fleet mode by submitting the fleet orchestration prompt to the session.
2153    ///
2154    /// Wire method: `session.fleet.start`.
2155    ///
2156    /// # Parameters
2157    ///
2158    /// * `params` - Optional user prompt to combine with the fleet orchestration instructions.
2159    ///
2160    /// # Returns
2161    ///
2162    /// Indicates whether fleet mode was successfully activated.
2163    ///
2164    /// <div class="warning">
2165    ///
2166    /// **Experimental.** This API is part of an experimental wire-protocol surface
2167    /// and may change or be removed in future SDK or CLI releases. Pin both the
2168    /// SDK and CLI versions if your code depends on it.
2169    ///
2170    /// </div>
2171    pub async fn start(&self, params: FleetStartRequest) -> Result<FleetStartResult, Error> {
2172        let mut wire_params = serde_json::to_value(params)?;
2173        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
2174        let _value = self
2175            .session
2176            .client()
2177            .call(rpc_methods::SESSION_FLEET_START, Some(wire_params))
2178            .await?;
2179        Ok(serde_json::from_value(_value)?)
2180    }
2181}
2182
2183/// `session.history.*` RPCs.
2184#[derive(Clone, Copy)]
2185pub struct SessionRpcHistory<'a> {
2186    pub(crate) session: &'a Session,
2187}
2188
2189impl<'a> SessionRpcHistory<'a> {
2190    /// Compacts the session history to reduce context usage.
2191    ///
2192    /// Wire method: `session.history.compact`.
2193    ///
2194    /// # Returns
2195    ///
2196    /// Compaction outcome with the number of tokens and messages removed, summary text, and the resulting context window breakdown.
2197    ///
2198    /// <div class="warning">
2199    ///
2200    /// **Experimental.** This API is part of an experimental wire-protocol surface
2201    /// and may change or be removed in future SDK or CLI releases. Pin both the
2202    /// SDK and CLI versions if your code depends on it.
2203    ///
2204    /// </div>
2205    pub async fn compact(&self) -> Result<HistoryCompactResult, Error> {
2206        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
2207        let _value = self
2208            .session
2209            .client()
2210            .call(rpc_methods::SESSION_HISTORY_COMPACT, Some(wire_params))
2211            .await?;
2212        Ok(serde_json::from_value(_value)?)
2213    }
2214
2215    /// Compacts the session history to reduce context usage.
2216    ///
2217    /// Wire method: `session.history.compact`.
2218    ///
2219    /// # Parameters
2220    ///
2221    /// * `params` - Optional compaction parameters.
2222    ///
2223    /// # Returns
2224    ///
2225    /// Compaction outcome with the number of tokens and messages removed, summary text, and the resulting context window breakdown.
2226    ///
2227    /// <div class="warning">
2228    ///
2229    /// **Experimental.** This API is part of an experimental wire-protocol surface
2230    /// and may change or be removed in future SDK or CLI releases. Pin both the
2231    /// SDK and CLI versions if your code depends on it.
2232    ///
2233    /// </div>
2234    pub async fn compact_with_params(
2235        &self,
2236        params: HistoryCompactRequest,
2237    ) -> Result<HistoryCompactResult, Error> {
2238        let mut wire_params = serde_json::to_value(params)?;
2239        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
2240        let _value = self
2241            .session
2242            .client()
2243            .call(rpc_methods::SESSION_HISTORY_COMPACT, Some(wire_params))
2244            .await?;
2245        Ok(serde_json::from_value(_value)?)
2246    }
2247
2248    /// Truncates persisted session history to a specific event.
2249    ///
2250    /// Wire method: `session.history.truncate`.
2251    ///
2252    /// # Parameters
2253    ///
2254    /// * `params` - Identifier of the event to truncate to; this event and all later events are removed.
2255    ///
2256    /// # Returns
2257    ///
2258    /// Number of events that were removed by the truncation.
2259    ///
2260    /// <div class="warning">
2261    ///
2262    /// **Experimental.** This API is part of an experimental wire-protocol surface
2263    /// and may change or be removed in future SDK or CLI releases. Pin both the
2264    /// SDK and CLI versions if your code depends on it.
2265    ///
2266    /// </div>
2267    pub async fn truncate(
2268        &self,
2269        params: HistoryTruncateRequest,
2270    ) -> Result<HistoryTruncateResult, Error> {
2271        let mut wire_params = serde_json::to_value(params)?;
2272        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
2273        let _value = self
2274            .session
2275            .client()
2276            .call(rpc_methods::SESSION_HISTORY_TRUNCATE, Some(wire_params))
2277            .await?;
2278        Ok(serde_json::from_value(_value)?)
2279    }
2280
2281    /// Cancels any in-progress background compaction on a local session.
2282    ///
2283    /// Wire method: `session.history.cancelBackgroundCompaction`.
2284    ///
2285    /// # Returns
2286    ///
2287    /// Indicates whether an in-progress background compaction was cancelled.
2288    ///
2289    /// <div class="warning">
2290    ///
2291    /// **Experimental.** This API is part of an experimental wire-protocol surface
2292    /// and may change or be removed in future SDK or CLI releases. Pin both the
2293    /// SDK and CLI versions if your code depends on it.
2294    ///
2295    /// </div>
2296    pub async fn cancel_background_compaction(
2297        &self,
2298    ) -> Result<HistoryCancelBackgroundCompactionResult, Error> {
2299        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
2300        let _value = self
2301            .session
2302            .client()
2303            .call(
2304                rpc_methods::SESSION_HISTORY_CANCELBACKGROUNDCOMPACTION,
2305                Some(wire_params),
2306            )
2307            .await?;
2308        Ok(serde_json::from_value(_value)?)
2309    }
2310
2311    /// Aborts any in-progress manual compaction on a local session.
2312    ///
2313    /// Wire method: `session.history.abortManualCompaction`.
2314    ///
2315    /// # Returns
2316    ///
2317    /// Indicates whether an in-progress manual compaction was aborted.
2318    ///
2319    /// <div class="warning">
2320    ///
2321    /// **Experimental.** This API is part of an experimental wire-protocol surface
2322    /// and may change or be removed in future SDK or CLI releases. Pin both the
2323    /// SDK and CLI versions if your code depends on it.
2324    ///
2325    /// </div>
2326    pub async fn abort_manual_compaction(
2327        &self,
2328    ) -> Result<HistoryAbortManualCompactionResult, Error> {
2329        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
2330        let _value = self
2331            .session
2332            .client()
2333            .call(
2334                rpc_methods::SESSION_HISTORY_ABORTMANUALCOMPACTION,
2335                Some(wire_params),
2336            )
2337            .await?;
2338        Ok(serde_json::from_value(_value)?)
2339    }
2340
2341    /// Produces a markdown summary of the session's conversation context for hand-off scenarios.
2342    ///
2343    /// Wire method: `session.history.summarizeForHandoff`.
2344    ///
2345    /// # Returns
2346    ///
2347    /// Markdown summary of the conversation context (empty when not available).
2348    ///
2349    /// <div class="warning">
2350    ///
2351    /// **Experimental.** This API is part of an experimental wire-protocol surface
2352    /// and may change or be removed in future SDK or CLI releases. Pin both the
2353    /// SDK and CLI versions if your code depends on it.
2354    ///
2355    /// </div>
2356    pub async fn summarize_for_handoff(&self) -> Result<HistorySummarizeForHandoffResult, Error> {
2357        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
2358        let _value = self
2359            .session
2360            .client()
2361            .call(
2362                rpc_methods::SESSION_HISTORY_SUMMARIZEFORHANDOFF,
2363                Some(wire_params),
2364            )
2365            .await?;
2366        Ok(serde_json::from_value(_value)?)
2367    }
2368}
2369
2370/// `session.instructions.*` RPCs.
2371#[derive(Clone, Copy)]
2372pub struct SessionRpcInstructions<'a> {
2373    pub(crate) session: &'a Session,
2374}
2375
2376impl<'a> SessionRpcInstructions<'a> {
2377    /// Gets instruction sources loaded for the session.
2378    ///
2379    /// Wire method: `session.instructions.getSources`.
2380    ///
2381    /// # Returns
2382    ///
2383    /// Instruction sources loaded for the session, in merge order.
2384    ///
2385    /// <div class="warning">
2386    ///
2387    /// **Experimental.** This API is part of an experimental wire-protocol surface
2388    /// and may change or be removed in future SDK or CLI releases. Pin both the
2389    /// SDK and CLI versions if your code depends on it.
2390    ///
2391    /// </div>
2392    pub async fn get_sources(&self) -> Result<InstructionsGetSourcesResult, Error> {
2393        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
2394        let _value = self
2395            .session
2396            .client()
2397            .call(
2398                rpc_methods::SESSION_INSTRUCTIONS_GETSOURCES,
2399                Some(wire_params),
2400            )
2401            .await?;
2402        Ok(serde_json::from_value(_value)?)
2403    }
2404}
2405
2406/// `session.lsp.*` RPCs.
2407#[derive(Clone, Copy)]
2408pub struct SessionRpcLsp<'a> {
2409    pub(crate) session: &'a Session,
2410}
2411
2412impl<'a> SessionRpcLsp<'a> {
2413    /// Loads the merged LSP configuration set for the session's working directory.
2414    ///
2415    /// Wire method: `session.lsp.initialize`.
2416    ///
2417    /// # Parameters
2418    ///
2419    /// * `params` - Parameters for (re)loading the merged LSP configuration set.
2420    ///
2421    /// <div class="warning">
2422    ///
2423    /// **Experimental.** This API is part of an experimental wire-protocol surface
2424    /// and may change or be removed in future SDK or CLI releases. Pin both the
2425    /// SDK and CLI versions if your code depends on it.
2426    ///
2427    /// </div>
2428    pub async fn initialize(&self, params: LspInitializeRequest) -> Result<(), Error> {
2429        let mut wire_params = serde_json::to_value(params)?;
2430        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
2431        let _value = self
2432            .session
2433            .client()
2434            .call(rpc_methods::SESSION_LSP_INITIALIZE, Some(wire_params))
2435            .await?;
2436        Ok(())
2437    }
2438}
2439
2440/// `session.mcp.*` RPCs.
2441#[derive(Clone, Copy)]
2442pub struct SessionRpcMcp<'a> {
2443    pub(crate) session: &'a Session,
2444}
2445
2446impl<'a> SessionRpcMcp<'a> {
2447    /// `session.mcp.oauth.*` sub-namespace.
2448    pub fn oauth(&self) -> SessionRpcMcpOauth<'a> {
2449        SessionRpcMcpOauth {
2450            session: self.session,
2451        }
2452    }
2453
2454    /// Lists MCP servers configured for the session and their connection status.
2455    ///
2456    /// Wire method: `session.mcp.list`.
2457    ///
2458    /// # Returns
2459    ///
2460    /// MCP servers configured for the session, with their connection status.
2461    ///
2462    /// <div class="warning">
2463    ///
2464    /// **Experimental.** This API is part of an experimental wire-protocol surface
2465    /// and may change or be removed in future SDK or CLI releases. Pin both the
2466    /// SDK and CLI versions if your code depends on it.
2467    ///
2468    /// </div>
2469    pub async fn list(&self) -> Result<McpServerList, Error> {
2470        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
2471        let _value = self
2472            .session
2473            .client()
2474            .call(rpc_methods::SESSION_MCP_LIST, Some(wire_params))
2475            .await?;
2476        Ok(serde_json::from_value(_value)?)
2477    }
2478
2479    /// Enables an MCP server for the session.
2480    ///
2481    /// Wire method: `session.mcp.enable`.
2482    ///
2483    /// # Parameters
2484    ///
2485    /// * `params` - Name of the MCP server to enable for the session.
2486    ///
2487    /// <div class="warning">
2488    ///
2489    /// **Experimental.** This API is part of an experimental wire-protocol surface
2490    /// and may change or be removed in future SDK or CLI releases. Pin both the
2491    /// SDK and CLI versions if your code depends on it.
2492    ///
2493    /// </div>
2494    pub async fn enable(&self, params: McpEnableRequest) -> Result<(), Error> {
2495        let mut wire_params = serde_json::to_value(params)?;
2496        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
2497        let _value = self
2498            .session
2499            .client()
2500            .call(rpc_methods::SESSION_MCP_ENABLE, Some(wire_params))
2501            .await?;
2502        Ok(())
2503    }
2504
2505    /// Disables an MCP server for the session.
2506    ///
2507    /// Wire method: `session.mcp.disable`.
2508    ///
2509    /// # Parameters
2510    ///
2511    /// * `params` - Name of the MCP server to disable for the session.
2512    ///
2513    /// <div class="warning">
2514    ///
2515    /// **Experimental.** This API is part of an experimental wire-protocol surface
2516    /// and may change or be removed in future SDK or CLI releases. Pin both the
2517    /// SDK and CLI versions if your code depends on it.
2518    ///
2519    /// </div>
2520    pub async fn disable(&self, params: McpDisableRequest) -> Result<(), Error> {
2521        let mut wire_params = serde_json::to_value(params)?;
2522        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
2523        let _value = self
2524            .session
2525            .client()
2526            .call(rpc_methods::SESSION_MCP_DISABLE, Some(wire_params))
2527            .await?;
2528        Ok(())
2529    }
2530
2531    /// Reloads MCP server connections for the session.
2532    ///
2533    /// Wire method: `session.mcp.reload`.
2534    ///
2535    /// <div class="warning">
2536    ///
2537    /// **Experimental.** This API is part of an experimental wire-protocol surface
2538    /// and may change or be removed in future SDK or CLI releases. Pin both the
2539    /// SDK and CLI versions if your code depends on it.
2540    ///
2541    /// </div>
2542    pub async fn reload(&self) -> Result<(), Error> {
2543        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
2544        let _value = self
2545            .session
2546            .client()
2547            .call(rpc_methods::SESSION_MCP_RELOAD, Some(wire_params))
2548            .await?;
2549        Ok(())
2550    }
2551
2552    /// Runs an MCP sampling inference on behalf of an MCP server.
2553    ///
2554    /// Wire method: `session.mcp.executeSampling`.
2555    ///
2556    /// # Parameters
2557    ///
2558    /// * `params` - Identifiers and raw MCP CreateMessageRequest params used to run a sampling inference.
2559    ///
2560    /// # Returns
2561    ///
2562    /// Outcome of an MCP sampling execution: success result, failure error, or cancellation.
2563    ///
2564    /// <div class="warning">
2565    ///
2566    /// **Experimental.** This API is part of an experimental wire-protocol surface
2567    /// and may change or be removed in future SDK or CLI releases. Pin both the
2568    /// SDK and CLI versions if your code depends on it.
2569    ///
2570    /// </div>
2571    pub async fn execute_sampling(
2572        &self,
2573        params: McpExecuteSamplingParams,
2574    ) -> Result<McpSamplingExecutionResult, Error> {
2575        let mut wire_params = serde_json::to_value(params)?;
2576        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
2577        let _value = self
2578            .session
2579            .client()
2580            .call(rpc_methods::SESSION_MCP_EXECUTESAMPLING, Some(wire_params))
2581            .await?;
2582        Ok(serde_json::from_value(_value)?)
2583    }
2584
2585    /// Cancels an in-flight MCP sampling execution by request ID.
2586    ///
2587    /// Wire method: `session.mcp.cancelSamplingExecution`.
2588    ///
2589    /// # Parameters
2590    ///
2591    /// * `params` - The requestId previously passed to executeSampling that should be cancelled.
2592    ///
2593    /// # Returns
2594    ///
2595    /// Indicates whether an in-flight sampling execution with the given requestId was found and cancelled.
2596    ///
2597    /// <div class="warning">
2598    ///
2599    /// **Experimental.** This API is part of an experimental wire-protocol surface
2600    /// and may change or be removed in future SDK or CLI releases. Pin both the
2601    /// SDK and CLI versions if your code depends on it.
2602    ///
2603    /// </div>
2604    pub async fn cancel_sampling_execution(
2605        &self,
2606        params: McpCancelSamplingExecutionParams,
2607    ) -> Result<McpCancelSamplingExecutionResult, Error> {
2608        let mut wire_params = serde_json::to_value(params)?;
2609        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
2610        let _value = self
2611            .session
2612            .client()
2613            .call(
2614                rpc_methods::SESSION_MCP_CANCELSAMPLINGEXECUTION,
2615                Some(wire_params),
2616            )
2617            .await?;
2618        Ok(serde_json::from_value(_value)?)
2619    }
2620
2621    /// Sets how environment-variable values supplied to MCP servers are resolved (direct or indirect).
2622    ///
2623    /// Wire method: `session.mcp.setEnvValueMode`.
2624    ///
2625    /// # Parameters
2626    ///
2627    /// * `params` - Mode controlling how MCP server env values are resolved (`direct` or `indirect`).
2628    ///
2629    /// # Returns
2630    ///
2631    /// Env-value mode recorded on the session after the update.
2632    ///
2633    /// <div class="warning">
2634    ///
2635    /// **Experimental.** This API is part of an experimental wire-protocol surface
2636    /// and may change or be removed in future SDK or CLI releases. Pin both the
2637    /// SDK and CLI versions if your code depends on it.
2638    ///
2639    /// </div>
2640    pub async fn set_env_value_mode(
2641        &self,
2642        params: McpSetEnvValueModeParams,
2643    ) -> Result<McpSetEnvValueModeResult, Error> {
2644        let mut wire_params = serde_json::to_value(params)?;
2645        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
2646        let _value = self
2647            .session
2648            .client()
2649            .call(rpc_methods::SESSION_MCP_SETENVVALUEMODE, Some(wire_params))
2650            .await?;
2651        Ok(serde_json::from_value(_value)?)
2652    }
2653
2654    /// Removes the auto-managed `github` MCP server when present.
2655    ///
2656    /// Wire method: `session.mcp.removeGitHub`.
2657    ///
2658    /// # Returns
2659    ///
2660    /// Indicates whether the auto-managed `github` MCP server was removed (false when nothing to remove).
2661    ///
2662    /// <div class="warning">
2663    ///
2664    /// **Experimental.** This API is part of an experimental wire-protocol surface
2665    /// and may change or be removed in future SDK or CLI releases. Pin both the
2666    /// SDK and CLI versions if your code depends on it.
2667    ///
2668    /// </div>
2669    pub async fn remove_git_hub(&self) -> Result<McpRemoveGitHubResult, Error> {
2670        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
2671        let _value = self
2672            .session
2673            .client()
2674            .call(rpc_methods::SESSION_MCP_REMOVEGITHUB, Some(wire_params))
2675            .await?;
2676        Ok(serde_json::from_value(_value)?)
2677    }
2678}
2679
2680/// `session.mcp.oauth.*` RPCs.
2681#[derive(Clone, Copy)]
2682pub struct SessionRpcMcpOauth<'a> {
2683    pub(crate) session: &'a Session,
2684}
2685
2686impl<'a> SessionRpcMcpOauth<'a> {
2687    /// Starts OAuth authentication for a remote MCP server.
2688    ///
2689    /// Wire method: `session.mcp.oauth.login`.
2690    ///
2691    /// # Parameters
2692    ///
2693    /// * `params` - Remote MCP server name and optional overrides controlling reauthentication, OAuth client display name, and the callback success-page copy.
2694    ///
2695    /// # Returns
2696    ///
2697    /// OAuth authorization URL the caller should open, or empty when cached tokens already authenticated the server.
2698    ///
2699    /// <div class="warning">
2700    ///
2701    /// **Experimental.** This API is part of an experimental wire-protocol surface
2702    /// and may change or be removed in future SDK or CLI releases. Pin both the
2703    /// SDK and CLI versions if your code depends on it.
2704    ///
2705    /// </div>
2706    pub async fn login(&self, params: McpOauthLoginRequest) -> Result<McpOauthLoginResult, Error> {
2707        let mut wire_params = serde_json::to_value(params)?;
2708        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
2709        let _value = self
2710            .session
2711            .client()
2712            .call(rpc_methods::SESSION_MCP_OAUTH_LOGIN, Some(wire_params))
2713            .await?;
2714        Ok(serde_json::from_value(_value)?)
2715    }
2716}
2717
2718/// `session.metadata.*` RPCs.
2719#[derive(Clone, Copy)]
2720pub struct SessionRpcMetadata<'a> {
2721    pub(crate) session: &'a Session,
2722}
2723
2724impl<'a> SessionRpcMetadata<'a> {
2725    /// Returns a snapshot of the session's identifying metadata, mode, agent, and remote info.
2726    ///
2727    /// Wire method: `session.metadata.snapshot`.
2728    ///
2729    /// # Returns
2730    ///
2731    /// Point-in-time snapshot of slow-changing session identifier and state fields
2732    ///
2733    /// <div class="warning">
2734    ///
2735    /// **Experimental.** This API is part of an experimental wire-protocol surface
2736    /// and may change or be removed in future SDK or CLI releases. Pin both the
2737    /// SDK and CLI versions if your code depends on it.
2738    ///
2739    /// </div>
2740    pub async fn snapshot(&self) -> Result<SessionMetadataSnapshot, Error> {
2741        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
2742        let _value = self
2743            .session
2744            .client()
2745            .call(rpc_methods::SESSION_METADATA_SNAPSHOT, Some(wire_params))
2746            .await?;
2747        Ok(serde_json::from_value(_value)?)
2748    }
2749
2750    /// Reports whether the local session is currently processing user/agent messages.
2751    ///
2752    /// Wire method: `session.metadata.isProcessing`.
2753    ///
2754    /// # Returns
2755    ///
2756    /// Indicates whether the local session is currently processing a turn or background continuation.
2757    ///
2758    /// <div class="warning">
2759    ///
2760    /// **Experimental.** This API is part of an experimental wire-protocol surface
2761    /// and may change or be removed in future SDK or CLI releases. Pin both the
2762    /// SDK and CLI versions if your code depends on it.
2763    ///
2764    /// </div>
2765    pub async fn is_processing(&self) -> Result<MetadataIsProcessingResult, Error> {
2766        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
2767        let _value = self
2768            .session
2769            .client()
2770            .call(
2771                rpc_methods::SESSION_METADATA_ISPROCESSING,
2772                Some(wire_params),
2773            )
2774            .await?;
2775        Ok(serde_json::from_value(_value)?)
2776    }
2777
2778    /// Returns the token breakdown for the session's current context window for a given model.
2779    ///
2780    /// Wire method: `session.metadata.contextInfo`.
2781    ///
2782    /// # Parameters
2783    ///
2784    /// * `params` - Model identifier and token limits used to compute the context-info breakdown.
2785    ///
2786    /// # Returns
2787    ///
2788    /// Token breakdown for the session's current context window, or null if uninitialized.
2789    ///
2790    /// <div class="warning">
2791    ///
2792    /// **Experimental.** This API is part of an experimental wire-protocol surface
2793    /// and may change or be removed in future SDK or CLI releases. Pin both the
2794    /// SDK and CLI versions if your code depends on it.
2795    ///
2796    /// </div>
2797    pub async fn context_info(
2798        &self,
2799        params: MetadataContextInfoRequest,
2800    ) -> Result<MetadataContextInfoResult, Error> {
2801        let mut wire_params = serde_json::to_value(params)?;
2802        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
2803        let _value = self
2804            .session
2805            .client()
2806            .call(rpc_methods::SESSION_METADATA_CONTEXTINFO, Some(wire_params))
2807            .await?;
2808        Ok(serde_json::from_value(_value)?)
2809    }
2810
2811    /// Records a working-directory/git context change and emits a `session.context_changed` event.
2812    ///
2813    /// Wire method: `session.metadata.recordContextChange`.
2814    ///
2815    /// # Parameters
2816    ///
2817    /// * `params` - Updated working-directory/git context to record on the session.
2818    ///
2819    /// # Returns
2820    ///
2821    /// 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).
2822    ///
2823    /// <div class="warning">
2824    ///
2825    /// **Experimental.** This API is part of an experimental wire-protocol surface
2826    /// and may change or be removed in future SDK or CLI releases. Pin both the
2827    /// SDK and CLI versions if your code depends on it.
2828    ///
2829    /// </div>
2830    pub async fn record_context_change(
2831        &self,
2832        params: MetadataRecordContextChangeRequest,
2833    ) -> Result<MetadataRecordContextChangeResult, Error> {
2834        let mut wire_params = serde_json::to_value(params)?;
2835        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
2836        let _value = self
2837            .session
2838            .client()
2839            .call(
2840                rpc_methods::SESSION_METADATA_RECORDCONTEXTCHANGE,
2841                Some(wire_params),
2842            )
2843            .await?;
2844        Ok(serde_json::from_value(_value)?)
2845    }
2846
2847    /// Updates the session's recorded working directory.
2848    ///
2849    /// Wire method: `session.metadata.setWorkingDirectory`.
2850    ///
2851    /// # Parameters
2852    ///
2853    /// * `params` - Absolute path to set as the session's new working directory.
2854    ///
2855    /// # Returns
2856    ///
2857    /// 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 `process.chdir` and any related side-effects (file index, etc.); this method only updates the session's own recorded path.
2858    ///
2859    /// <div class="warning">
2860    ///
2861    /// **Experimental.** This API is part of an experimental wire-protocol surface
2862    /// and may change or be removed in future SDK or CLI releases. Pin both the
2863    /// SDK and CLI versions if your code depends on it.
2864    ///
2865    /// </div>
2866    pub async fn set_working_directory(
2867        &self,
2868        params: MetadataSetWorkingDirectoryRequest,
2869    ) -> Result<MetadataSetWorkingDirectoryResult, Error> {
2870        let mut wire_params = serde_json::to_value(params)?;
2871        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
2872        let _value = self
2873            .session
2874            .client()
2875            .call(
2876                rpc_methods::SESSION_METADATA_SETWORKINGDIRECTORY,
2877                Some(wire_params),
2878            )
2879            .await?;
2880        Ok(serde_json::from_value(_value)?)
2881    }
2882
2883    /// Re-tokenizes the session's existing messages against a model and returns aggregate token totals.
2884    ///
2885    /// Wire method: `session.metadata.recomputeContextTokens`.
2886    ///
2887    /// # Parameters
2888    ///
2889    /// * `params` - Model identifier to use when re-tokenizing the session's existing messages.
2890    ///
2891    /// # Returns
2892    ///
2893    /// 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.
2894    ///
2895    /// <div class="warning">
2896    ///
2897    /// **Experimental.** This API is part of an experimental wire-protocol surface
2898    /// and may change or be removed in future SDK or CLI releases. Pin both the
2899    /// SDK and CLI versions if your code depends on it.
2900    ///
2901    /// </div>
2902    pub async fn recompute_context_tokens(
2903        &self,
2904        params: MetadataRecomputeContextTokensRequest,
2905    ) -> Result<MetadataRecomputeContextTokensResult, Error> {
2906        let mut wire_params = serde_json::to_value(params)?;
2907        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
2908        let _value = self
2909            .session
2910            .client()
2911            .call(
2912                rpc_methods::SESSION_METADATA_RECOMPUTECONTEXTTOKENS,
2913                Some(wire_params),
2914            )
2915            .await?;
2916        Ok(serde_json::from_value(_value)?)
2917    }
2918}
2919
2920/// `session.mode.*` RPCs.
2921#[derive(Clone, Copy)]
2922pub struct SessionRpcMode<'a> {
2923    pub(crate) session: &'a Session,
2924}
2925
2926impl<'a> SessionRpcMode<'a> {
2927    /// Gets the current agent interaction mode.
2928    ///
2929    /// Wire method: `session.mode.get`.
2930    ///
2931    /// # Returns
2932    ///
2933    /// The session mode the agent is operating in
2934    ///
2935    /// <div class="warning">
2936    ///
2937    /// **Experimental.** This API is part of an experimental wire-protocol surface
2938    /// and may change or be removed in future SDK or CLI releases. Pin both the
2939    /// SDK and CLI versions if your code depends on it.
2940    ///
2941    /// </div>
2942    pub async fn get(&self) -> Result<SessionMode, Error> {
2943        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
2944        let _value = self
2945            .session
2946            .client()
2947            .call(rpc_methods::SESSION_MODE_GET, Some(wire_params))
2948            .await?;
2949        Ok(serde_json::from_value(_value)?)
2950    }
2951
2952    /// Sets the current agent interaction mode.
2953    ///
2954    /// Wire method: `session.mode.set`.
2955    ///
2956    /// # Parameters
2957    ///
2958    /// * `params` - Agent interaction mode to apply to the session.
2959    ///
2960    /// <div class="warning">
2961    ///
2962    /// **Experimental.** This API is part of an experimental wire-protocol surface
2963    /// and may change or be removed in future SDK or CLI releases. Pin both the
2964    /// SDK and CLI versions if your code depends on it.
2965    ///
2966    /// </div>
2967    pub async fn set(&self, params: ModeSetRequest) -> Result<(), Error> {
2968        let mut wire_params = serde_json::to_value(params)?;
2969        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
2970        let _value = self
2971            .session
2972            .client()
2973            .call(rpc_methods::SESSION_MODE_SET, Some(wire_params))
2974            .await?;
2975        Ok(())
2976    }
2977}
2978
2979/// `session.model.*` RPCs.
2980#[derive(Clone, Copy)]
2981pub struct SessionRpcModel<'a> {
2982    pub(crate) session: &'a Session,
2983}
2984
2985impl<'a> SessionRpcModel<'a> {
2986    /// Gets the currently selected model for the session.
2987    ///
2988    /// Wire method: `session.model.getCurrent`.
2989    ///
2990    /// # Returns
2991    ///
2992    /// The currently selected model and reasoning effort for the session.
2993    ///
2994    /// <div class="warning">
2995    ///
2996    /// **Experimental.** This API is part of an experimental wire-protocol surface
2997    /// and may change or be removed in future SDK or CLI releases. Pin both the
2998    /// SDK and CLI versions if your code depends on it.
2999    ///
3000    /// </div>
3001    pub async fn get_current(&self) -> Result<CurrentModel, Error> {
3002        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
3003        let _value = self
3004            .session
3005            .client()
3006            .call(rpc_methods::SESSION_MODEL_GETCURRENT, Some(wire_params))
3007            .await?;
3008        Ok(serde_json::from_value(_value)?)
3009    }
3010
3011    /// Switches the session to a model and optional reasoning configuration.
3012    ///
3013    /// Wire method: `session.model.switchTo`.
3014    ///
3015    /// # Parameters
3016    ///
3017    /// * `params` - Target model identifier and optional reasoning effort, summary, and capability overrides.
3018    ///
3019    /// # Returns
3020    ///
3021    /// The model identifier active on the session after the switch.
3022    ///
3023    /// <div class="warning">
3024    ///
3025    /// **Experimental.** This API is part of an experimental wire-protocol surface
3026    /// and may change or be removed in future SDK or CLI releases. Pin both the
3027    /// SDK and CLI versions if your code depends on it.
3028    ///
3029    /// </div>
3030    pub async fn switch_to(
3031        &self,
3032        params: ModelSwitchToRequest,
3033    ) -> Result<ModelSwitchToResult, Error> {
3034        let mut wire_params = serde_json::to_value(params)?;
3035        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3036        let _value = self
3037            .session
3038            .client()
3039            .call(rpc_methods::SESSION_MODEL_SWITCHTO, Some(wire_params))
3040            .await?;
3041        Ok(serde_json::from_value(_value)?)
3042    }
3043
3044    /// Updates the session's reasoning effort without changing the selected model.
3045    ///
3046    /// Wire method: `session.model.setReasoningEffort`.
3047    ///
3048    /// # Parameters
3049    ///
3050    /// * `params` - Reasoning effort level to apply to the currently selected model.
3051    ///
3052    /// # Returns
3053    ///
3054    /// 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.
3055    ///
3056    /// <div class="warning">
3057    ///
3058    /// **Experimental.** This API is part of an experimental wire-protocol surface
3059    /// and may change or be removed in future SDK or CLI releases. Pin both the
3060    /// SDK and CLI versions if your code depends on it.
3061    ///
3062    /// </div>
3063    pub async fn set_reasoning_effort(
3064        &self,
3065        params: ModelSetReasoningEffortRequest,
3066    ) -> Result<ModelSetReasoningEffortResult, Error> {
3067        let mut wire_params = serde_json::to_value(params)?;
3068        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3069        let _value = self
3070            .session
3071            .client()
3072            .call(
3073                rpc_methods::SESSION_MODEL_SETREASONINGEFFORT,
3074                Some(wire_params),
3075            )
3076            .await?;
3077        Ok(serde_json::from_value(_value)?)
3078    }
3079}
3080
3081/// `session.name.*` RPCs.
3082#[derive(Clone, Copy)]
3083pub struct SessionRpcName<'a> {
3084    pub(crate) session: &'a Session,
3085}
3086
3087impl<'a> SessionRpcName<'a> {
3088    /// Gets the session's friendly name.
3089    ///
3090    /// Wire method: `session.name.get`.
3091    ///
3092    /// # Returns
3093    ///
3094    /// The session's friendly name, or null when not yet set.
3095    ///
3096    /// <div class="warning">
3097    ///
3098    /// **Experimental.** This API is part of an experimental wire-protocol surface
3099    /// and may change or be removed in future SDK or CLI releases. Pin both the
3100    /// SDK and CLI versions if your code depends on it.
3101    ///
3102    /// </div>
3103    pub async fn get(&self) -> Result<NameGetResult, Error> {
3104        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
3105        let _value = self
3106            .session
3107            .client()
3108            .call(rpc_methods::SESSION_NAME_GET, Some(wire_params))
3109            .await?;
3110        Ok(serde_json::from_value(_value)?)
3111    }
3112
3113    /// Sets the session's friendly name.
3114    ///
3115    /// Wire method: `session.name.set`.
3116    ///
3117    /// # Parameters
3118    ///
3119    /// * `params` - New friendly name to apply to the session.
3120    ///
3121    /// <div class="warning">
3122    ///
3123    /// **Experimental.** This API is part of an experimental wire-protocol surface
3124    /// and may change or be removed in future SDK or CLI releases. Pin both the
3125    /// SDK and CLI versions if your code depends on it.
3126    ///
3127    /// </div>
3128    pub async fn set(&self, params: NameSetRequest) -> Result<(), Error> {
3129        let mut wire_params = serde_json::to_value(params)?;
3130        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3131        let _value = self
3132            .session
3133            .client()
3134            .call(rpc_methods::SESSION_NAME_SET, Some(wire_params))
3135            .await?;
3136        Ok(())
3137    }
3138
3139    /// Persists an auto-generated session summary as the session's name when no user-set name exists.
3140    ///
3141    /// Wire method: `session.name.setAuto`.
3142    ///
3143    /// # Parameters
3144    ///
3145    /// * `params` - Auto-generated session summary to apply as the session's name when no user-set name exists.
3146    ///
3147    /// # Returns
3148    ///
3149    /// Indicates whether the auto-generated summary was applied as the session's name.
3150    ///
3151    /// <div class="warning">
3152    ///
3153    /// **Experimental.** This API is part of an experimental wire-protocol surface
3154    /// and may change or be removed in future SDK or CLI releases. Pin both the
3155    /// SDK and CLI versions if your code depends on it.
3156    ///
3157    /// </div>
3158    pub async fn set_auto(&self, params: NameSetAutoRequest) -> Result<NameSetAutoResult, Error> {
3159        let mut wire_params = serde_json::to_value(params)?;
3160        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3161        let _value = self
3162            .session
3163            .client()
3164            .call(rpc_methods::SESSION_NAME_SETAUTO, Some(wire_params))
3165            .await?;
3166        Ok(serde_json::from_value(_value)?)
3167    }
3168}
3169
3170/// `session.options.*` RPCs.
3171#[derive(Clone, Copy)]
3172pub struct SessionRpcOptions<'a> {
3173    pub(crate) session: &'a Session,
3174}
3175
3176impl<'a> SessionRpcOptions<'a> {
3177    /// Patches the genuinely-mutable subset of session options.
3178    ///
3179    /// Wire method: `session.options.update`.
3180    ///
3181    /// # Parameters
3182    ///
3183    /// * `params` - Patch of mutable session options to apply to the running session.
3184    ///
3185    /// # Returns
3186    ///
3187    /// Indicates whether the session options patch was applied successfully.
3188    ///
3189    /// <div class="warning">
3190    ///
3191    /// **Experimental.** This API is part of an experimental wire-protocol surface
3192    /// and may change or be removed in future SDK or CLI releases. Pin both the
3193    /// SDK and CLI versions if your code depends on it.
3194    ///
3195    /// </div>
3196    pub async fn update(
3197        &self,
3198        params: SessionUpdateOptionsParams,
3199    ) -> Result<SessionUpdateOptionsResult, Error> {
3200        let mut wire_params = serde_json::to_value(params)?;
3201        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3202        let _value = self
3203            .session
3204            .client()
3205            .call(rpc_methods::SESSION_OPTIONS_UPDATE, Some(wire_params))
3206            .await?;
3207        Ok(serde_json::from_value(_value)?)
3208    }
3209}
3210
3211/// `session.permissions.*` RPCs.
3212#[derive(Clone, Copy)]
3213pub struct SessionRpcPermissions<'a> {
3214    pub(crate) session: &'a Session,
3215}
3216
3217impl<'a> SessionRpcPermissions<'a> {
3218    /// `session.permissions.folderTrust.*` sub-namespace.
3219    pub fn folder_trust(&self) -> SessionRpcPermissionsFolderTrust<'a> {
3220        SessionRpcPermissionsFolderTrust {
3221            session: self.session,
3222        }
3223    }
3224
3225    /// `session.permissions.locations.*` sub-namespace.
3226    pub fn locations(&self) -> SessionRpcPermissionsLocations<'a> {
3227        SessionRpcPermissionsLocations {
3228            session: self.session,
3229        }
3230    }
3231
3232    /// `session.permissions.paths.*` sub-namespace.
3233    pub fn paths(&self) -> SessionRpcPermissionsPaths<'a> {
3234        SessionRpcPermissionsPaths {
3235            session: self.session,
3236        }
3237    }
3238
3239    /// `session.permissions.urls.*` sub-namespace.
3240    pub fn urls(&self) -> SessionRpcPermissionsUrls<'a> {
3241        SessionRpcPermissionsUrls {
3242            session: self.session,
3243        }
3244    }
3245
3246    /// Replaces selected permission policy fields (rules, paths, URLs, exclusions, allow-all flags) on the session.
3247    ///
3248    /// Wire method: `session.permissions.configure`.
3249    ///
3250    /// # Parameters
3251    ///
3252    /// * `params` - Patch of permission policy fields to apply (omit a field to leave it unchanged).
3253    ///
3254    /// # Returns
3255    ///
3256    /// Indicates whether the operation succeeded.
3257    ///
3258    /// <div class="warning">
3259    ///
3260    /// **Experimental.** This API is part of an experimental wire-protocol surface
3261    /// and may change or be removed in future SDK or CLI releases. Pin both the
3262    /// SDK and CLI versions if your code depends on it.
3263    ///
3264    /// </div>
3265    pub async fn configure(
3266        &self,
3267        params: PermissionsConfigureParams,
3268    ) -> Result<PermissionsConfigureResult, Error> {
3269        let mut wire_params = serde_json::to_value(params)?;
3270        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3271        let _value = self
3272            .session
3273            .client()
3274            .call(
3275                rpc_methods::SESSION_PERMISSIONS_CONFIGURE,
3276                Some(wire_params),
3277            )
3278            .await?;
3279        Ok(serde_json::from_value(_value)?)
3280    }
3281
3282    /// Provides a decision for a pending tool permission request.
3283    ///
3284    /// Wire method: `session.permissions.handlePendingPermissionRequest`.
3285    ///
3286    /// # Parameters
3287    ///
3288    /// * `params` - Pending permission request ID and the decision to apply (approve/reject and scope).
3289    ///
3290    /// # Returns
3291    ///
3292    /// Indicates whether the permission decision was applied; false when the request was already resolved.
3293    ///
3294    /// <div class="warning">
3295    ///
3296    /// **Experimental.** This API is part of an experimental wire-protocol surface
3297    /// and may change or be removed in future SDK or CLI releases. Pin both the
3298    /// SDK and CLI versions if your code depends on it.
3299    ///
3300    /// </div>
3301    pub async fn handle_pending_permission_request(
3302        &self,
3303        params: PermissionDecisionRequest,
3304    ) -> Result<PermissionRequestResult, Error> {
3305        let mut wire_params = serde_json::to_value(params)?;
3306        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3307        let _value = self
3308            .session
3309            .client()
3310            .call(
3311                rpc_methods::SESSION_PERMISSIONS_HANDLEPENDINGPERMISSIONREQUEST,
3312                Some(wire_params),
3313            )
3314            .await?;
3315        Ok(serde_json::from_value(_value)?)
3316    }
3317
3318    /// Reconstructs the set of pending tool permission requests from the session's event history.
3319    ///
3320    /// Wire method: `session.permissions.pendingRequests`.
3321    ///
3322    /// # Returns
3323    ///
3324    /// List of pending permission requests reconstructed from event history.
3325    ///
3326    /// <div class="warning">
3327    ///
3328    /// **Experimental.** This API is part of an experimental wire-protocol surface
3329    /// and may change or be removed in future SDK or CLI releases. Pin both the
3330    /// SDK and CLI versions if your code depends on it.
3331    ///
3332    /// </div>
3333    pub async fn pending_requests(&self) -> Result<PendingPermissionRequestList, Error> {
3334        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
3335        let _value = self
3336            .session
3337            .client()
3338            .call(
3339                rpc_methods::SESSION_PERMISSIONS_PENDINGREQUESTS,
3340                Some(wire_params),
3341            )
3342            .await?;
3343        Ok(serde_json::from_value(_value)?)
3344    }
3345
3346    /// Enables or disables automatic approval of tool permission requests for the session.
3347    ///
3348    /// Wire method: `session.permissions.setApproveAll`.
3349    ///
3350    /// # Parameters
3351    ///
3352    /// * `params` - Allow-all toggle for tool permission requests, with an optional telemetry source.
3353    ///
3354    /// # Returns
3355    ///
3356    /// Indicates whether the operation succeeded.
3357    ///
3358    /// <div class="warning">
3359    ///
3360    /// **Experimental.** This API is part of an experimental wire-protocol surface
3361    /// and may change or be removed in future SDK or CLI releases. Pin both the
3362    /// SDK and CLI versions if your code depends on it.
3363    ///
3364    /// </div>
3365    pub async fn set_approve_all(
3366        &self,
3367        params: PermissionsSetApproveAllRequest,
3368    ) -> Result<PermissionsSetApproveAllResult, Error> {
3369        let mut wire_params = serde_json::to_value(params)?;
3370        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3371        let _value = self
3372            .session
3373            .client()
3374            .call(
3375                rpc_methods::SESSION_PERMISSIONS_SETAPPROVEALL,
3376                Some(wire_params),
3377            )
3378            .await?;
3379        Ok(serde_json::from_value(_value)?)
3380    }
3381
3382    /// Adds or removes session-scoped or location-scoped permission rules.
3383    ///
3384    /// Wire method: `session.permissions.modifyRules`.
3385    ///
3386    /// # Parameters
3387    ///
3388    /// * `params` - Scope and add/remove instructions for modifying session- or location-scoped permission rules.
3389    ///
3390    /// # Returns
3391    ///
3392    /// Indicates whether the operation succeeded.
3393    ///
3394    /// <div class="warning">
3395    ///
3396    /// **Experimental.** This API is part of an experimental wire-protocol surface
3397    /// and may change or be removed in future SDK or CLI releases. Pin both the
3398    /// SDK and CLI versions if your code depends on it.
3399    ///
3400    /// </div>
3401    pub async fn modify_rules(
3402        &self,
3403        params: PermissionsModifyRulesParams,
3404    ) -> Result<PermissionsModifyRulesResult, Error> {
3405        let mut wire_params = serde_json::to_value(params)?;
3406        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3407        let _value = self
3408            .session
3409            .client()
3410            .call(
3411                rpc_methods::SESSION_PERMISSIONS_MODIFYRULES,
3412                Some(wire_params),
3413            )
3414            .await?;
3415        Ok(serde_json::from_value(_value)?)
3416    }
3417
3418    /// Sets whether the client wants permission prompts bridged into session events.
3419    ///
3420    /// Wire method: `session.permissions.setRequired`.
3421    ///
3422    /// # Parameters
3423    ///
3424    /// * `params` - Toggles whether permission prompts should be bridged into session events for this client.
3425    ///
3426    /// # Returns
3427    ///
3428    /// Indicates whether the operation succeeded.
3429    ///
3430    /// <div class="warning">
3431    ///
3432    /// **Experimental.** This API is part of an experimental wire-protocol surface
3433    /// and may change or be removed in future SDK or CLI releases. Pin both the
3434    /// SDK and CLI versions if your code depends on it.
3435    ///
3436    /// </div>
3437    pub async fn set_required(
3438        &self,
3439        params: PermissionsSetRequiredRequest,
3440    ) -> Result<PermissionsSetRequiredResult, Error> {
3441        let mut wire_params = serde_json::to_value(params)?;
3442        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3443        let _value = self
3444            .session
3445            .client()
3446            .call(
3447                rpc_methods::SESSION_PERMISSIONS_SETREQUIRED,
3448                Some(wire_params),
3449            )
3450            .await?;
3451        Ok(serde_json::from_value(_value)?)
3452    }
3453
3454    /// Clears session-scoped tool permission approvals.
3455    ///
3456    /// Wire method: `session.permissions.resetSessionApprovals`.
3457    ///
3458    /// # Returns
3459    ///
3460    /// Indicates whether the operation succeeded.
3461    ///
3462    /// <div class="warning">
3463    ///
3464    /// **Experimental.** This API is part of an experimental wire-protocol surface
3465    /// and may change or be removed in future SDK or CLI releases. Pin both the
3466    /// SDK and CLI versions if your code depends on it.
3467    ///
3468    /// </div>
3469    pub async fn reset_session_approvals(
3470        &self,
3471    ) -> Result<PermissionsResetSessionApprovalsResult, Error> {
3472        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
3473        let _value = self
3474            .session
3475            .client()
3476            .call(
3477                rpc_methods::SESSION_PERMISSIONS_RESETSESSIONAPPROVALS,
3478                Some(wire_params),
3479            )
3480            .await?;
3481        Ok(serde_json::from_value(_value)?)
3482    }
3483
3484    /// Notifies the runtime that a permission prompt UI has been shown to the user.
3485    ///
3486    /// Wire method: `session.permissions.notifyPromptShown`.
3487    ///
3488    /// # Parameters
3489    ///
3490    /// * `params` - Notification payload describing the permission prompt that the client just rendered.
3491    ///
3492    /// # Returns
3493    ///
3494    /// Indicates whether the operation succeeded.
3495    ///
3496    /// <div class="warning">
3497    ///
3498    /// **Experimental.** This API is part of an experimental wire-protocol surface
3499    /// and may change or be removed in future SDK or CLI releases. Pin both the
3500    /// SDK and CLI versions if your code depends on it.
3501    ///
3502    /// </div>
3503    pub async fn notify_prompt_shown(
3504        &self,
3505        params: PermissionPromptShownNotification,
3506    ) -> Result<PermissionsNotifyPromptShownResult, Error> {
3507        let mut wire_params = serde_json::to_value(params)?;
3508        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3509        let _value = self
3510            .session
3511            .client()
3512            .call(
3513                rpc_methods::SESSION_PERMISSIONS_NOTIFYPROMPTSHOWN,
3514                Some(wire_params),
3515            )
3516            .await?;
3517        Ok(serde_json::from_value(_value)?)
3518    }
3519}
3520
3521/// `session.permissions.folderTrust.*` RPCs.
3522#[derive(Clone, Copy)]
3523pub struct SessionRpcPermissionsFolderTrust<'a> {
3524    pub(crate) session: &'a Session,
3525}
3526
3527impl<'a> SessionRpcPermissionsFolderTrust<'a> {
3528    /// Reports whether a folder is trusted according to the user's folder trust state.
3529    ///
3530    /// Wire method: `session.permissions.folderTrust.isTrusted`.
3531    ///
3532    /// # Parameters
3533    ///
3534    /// * `params` - Folder path to check for trust.
3535    ///
3536    /// # Returns
3537    ///
3538    /// Folder trust check result.
3539    ///
3540    /// <div class="warning">
3541    ///
3542    /// **Experimental.** This API is part of an experimental wire-protocol surface
3543    /// and may change or be removed in future SDK or CLI releases. Pin both the
3544    /// SDK and CLI versions if your code depends on it.
3545    ///
3546    /// </div>
3547    pub async fn is_trusted(
3548        &self,
3549        params: FolderTrustCheckParams,
3550    ) -> Result<FolderTrustCheckResult, Error> {
3551        let mut wire_params = serde_json::to_value(params)?;
3552        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3553        let _value = self
3554            .session
3555            .client()
3556            .call(
3557                rpc_methods::SESSION_PERMISSIONS_FOLDERTRUST_ISTRUSTED,
3558                Some(wire_params),
3559            )
3560            .await?;
3561        Ok(serde_json::from_value(_value)?)
3562    }
3563
3564    /// Adds a folder to the user's trusted folders list.
3565    ///
3566    /// Wire method: `session.permissions.folderTrust.addTrusted`.
3567    ///
3568    /// # Parameters
3569    ///
3570    /// * `params` - Folder path to add to trusted folders.
3571    ///
3572    /// # Returns
3573    ///
3574    /// Indicates whether the operation succeeded.
3575    ///
3576    /// <div class="warning">
3577    ///
3578    /// **Experimental.** This API is part of an experimental wire-protocol surface
3579    /// and may change or be removed in future SDK or CLI releases. Pin both the
3580    /// SDK and CLI versions if your code depends on it.
3581    ///
3582    /// </div>
3583    pub async fn add_trusted(
3584        &self,
3585        params: FolderTrustAddParams,
3586    ) -> Result<PermissionsFolderTrustAddTrustedResult, Error> {
3587        let mut wire_params = serde_json::to_value(params)?;
3588        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3589        let _value = self
3590            .session
3591            .client()
3592            .call(
3593                rpc_methods::SESSION_PERMISSIONS_FOLDERTRUST_ADDTRUSTED,
3594                Some(wire_params),
3595            )
3596            .await?;
3597        Ok(serde_json::from_value(_value)?)
3598    }
3599}
3600
3601/// `session.permissions.locations.*` RPCs.
3602#[derive(Clone, Copy)]
3603pub struct SessionRpcPermissionsLocations<'a> {
3604    pub(crate) session: &'a Session,
3605}
3606
3607impl<'a> SessionRpcPermissionsLocations<'a> {
3608    /// Resolves the permission location key and type for a working directory.
3609    ///
3610    /// Wire method: `session.permissions.locations.resolve`.
3611    ///
3612    /// # Parameters
3613    ///
3614    /// * `params` - Working directory to resolve into a location-permissions key.
3615    ///
3616    /// # Returns
3617    ///
3618    /// Resolved location-permissions key and type.
3619    ///
3620    /// <div class="warning">
3621    ///
3622    /// **Experimental.** This API is part of an experimental wire-protocol surface
3623    /// and may change or be removed in future SDK or CLI releases. Pin both the
3624    /// SDK and CLI versions if your code depends on it.
3625    ///
3626    /// </div>
3627    pub async fn resolve(
3628        &self,
3629        params: PermissionLocationResolveParams,
3630    ) -> Result<PermissionLocationResolveResult, Error> {
3631        let mut wire_params = serde_json::to_value(params)?;
3632        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3633        let _value = self
3634            .session
3635            .client()
3636            .call(
3637                rpc_methods::SESSION_PERMISSIONS_LOCATIONS_RESOLVE,
3638                Some(wire_params),
3639            )
3640            .await?;
3641        Ok(serde_json::from_value(_value)?)
3642    }
3643
3644    /// Applies persisted location-scoped tool approvals and allowed directories for a working directory to this session's permission service.
3645    ///
3646    /// Wire method: `session.permissions.locations.apply`.
3647    ///
3648    /// # Parameters
3649    ///
3650    /// * `params` - Working directory to load persisted location permissions for.
3651    ///
3652    /// # Returns
3653    ///
3654    /// Summary of persisted location permissions applied to the session.
3655    ///
3656    /// <div class="warning">
3657    ///
3658    /// **Experimental.** This API is part of an experimental wire-protocol surface
3659    /// and may change or be removed in future SDK or CLI releases. Pin both the
3660    /// SDK and CLI versions if your code depends on it.
3661    ///
3662    /// </div>
3663    pub async fn apply(
3664        &self,
3665        params: PermissionLocationApplyParams,
3666    ) -> Result<PermissionLocationApplyResult, Error> {
3667        let mut wire_params = serde_json::to_value(params)?;
3668        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3669        let _value = self
3670            .session
3671            .client()
3672            .call(
3673                rpc_methods::SESSION_PERMISSIONS_LOCATIONS_APPLY,
3674                Some(wire_params),
3675            )
3676            .await?;
3677        Ok(serde_json::from_value(_value)?)
3678    }
3679
3680    /// Persists a tool approval for a permission location and applies its rules to this session's live permission service.
3681    ///
3682    /// Wire method: `session.permissions.locations.addToolApproval`.
3683    ///
3684    /// # Parameters
3685    ///
3686    /// * `params` - Location-scoped tool approval to persist.
3687    ///
3688    /// # Returns
3689    ///
3690    /// Indicates whether the operation succeeded.
3691    ///
3692    /// <div class="warning">
3693    ///
3694    /// **Experimental.** This API is part of an experimental wire-protocol surface
3695    /// and may change or be removed in future SDK or CLI releases. Pin both the
3696    /// SDK and CLI versions if your code depends on it.
3697    ///
3698    /// </div>
3699    pub async fn add_tool_approval(
3700        &self,
3701        params: PermissionLocationAddToolApprovalParams,
3702    ) -> Result<PermissionsLocationsAddToolApprovalResult, Error> {
3703        let mut wire_params = serde_json::to_value(params)?;
3704        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3705        let _value = self
3706            .session
3707            .client()
3708            .call(
3709                rpc_methods::SESSION_PERMISSIONS_LOCATIONS_ADDTOOLAPPROVAL,
3710                Some(wire_params),
3711            )
3712            .await?;
3713        Ok(serde_json::from_value(_value)?)
3714    }
3715}
3716
3717/// `session.permissions.paths.*` RPCs.
3718#[derive(Clone, Copy)]
3719pub struct SessionRpcPermissionsPaths<'a> {
3720    pub(crate) session: &'a Session,
3721}
3722
3723impl<'a> SessionRpcPermissionsPaths<'a> {
3724    /// Returns the session's allowed directories and primary working directory.
3725    ///
3726    /// Wire method: `session.permissions.paths.list`.
3727    ///
3728    /// # Returns
3729    ///
3730    /// Snapshot of the session's allow-listed directories and primary working directory.
3731    ///
3732    /// <div class="warning">
3733    ///
3734    /// **Experimental.** This API is part of an experimental wire-protocol surface
3735    /// and may change or be removed in future SDK or CLI releases. Pin both the
3736    /// SDK and CLI versions if your code depends on it.
3737    ///
3738    /// </div>
3739    pub async fn list(&self) -> Result<PermissionPathsList, Error> {
3740        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
3741        let _value = self
3742            .session
3743            .client()
3744            .call(
3745                rpc_methods::SESSION_PERMISSIONS_PATHS_LIST,
3746                Some(wire_params),
3747            )
3748            .await?;
3749        Ok(serde_json::from_value(_value)?)
3750    }
3751
3752    /// Adds a directory to the session's allow-list.
3753    ///
3754    /// Wire method: `session.permissions.paths.add`.
3755    ///
3756    /// # Parameters
3757    ///
3758    /// * `params` - Directory path to add to the session's allowed directories.
3759    ///
3760    /// # Returns
3761    ///
3762    /// Indicates whether the operation succeeded.
3763    ///
3764    /// <div class="warning">
3765    ///
3766    /// **Experimental.** This API is part of an experimental wire-protocol surface
3767    /// and may change or be removed in future SDK or CLI releases. Pin both the
3768    /// SDK and CLI versions if your code depends on it.
3769    ///
3770    /// </div>
3771    pub async fn add(
3772        &self,
3773        params: PermissionPathsAddParams,
3774    ) -> Result<PermissionsPathsAddResult, Error> {
3775        let mut wire_params = serde_json::to_value(params)?;
3776        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3777        let _value = self
3778            .session
3779            .client()
3780            .call(
3781                rpc_methods::SESSION_PERMISSIONS_PATHS_ADD,
3782                Some(wire_params),
3783            )
3784            .await?;
3785        Ok(serde_json::from_value(_value)?)
3786    }
3787
3788    /// Updates the session's primary working directory used by the permission policy.
3789    ///
3790    /// Wire method: `session.permissions.paths.updatePrimary`.
3791    ///
3792    /// # Parameters
3793    ///
3794    /// * `params` - Directory path to set as the session's new primary working directory.
3795    ///
3796    /// # Returns
3797    ///
3798    /// Indicates whether the operation succeeded.
3799    ///
3800    /// <div class="warning">
3801    ///
3802    /// **Experimental.** This API is part of an experimental wire-protocol surface
3803    /// and may change or be removed in future SDK or CLI releases. Pin both the
3804    /// SDK and CLI versions if your code depends on it.
3805    ///
3806    /// </div>
3807    pub async fn update_primary(
3808        &self,
3809        params: PermissionPathsUpdatePrimaryParams,
3810    ) -> Result<PermissionsPathsUpdatePrimaryResult, Error> {
3811        let mut wire_params = serde_json::to_value(params)?;
3812        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3813        let _value = self
3814            .session
3815            .client()
3816            .call(
3817                rpc_methods::SESSION_PERMISSIONS_PATHS_UPDATEPRIMARY,
3818                Some(wire_params),
3819            )
3820            .await?;
3821        Ok(serde_json::from_value(_value)?)
3822    }
3823
3824    /// Reports whether a path falls within any of the session's allowed directories.
3825    ///
3826    /// Wire method: `session.permissions.paths.isPathWithinAllowedDirectories`.
3827    ///
3828    /// # Parameters
3829    ///
3830    /// * `params` - Path to evaluate against the session's allowed directories.
3831    ///
3832    /// # Returns
3833    ///
3834    /// Indicates whether the supplied path is within the session's allowed directories.
3835    ///
3836    /// <div class="warning">
3837    ///
3838    /// **Experimental.** This API is part of an experimental wire-protocol surface
3839    /// and may change or be removed in future SDK or CLI releases. Pin both the
3840    /// SDK and CLI versions if your code depends on it.
3841    ///
3842    /// </div>
3843    pub async fn is_path_within_allowed_directories(
3844        &self,
3845        params: PermissionPathsAllowedCheckParams,
3846    ) -> Result<PermissionPathsAllowedCheckResult, Error> {
3847        let mut wire_params = serde_json::to_value(params)?;
3848        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3849        let _value = self
3850            .session
3851            .client()
3852            .call(
3853                rpc_methods::SESSION_PERMISSIONS_PATHS_ISPATHWITHINALLOWEDDIRECTORIES,
3854                Some(wire_params),
3855            )
3856            .await?;
3857        Ok(serde_json::from_value(_value)?)
3858    }
3859
3860    /// Reports whether a path falls within the session's workspace (primary) directory.
3861    ///
3862    /// Wire method: `session.permissions.paths.isPathWithinWorkspace`.
3863    ///
3864    /// # Parameters
3865    ///
3866    /// * `params` - Path to evaluate against the session's workspace (primary) directory.
3867    ///
3868    /// # Returns
3869    ///
3870    /// Indicates whether the supplied path is within the session's workspace directory.
3871    ///
3872    /// <div class="warning">
3873    ///
3874    /// **Experimental.** This API is part of an experimental wire-protocol surface
3875    /// and may change or be removed in future SDK or CLI releases. Pin both the
3876    /// SDK and CLI versions if your code depends on it.
3877    ///
3878    /// </div>
3879    pub async fn is_path_within_workspace(
3880        &self,
3881        params: PermissionPathsWorkspaceCheckParams,
3882    ) -> Result<PermissionPathsWorkspaceCheckResult, Error> {
3883        let mut wire_params = serde_json::to_value(params)?;
3884        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3885        let _value = self
3886            .session
3887            .client()
3888            .call(
3889                rpc_methods::SESSION_PERMISSIONS_PATHS_ISPATHWITHINWORKSPACE,
3890                Some(wire_params),
3891            )
3892            .await?;
3893        Ok(serde_json::from_value(_value)?)
3894    }
3895}
3896
3897/// `session.permissions.urls.*` RPCs.
3898#[derive(Clone, Copy)]
3899pub struct SessionRpcPermissionsUrls<'a> {
3900    pub(crate) session: &'a Session,
3901}
3902
3903impl<'a> SessionRpcPermissionsUrls<'a> {
3904    /// Toggles the runtime's URL-permission policy between unrestricted and restricted modes.
3905    ///
3906    /// Wire method: `session.permissions.urls.setUnrestrictedMode`.
3907    ///
3908    /// # Parameters
3909    ///
3910    /// * `params` - Whether the URL-permission policy should run in unrestricted mode.
3911    ///
3912    /// # Returns
3913    ///
3914    /// Indicates whether the operation succeeded.
3915    ///
3916    /// <div class="warning">
3917    ///
3918    /// **Experimental.** This API is part of an experimental wire-protocol surface
3919    /// and may change or be removed in future SDK or CLI releases. Pin both the
3920    /// SDK and CLI versions if your code depends on it.
3921    ///
3922    /// </div>
3923    pub async fn set_unrestricted_mode(
3924        &self,
3925        params: PermissionUrlsSetUnrestrictedModeParams,
3926    ) -> Result<PermissionsUrlsSetUnrestrictedModeResult, Error> {
3927        let mut wire_params = serde_json::to_value(params)?;
3928        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3929        let _value = self
3930            .session
3931            .client()
3932            .call(
3933                rpc_methods::SESSION_PERMISSIONS_URLS_SETUNRESTRICTEDMODE,
3934                Some(wire_params),
3935            )
3936            .await?;
3937        Ok(serde_json::from_value(_value)?)
3938    }
3939}
3940
3941/// `session.plan.*` RPCs.
3942#[derive(Clone, Copy)]
3943pub struct SessionRpcPlan<'a> {
3944    pub(crate) session: &'a Session,
3945}
3946
3947impl<'a> SessionRpcPlan<'a> {
3948    /// Reads the session plan file from the workspace.
3949    ///
3950    /// Wire method: `session.plan.read`.
3951    ///
3952    /// # Returns
3953    ///
3954    /// Existence, contents, and resolved path of the session plan file.
3955    ///
3956    /// <div class="warning">
3957    ///
3958    /// **Experimental.** This API is part of an experimental wire-protocol surface
3959    /// and may change or be removed in future SDK or CLI releases. Pin both the
3960    /// SDK and CLI versions if your code depends on it.
3961    ///
3962    /// </div>
3963    pub async fn read(&self) -> Result<PlanReadResult, Error> {
3964        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
3965        let _value = self
3966            .session
3967            .client()
3968            .call(rpc_methods::SESSION_PLAN_READ, Some(wire_params))
3969            .await?;
3970        Ok(serde_json::from_value(_value)?)
3971    }
3972
3973    /// Writes new content to the session plan file.
3974    ///
3975    /// Wire method: `session.plan.update`.
3976    ///
3977    /// # Parameters
3978    ///
3979    /// * `params` - Replacement contents to write to the session plan file.
3980    ///
3981    /// <div class="warning">
3982    ///
3983    /// **Experimental.** This API is part of an experimental wire-protocol surface
3984    /// and may change or be removed in future SDK or CLI releases. Pin both the
3985    /// SDK and CLI versions if your code depends on it.
3986    ///
3987    /// </div>
3988    pub async fn update(&self, params: PlanUpdateRequest) -> Result<(), Error> {
3989        let mut wire_params = serde_json::to_value(params)?;
3990        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
3991        let _value = self
3992            .session
3993            .client()
3994            .call(rpc_methods::SESSION_PLAN_UPDATE, Some(wire_params))
3995            .await?;
3996        Ok(())
3997    }
3998
3999    /// Deletes the session plan file from the workspace.
4000    ///
4001    /// Wire method: `session.plan.delete`.
4002    ///
4003    /// <div class="warning">
4004    ///
4005    /// **Experimental.** This API is part of an experimental wire-protocol surface
4006    /// and may change or be removed in future SDK or CLI releases. Pin both the
4007    /// SDK and CLI versions if your code depends on it.
4008    ///
4009    /// </div>
4010    pub async fn delete(&self) -> Result<(), Error> {
4011        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4012        let _value = self
4013            .session
4014            .client()
4015            .call(rpc_methods::SESSION_PLAN_DELETE, Some(wire_params))
4016            .await?;
4017        Ok(())
4018    }
4019}
4020
4021/// `session.plugins.*` RPCs.
4022#[derive(Clone, Copy)]
4023pub struct SessionRpcPlugins<'a> {
4024    pub(crate) session: &'a Session,
4025}
4026
4027impl<'a> SessionRpcPlugins<'a> {
4028    /// Lists plugins installed for the session.
4029    ///
4030    /// Wire method: `session.plugins.list`.
4031    ///
4032    /// # Returns
4033    ///
4034    /// Plugins installed for the session, with their enabled state and version metadata.
4035    ///
4036    /// <div class="warning">
4037    ///
4038    /// **Experimental.** This API is part of an experimental wire-protocol surface
4039    /// and may change or be removed in future SDK or CLI releases. Pin both the
4040    /// SDK and CLI versions if your code depends on it.
4041    ///
4042    /// </div>
4043    pub async fn list(&self) -> Result<PluginList, Error> {
4044        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4045        let _value = self
4046            .session
4047            .client()
4048            .call(rpc_methods::SESSION_PLUGINS_LIST, Some(wire_params))
4049            .await?;
4050        Ok(serde_json::from_value(_value)?)
4051    }
4052}
4053
4054/// `session.queue.*` RPCs.
4055#[derive(Clone, Copy)]
4056pub struct SessionRpcQueue<'a> {
4057    pub(crate) session: &'a Session,
4058}
4059
4060impl<'a> SessionRpcQueue<'a> {
4061    /// Returns the local session's pending user-facing queued items and steering messages.
4062    ///
4063    /// Wire method: `session.queue.pendingItems`.
4064    ///
4065    /// # Returns
4066    ///
4067    /// Snapshot of the session's pending queued items and immediate-steering messages.
4068    ///
4069    /// <div class="warning">
4070    ///
4071    /// **Experimental.** This API is part of an experimental wire-protocol surface
4072    /// and may change or be removed in future SDK or CLI releases. Pin both the
4073    /// SDK and CLI versions if your code depends on it.
4074    ///
4075    /// </div>
4076    pub async fn pending_items(&self) -> Result<QueuePendingItemsResult, Error> {
4077        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4078        let _value = self
4079            .session
4080            .client()
4081            .call(rpc_methods::SESSION_QUEUE_PENDINGITEMS, Some(wire_params))
4082            .await?;
4083        Ok(serde_json::from_value(_value)?)
4084    }
4085
4086    /// Removes the most recently queued user-facing item (LIFO).
4087    ///
4088    /// Wire method: `session.queue.removeMostRecent`.
4089    ///
4090    /// # Returns
4091    ///
4092    /// Indicates whether a user-facing pending item was removed.
4093    ///
4094    /// <div class="warning">
4095    ///
4096    /// **Experimental.** This API is part of an experimental wire-protocol surface
4097    /// and may change or be removed in future SDK or CLI releases. Pin both the
4098    /// SDK and CLI versions if your code depends on it.
4099    ///
4100    /// </div>
4101    pub async fn remove_most_recent(&self) -> Result<QueueRemoveMostRecentResult, Error> {
4102        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4103        let _value = self
4104            .session
4105            .client()
4106            .call(
4107                rpc_methods::SESSION_QUEUE_REMOVEMOSTRECENT,
4108                Some(wire_params),
4109            )
4110            .await?;
4111        Ok(serde_json::from_value(_value)?)
4112    }
4113
4114    /// Clears all pending queued items on the local session.
4115    ///
4116    /// Wire method: `session.queue.clear`.
4117    ///
4118    /// <div class="warning">
4119    ///
4120    /// **Experimental.** This API is part of an experimental wire-protocol surface
4121    /// and may change or be removed in future SDK or CLI releases. Pin both the
4122    /// SDK and CLI versions if your code depends on it.
4123    ///
4124    /// </div>
4125    pub async fn clear(&self) -> Result<(), Error> {
4126        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4127        let _value = self
4128            .session
4129            .client()
4130            .call(rpc_methods::SESSION_QUEUE_CLEAR, Some(wire_params))
4131            .await?;
4132        Ok(())
4133    }
4134}
4135
4136/// `session.remote.*` RPCs.
4137#[derive(Clone, Copy)]
4138pub struct SessionRpcRemote<'a> {
4139    pub(crate) session: &'a Session,
4140}
4141
4142impl<'a> SessionRpcRemote<'a> {
4143    /// Enables remote session export or steering.
4144    ///
4145    /// Wire method: `session.remote.enable`.
4146    ///
4147    /// # Parameters
4148    ///
4149    /// * `params` - Optional remote session mode ("off", "export", or "on"); defaults to enabling both export and remote steering.
4150    ///
4151    /// # Returns
4152    ///
4153    /// GitHub URL for the session and a flag indicating whether remote steering is enabled.
4154    ///
4155    /// <div class="warning">
4156    ///
4157    /// **Experimental.** This API is part of an experimental wire-protocol surface
4158    /// and may change or be removed in future SDK or CLI releases. Pin both the
4159    /// SDK and CLI versions if your code depends on it.
4160    ///
4161    /// </div>
4162    pub async fn enable(&self, params: RemoteEnableRequest) -> Result<RemoteEnableResult, Error> {
4163        let mut wire_params = serde_json::to_value(params)?;
4164        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4165        let _value = self
4166            .session
4167            .client()
4168            .call(rpc_methods::SESSION_REMOTE_ENABLE, Some(wire_params))
4169            .await?;
4170        Ok(serde_json::from_value(_value)?)
4171    }
4172
4173    /// Disables remote session export and steering.
4174    ///
4175    /// Wire method: `session.remote.disable`.
4176    ///
4177    /// <div class="warning">
4178    ///
4179    /// **Experimental.** This API is part of an experimental wire-protocol surface
4180    /// and may change or be removed in future SDK or CLI releases. Pin both the
4181    /// SDK and CLI versions if your code depends on it.
4182    ///
4183    /// </div>
4184    pub async fn disable(&self) -> Result<(), Error> {
4185        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4186        let _value = self
4187            .session
4188            .client()
4189            .call(rpc_methods::SESSION_REMOTE_DISABLE, Some(wire_params))
4190            .await?;
4191        Ok(())
4192    }
4193
4194    /// Persists a remote-steerability change emitted by the host as a session event.
4195    ///
4196    /// Wire method: `session.remote.notifySteerableChanged`.
4197    ///
4198    /// # Parameters
4199    ///
4200    /// * `params` - New remote-steerability state to persist as a `session.remote_steerable_changed` event.
4201    ///
4202    /// # Returns
4203    ///
4204    /// 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.
4205    ///
4206    /// <div class="warning">
4207    ///
4208    /// **Experimental.** This API is part of an experimental wire-protocol surface
4209    /// and may change or be removed in future SDK or CLI releases. Pin both the
4210    /// SDK and CLI versions if your code depends on it.
4211    ///
4212    /// </div>
4213    pub async fn notify_steerable_changed(
4214        &self,
4215        params: RemoteNotifySteerableChangedRequest,
4216    ) -> Result<RemoteNotifySteerableChangedResult, Error> {
4217        let mut wire_params = serde_json::to_value(params)?;
4218        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4219        let _value = self
4220            .session
4221            .client()
4222            .call(
4223                rpc_methods::SESSION_REMOTE_NOTIFYSTEERABLECHANGED,
4224                Some(wire_params),
4225            )
4226            .await?;
4227        Ok(serde_json::from_value(_value)?)
4228    }
4229}
4230
4231/// `session.schedule.*` RPCs.
4232#[derive(Clone, Copy)]
4233pub struct SessionRpcSchedule<'a> {
4234    pub(crate) session: &'a Session,
4235}
4236
4237impl<'a> SessionRpcSchedule<'a> {
4238    /// Lists the session's currently active scheduled prompts.
4239    ///
4240    /// Wire method: `session.schedule.list`.
4241    ///
4242    /// # Returns
4243    ///
4244    /// Snapshot of the currently active recurring prompts for this session.
4245    ///
4246    /// <div class="warning">
4247    ///
4248    /// **Experimental.** This API is part of an experimental wire-protocol surface
4249    /// and may change or be removed in future SDK or CLI releases. Pin both the
4250    /// SDK and CLI versions if your code depends on it.
4251    ///
4252    /// </div>
4253    pub async fn list(&self) -> Result<ScheduleList, Error> {
4254        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4255        let _value = self
4256            .session
4257            .client()
4258            .call(rpc_methods::SESSION_SCHEDULE_LIST, Some(wire_params))
4259            .await?;
4260        Ok(serde_json::from_value(_value)?)
4261    }
4262
4263    /// Removes a scheduled prompt by id.
4264    ///
4265    /// Wire method: `session.schedule.stop`.
4266    ///
4267    /// # Parameters
4268    ///
4269    /// * `params` - Identifier of the scheduled prompt to remove.
4270    ///
4271    /// # Returns
4272    ///
4273    /// Remove a scheduled prompt by id. The result entry is omitted if the id was unknown.
4274    ///
4275    /// <div class="warning">
4276    ///
4277    /// **Experimental.** This API is part of an experimental wire-protocol surface
4278    /// and may change or be removed in future SDK or CLI releases. Pin both the
4279    /// SDK and CLI versions if your code depends on it.
4280    ///
4281    /// </div>
4282    pub async fn stop(&self, params: ScheduleStopRequest) -> Result<ScheduleStopResult, Error> {
4283        let mut wire_params = serde_json::to_value(params)?;
4284        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4285        let _value = self
4286            .session
4287            .client()
4288            .call(rpc_methods::SESSION_SCHEDULE_STOP, Some(wire_params))
4289            .await?;
4290        Ok(serde_json::from_value(_value)?)
4291    }
4292}
4293
4294/// `session.shell.*` RPCs.
4295#[derive(Clone, Copy)]
4296pub struct SessionRpcShell<'a> {
4297    pub(crate) session: &'a Session,
4298}
4299
4300impl<'a> SessionRpcShell<'a> {
4301    /// Starts a shell command and streams output through session notifications.
4302    ///
4303    /// Wire method: `session.shell.exec`.
4304    ///
4305    /// # Parameters
4306    ///
4307    /// * `params` - Shell command to run, with optional working directory and timeout in milliseconds.
4308    ///
4309    /// # Returns
4310    ///
4311    /// Identifier of the spawned process, used to correlate streamed output and exit notifications.
4312    ///
4313    /// <div class="warning">
4314    ///
4315    /// **Experimental.** This API is part of an experimental wire-protocol surface
4316    /// and may change or be removed in future SDK or CLI releases. Pin both the
4317    /// SDK and CLI versions if your code depends on it.
4318    ///
4319    /// </div>
4320    pub async fn exec(&self, params: ShellExecRequest) -> Result<ShellExecResult, Error> {
4321        let mut wire_params = serde_json::to_value(params)?;
4322        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4323        let _value = self
4324            .session
4325            .client()
4326            .call(rpc_methods::SESSION_SHELL_EXEC, Some(wire_params))
4327            .await?;
4328        Ok(serde_json::from_value(_value)?)
4329    }
4330
4331    /// Sends a signal to a shell process previously started via "shell.exec".
4332    ///
4333    /// Wire method: `session.shell.kill`.
4334    ///
4335    /// # Parameters
4336    ///
4337    /// * `params` - Identifier of a process previously returned by "shell.exec" and the signal to send.
4338    ///
4339    /// # Returns
4340    ///
4341    /// Indicates whether the signal was delivered; false if the process was unknown or already exited.
4342    ///
4343    /// <div class="warning">
4344    ///
4345    /// **Experimental.** This API is part of an experimental wire-protocol surface
4346    /// and may change or be removed in future SDK or CLI releases. Pin both the
4347    /// SDK and CLI versions if your code depends on it.
4348    ///
4349    /// </div>
4350    pub async fn kill(&self, params: ShellKillRequest) -> Result<ShellKillResult, Error> {
4351        let mut wire_params = serde_json::to_value(params)?;
4352        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4353        let _value = self
4354            .session
4355            .client()
4356            .call(rpc_methods::SESSION_SHELL_KILL, Some(wire_params))
4357            .await?;
4358        Ok(serde_json::from_value(_value)?)
4359    }
4360}
4361
4362/// `session.skills.*` RPCs.
4363#[derive(Clone, Copy)]
4364pub struct SessionRpcSkills<'a> {
4365    pub(crate) session: &'a Session,
4366}
4367
4368impl<'a> SessionRpcSkills<'a> {
4369    /// Lists skills available to the session.
4370    ///
4371    /// Wire method: `session.skills.list`.
4372    ///
4373    /// # Returns
4374    ///
4375    /// Skills available to the session, with their enabled state.
4376    ///
4377    /// <div class="warning">
4378    ///
4379    /// **Experimental.** This API is part of an experimental wire-protocol surface
4380    /// and may change or be removed in future SDK or CLI releases. Pin both the
4381    /// SDK and CLI versions if your code depends on it.
4382    ///
4383    /// </div>
4384    pub async fn list(&self) -> Result<SkillList, Error> {
4385        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4386        let _value = self
4387            .session
4388            .client()
4389            .call(rpc_methods::SESSION_SKILLS_LIST, Some(wire_params))
4390            .await?;
4391        Ok(serde_json::from_value(_value)?)
4392    }
4393
4394    /// Returns the skills that have been invoked during this session.
4395    ///
4396    /// Wire method: `session.skills.getInvoked`.
4397    ///
4398    /// # Returns
4399    ///
4400    /// Skills invoked during this session, ordered by invocation time (most recent last).
4401    ///
4402    /// <div class="warning">
4403    ///
4404    /// **Experimental.** This API is part of an experimental wire-protocol surface
4405    /// and may change or be removed in future SDK or CLI releases. Pin both the
4406    /// SDK and CLI versions if your code depends on it.
4407    ///
4408    /// </div>
4409    pub async fn get_invoked(&self) -> Result<SkillsGetInvokedResult, Error> {
4410        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4411        let _value = self
4412            .session
4413            .client()
4414            .call(rpc_methods::SESSION_SKILLS_GETINVOKED, Some(wire_params))
4415            .await?;
4416        Ok(serde_json::from_value(_value)?)
4417    }
4418
4419    /// Enables a skill for the session.
4420    ///
4421    /// Wire method: `session.skills.enable`.
4422    ///
4423    /// # Parameters
4424    ///
4425    /// * `params` - Name of the skill to enable for the session.
4426    ///
4427    /// <div class="warning">
4428    ///
4429    /// **Experimental.** This API is part of an experimental wire-protocol surface
4430    /// and may change or be removed in future SDK or CLI releases. Pin both the
4431    /// SDK and CLI versions if your code depends on it.
4432    ///
4433    /// </div>
4434    pub async fn enable(&self, params: SkillsEnableRequest) -> Result<(), Error> {
4435        let mut wire_params = serde_json::to_value(params)?;
4436        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4437        let _value = self
4438            .session
4439            .client()
4440            .call(rpc_methods::SESSION_SKILLS_ENABLE, Some(wire_params))
4441            .await?;
4442        Ok(())
4443    }
4444
4445    /// Disables a skill for the session.
4446    ///
4447    /// Wire method: `session.skills.disable`.
4448    ///
4449    /// # Parameters
4450    ///
4451    /// * `params` - Name of the skill to disable for the session.
4452    ///
4453    /// <div class="warning">
4454    ///
4455    /// **Experimental.** This API is part of an experimental wire-protocol surface
4456    /// and may change or be removed in future SDK or CLI releases. Pin both the
4457    /// SDK and CLI versions if your code depends on it.
4458    ///
4459    /// </div>
4460    pub async fn disable(&self, params: SkillsDisableRequest) -> Result<(), Error> {
4461        let mut wire_params = serde_json::to_value(params)?;
4462        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4463        let _value = self
4464            .session
4465            .client()
4466            .call(rpc_methods::SESSION_SKILLS_DISABLE, Some(wire_params))
4467            .await?;
4468        Ok(())
4469    }
4470
4471    /// Reloads skill definitions for the session.
4472    ///
4473    /// Wire method: `session.skills.reload`.
4474    ///
4475    /// # Returns
4476    ///
4477    /// Diagnostics from reloading skill definitions, with warnings and errors as separate lists.
4478    ///
4479    /// <div class="warning">
4480    ///
4481    /// **Experimental.** This API is part of an experimental wire-protocol surface
4482    /// and may change or be removed in future SDK or CLI releases. Pin both the
4483    /// SDK and CLI versions if your code depends on it.
4484    ///
4485    /// </div>
4486    pub async fn reload(&self) -> Result<SkillsLoadDiagnostics, Error> {
4487        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4488        let _value = self
4489            .session
4490            .client()
4491            .call(rpc_methods::SESSION_SKILLS_RELOAD, Some(wire_params))
4492            .await?;
4493        Ok(serde_json::from_value(_value)?)
4494    }
4495
4496    /// Ensures the session's skill definitions have been loaded from disk.
4497    ///
4498    /// Wire method: `session.skills.ensureLoaded`.
4499    ///
4500    /// <div class="warning">
4501    ///
4502    /// **Experimental.** This API is part of an experimental wire-protocol surface
4503    /// and may change or be removed in future SDK or CLI releases. Pin both the
4504    /// SDK and CLI versions if your code depends on it.
4505    ///
4506    /// </div>
4507    pub async fn ensure_loaded(&self) -> Result<(), Error> {
4508        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4509        let _value = self
4510            .session
4511            .client()
4512            .call(rpc_methods::SESSION_SKILLS_ENSURELOADED, Some(wire_params))
4513            .await?;
4514        Ok(())
4515    }
4516}
4517
4518/// `session.tasks.*` RPCs.
4519#[derive(Clone, Copy)]
4520pub struct SessionRpcTasks<'a> {
4521    pub(crate) session: &'a Session,
4522}
4523
4524impl<'a> SessionRpcTasks<'a> {
4525    /// Starts a background agent task in the session.
4526    ///
4527    /// Wire method: `session.tasks.startAgent`.
4528    ///
4529    /// # Parameters
4530    ///
4531    /// * `params` - Agent type, prompt, name, and optional description and model override for the new task.
4532    ///
4533    /// # Returns
4534    ///
4535    /// Identifier assigned to the newly started background agent task.
4536    ///
4537    /// <div class="warning">
4538    ///
4539    /// **Experimental.** This API is part of an experimental wire-protocol surface
4540    /// and may change or be removed in future SDK or CLI releases. Pin both the
4541    /// SDK and CLI versions if your code depends on it.
4542    ///
4543    /// </div>
4544    pub async fn start_agent(
4545        &self,
4546        params: TasksStartAgentRequest,
4547    ) -> Result<TasksStartAgentResult, Error> {
4548        let mut wire_params = serde_json::to_value(params)?;
4549        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4550        let _value = self
4551            .session
4552            .client()
4553            .call(rpc_methods::SESSION_TASKS_STARTAGENT, Some(wire_params))
4554            .await?;
4555        Ok(serde_json::from_value(_value)?)
4556    }
4557
4558    /// Lists background tasks tracked by the session.
4559    ///
4560    /// Wire method: `session.tasks.list`.
4561    ///
4562    /// # Returns
4563    ///
4564    /// Background tasks currently tracked by the session.
4565    ///
4566    /// <div class="warning">
4567    ///
4568    /// **Experimental.** This API is part of an experimental wire-protocol surface
4569    /// and may change or be removed in future SDK or CLI releases. Pin both the
4570    /// SDK and CLI versions if your code depends on it.
4571    ///
4572    /// </div>
4573    pub async fn list(&self) -> Result<TaskList, Error> {
4574        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4575        let _value = self
4576            .session
4577            .client()
4578            .call(rpc_methods::SESSION_TASKS_LIST, Some(wire_params))
4579            .await?;
4580        Ok(serde_json::from_value(_value)?)
4581    }
4582
4583    /// Refreshes metadata for any detached background shells the runtime knows about.
4584    ///
4585    /// Wire method: `session.tasks.refresh`.
4586    ///
4587    /// # Returns
4588    ///
4589    /// 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.
4590    ///
4591    /// <div class="warning">
4592    ///
4593    /// **Experimental.** This API is part of an experimental wire-protocol surface
4594    /// and may change or be removed in future SDK or CLI releases. Pin both the
4595    /// SDK and CLI versions if your code depends on it.
4596    ///
4597    /// </div>
4598    pub async fn refresh(&self) -> Result<TasksRefreshResult, Error> {
4599        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4600        let _value = self
4601            .session
4602            .client()
4603            .call(rpc_methods::SESSION_TASKS_REFRESH, Some(wire_params))
4604            .await?;
4605        Ok(serde_json::from_value(_value)?)
4606    }
4607
4608    /// Waits for all in-flight background tasks and any follow-up turns to settle.
4609    ///
4610    /// Wire method: `session.tasks.waitForPending`.
4611    ///
4612    /// # Returns
4613    ///
4614    /// 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).
4615    ///
4616    /// <div class="warning">
4617    ///
4618    /// **Experimental.** This API is part of an experimental wire-protocol surface
4619    /// and may change or be removed in future SDK or CLI releases. Pin both the
4620    /// SDK and CLI versions if your code depends on it.
4621    ///
4622    /// </div>
4623    pub async fn wait_for_pending(&self) -> Result<TasksWaitForPendingResult, Error> {
4624        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4625        let _value = self
4626            .session
4627            .client()
4628            .call(rpc_methods::SESSION_TASKS_WAITFORPENDING, Some(wire_params))
4629            .await?;
4630        Ok(serde_json::from_value(_value)?)
4631    }
4632
4633    /// Returns progress information for a background task by ID.
4634    ///
4635    /// Wire method: `session.tasks.getProgress`.
4636    ///
4637    /// # Parameters
4638    ///
4639    /// * `params` - Identifier of the background task to fetch progress for.
4640    ///
4641    /// # Returns
4642    ///
4643    /// Progress information for the task, or null when no task with that ID is tracked.
4644    ///
4645    /// <div class="warning">
4646    ///
4647    /// **Experimental.** This API is part of an experimental wire-protocol surface
4648    /// and may change or be removed in future SDK or CLI releases. Pin both the
4649    /// SDK and CLI versions if your code depends on it.
4650    ///
4651    /// </div>
4652    pub async fn get_progress(
4653        &self,
4654        params: TasksGetProgressRequest,
4655    ) -> Result<TasksGetProgressResult, Error> {
4656        let mut wire_params = serde_json::to_value(params)?;
4657        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4658        let _value = self
4659            .session
4660            .client()
4661            .call(rpc_methods::SESSION_TASKS_GETPROGRESS, Some(wire_params))
4662            .await?;
4663        Ok(serde_json::from_value(_value)?)
4664    }
4665
4666    /// Returns the first sync-waiting task that can currently be promoted to background mode.
4667    ///
4668    /// Wire method: `session.tasks.getCurrentPromotable`.
4669    ///
4670    /// # Returns
4671    ///
4672    /// The first sync-waiting task that can currently be promoted to background mode.
4673    ///
4674    /// <div class="warning">
4675    ///
4676    /// **Experimental.** This API is part of an experimental wire-protocol surface
4677    /// and may change or be removed in future SDK or CLI releases. Pin both the
4678    /// SDK and CLI versions if your code depends on it.
4679    ///
4680    /// </div>
4681    pub async fn get_current_promotable(&self) -> Result<TasksGetCurrentPromotableResult, Error> {
4682        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4683        let _value = self
4684            .session
4685            .client()
4686            .call(
4687                rpc_methods::SESSION_TASKS_GETCURRENTPROMOTABLE,
4688                Some(wire_params),
4689            )
4690            .await?;
4691        Ok(serde_json::from_value(_value)?)
4692    }
4693
4694    /// Promotes an eligible synchronously-waited task so it continues running in the background.
4695    ///
4696    /// Wire method: `session.tasks.promoteToBackground`.
4697    ///
4698    /// # Parameters
4699    ///
4700    /// * `params` - Identifier of the task to promote to background mode.
4701    ///
4702    /// # Returns
4703    ///
4704    /// Indicates whether the task was successfully promoted to background mode.
4705    ///
4706    /// <div class="warning">
4707    ///
4708    /// **Experimental.** This API is part of an experimental wire-protocol surface
4709    /// and may change or be removed in future SDK or CLI releases. Pin both the
4710    /// SDK and CLI versions if your code depends on it.
4711    ///
4712    /// </div>
4713    pub async fn promote_to_background(
4714        &self,
4715        params: TasksPromoteToBackgroundRequest,
4716    ) -> Result<TasksPromoteToBackgroundResult, Error> {
4717        let mut wire_params = serde_json::to_value(params)?;
4718        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4719        let _value = self
4720            .session
4721            .client()
4722            .call(
4723                rpc_methods::SESSION_TASKS_PROMOTETOBACKGROUND,
4724                Some(wire_params),
4725            )
4726            .await?;
4727        Ok(serde_json::from_value(_value)?)
4728    }
4729
4730    /// Atomically promotes the first promotable sync-waiting task to background mode and returns it.
4731    ///
4732    /// Wire method: `session.tasks.promoteCurrentToBackground`.
4733    ///
4734    /// # Returns
4735    ///
4736    /// The promoted task as it now exists in background mode, omitted if no promotable task was waiting.
4737    ///
4738    /// <div class="warning">
4739    ///
4740    /// **Experimental.** This API is part of an experimental wire-protocol surface
4741    /// and may change or be removed in future SDK or CLI releases. Pin both the
4742    /// SDK and CLI versions if your code depends on it.
4743    ///
4744    /// </div>
4745    pub async fn promote_current_to_background(
4746        &self,
4747    ) -> Result<TasksPromoteCurrentToBackgroundResult, Error> {
4748        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4749        let _value = self
4750            .session
4751            .client()
4752            .call(
4753                rpc_methods::SESSION_TASKS_PROMOTECURRENTTOBACKGROUND,
4754                Some(wire_params),
4755            )
4756            .await?;
4757        Ok(serde_json::from_value(_value)?)
4758    }
4759
4760    /// Cancels a background task.
4761    ///
4762    /// Wire method: `session.tasks.cancel`.
4763    ///
4764    /// # Parameters
4765    ///
4766    /// * `params` - Identifier of the background task to cancel.
4767    ///
4768    /// # Returns
4769    ///
4770    /// Indicates whether the background task was successfully cancelled.
4771    ///
4772    /// <div class="warning">
4773    ///
4774    /// **Experimental.** This API is part of an experimental wire-protocol surface
4775    /// and may change or be removed in future SDK or CLI releases. Pin both the
4776    /// SDK and CLI versions if your code depends on it.
4777    ///
4778    /// </div>
4779    pub async fn cancel(&self, params: TasksCancelRequest) -> Result<TasksCancelResult, Error> {
4780        let mut wire_params = serde_json::to_value(params)?;
4781        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4782        let _value = self
4783            .session
4784            .client()
4785            .call(rpc_methods::SESSION_TASKS_CANCEL, Some(wire_params))
4786            .await?;
4787        Ok(serde_json::from_value(_value)?)
4788    }
4789
4790    /// Removes a completed or cancelled background task from tracking.
4791    ///
4792    /// Wire method: `session.tasks.remove`.
4793    ///
4794    /// # Parameters
4795    ///
4796    /// * `params` - Identifier of the completed or cancelled task to remove from tracking.
4797    ///
4798    /// # Returns
4799    ///
4800    /// Indicates whether the task was removed. False when the task does not exist or is still running/idle.
4801    ///
4802    /// <div class="warning">
4803    ///
4804    /// **Experimental.** This API is part of an experimental wire-protocol surface
4805    /// and may change or be removed in future SDK or CLI releases. Pin both the
4806    /// SDK and CLI versions if your code depends on it.
4807    ///
4808    /// </div>
4809    pub async fn remove(&self, params: TasksRemoveRequest) -> Result<TasksRemoveResult, Error> {
4810        let mut wire_params = serde_json::to_value(params)?;
4811        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4812        let _value = self
4813            .session
4814            .client()
4815            .call(rpc_methods::SESSION_TASKS_REMOVE, Some(wire_params))
4816            .await?;
4817        Ok(serde_json::from_value(_value)?)
4818    }
4819
4820    /// Sends a message to a background agent task.
4821    ///
4822    /// Wire method: `session.tasks.sendMessage`.
4823    ///
4824    /// # Parameters
4825    ///
4826    /// * `params` - Identifier of the target agent task, message content, and optional sender agent ID.
4827    ///
4828    /// # Returns
4829    ///
4830    /// Indicates whether the message was delivered, with an error message when delivery failed.
4831    ///
4832    /// <div class="warning">
4833    ///
4834    /// **Experimental.** This API is part of an experimental wire-protocol surface
4835    /// and may change or be removed in future SDK or CLI releases. Pin both the
4836    /// SDK and CLI versions if your code depends on it.
4837    ///
4838    /// </div>
4839    pub async fn send_message(
4840        &self,
4841        params: TasksSendMessageRequest,
4842    ) -> Result<TasksSendMessageResult, Error> {
4843        let mut wire_params = serde_json::to_value(params)?;
4844        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4845        let _value = self
4846            .session
4847            .client()
4848            .call(rpc_methods::SESSION_TASKS_SENDMESSAGE, Some(wire_params))
4849            .await?;
4850        Ok(serde_json::from_value(_value)?)
4851    }
4852}
4853
4854/// `session.telemetry.*` RPCs.
4855#[derive(Clone, Copy)]
4856pub struct SessionRpcTelemetry<'a> {
4857    pub(crate) session: &'a Session,
4858}
4859
4860impl<'a> SessionRpcTelemetry<'a> {
4861    /// Sets feature override key/value pairs to attach to subsequent telemetry events for the session.
4862    ///
4863    /// Wire method: `session.telemetry.setFeatureOverrides`.
4864    ///
4865    /// # Parameters
4866    ///
4867    /// * `params` - Feature override key/value pairs to attach to subsequent telemetry events from this session.
4868    ///
4869    /// <div class="warning">
4870    ///
4871    /// **Experimental.** This API is part of an experimental wire-protocol surface
4872    /// and may change or be removed in future SDK or CLI releases. Pin both the
4873    /// SDK and CLI versions if your code depends on it.
4874    ///
4875    /// </div>
4876    pub async fn set_feature_overrides(
4877        &self,
4878        params: TelemetrySetFeatureOverridesRequest,
4879    ) -> Result<(), Error> {
4880        let mut wire_params = serde_json::to_value(params)?;
4881        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4882        let _value = self
4883            .session
4884            .client()
4885            .call(
4886                rpc_methods::SESSION_TELEMETRY_SETFEATUREOVERRIDES,
4887                Some(wire_params),
4888            )
4889            .await?;
4890        Ok(())
4891    }
4892}
4893
4894/// `session.tools.*` RPCs.
4895#[derive(Clone, Copy)]
4896pub struct SessionRpcTools<'a> {
4897    pub(crate) session: &'a Session,
4898}
4899
4900impl<'a> SessionRpcTools<'a> {
4901    /// Provides the result for a pending external tool call.
4902    ///
4903    /// Wire method: `session.tools.handlePendingToolCall`.
4904    ///
4905    /// # Parameters
4906    ///
4907    /// * `params` - Pending external tool call request ID, with the tool result or an error describing why it failed.
4908    ///
4909    /// # Returns
4910    ///
4911    /// Indicates whether the external tool call result was handled successfully.
4912    ///
4913    /// <div class="warning">
4914    ///
4915    /// **Experimental.** This API is part of an experimental wire-protocol surface
4916    /// and may change or be removed in future SDK or CLI releases. Pin both the
4917    /// SDK and CLI versions if your code depends on it.
4918    ///
4919    /// </div>
4920    pub async fn handle_pending_tool_call(
4921        &self,
4922        params: HandlePendingToolCallRequest,
4923    ) -> Result<HandlePendingToolCallResult, Error> {
4924        let mut wire_params = serde_json::to_value(params)?;
4925        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4926        let _value = self
4927            .session
4928            .client()
4929            .call(
4930                rpc_methods::SESSION_TOOLS_HANDLEPENDINGTOOLCALL,
4931                Some(wire_params),
4932            )
4933            .await?;
4934        Ok(serde_json::from_value(_value)?)
4935    }
4936
4937    /// Resolves, builds, and validates the runtime tool list for the session.
4938    ///
4939    /// Wire method: `session.tools.initializeAndValidate`.
4940    ///
4941    /// # Returns
4942    ///
4943    /// 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.
4944    ///
4945    /// <div class="warning">
4946    ///
4947    /// **Experimental.** This API is part of an experimental wire-protocol surface
4948    /// and may change or be removed in future SDK or CLI releases. Pin both the
4949    /// SDK and CLI versions if your code depends on it.
4950    ///
4951    /// </div>
4952    pub async fn initialize_and_validate(&self) -> Result<ToolsInitializeAndValidateResult, Error> {
4953        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
4954        let _value = self
4955            .session
4956            .client()
4957            .call(
4958                rpc_methods::SESSION_TOOLS_INITIALIZEANDVALIDATE,
4959                Some(wire_params),
4960            )
4961            .await?;
4962        Ok(serde_json::from_value(_value)?)
4963    }
4964}
4965
4966/// `session.ui.*` RPCs.
4967#[derive(Clone, Copy)]
4968pub struct SessionRpcUi<'a> {
4969    pub(crate) session: &'a Session,
4970}
4971
4972impl<'a> SessionRpcUi<'a> {
4973    /// Requests structured input from a UI-capable client.
4974    ///
4975    /// Wire method: `session.ui.elicitation`.
4976    ///
4977    /// # Parameters
4978    ///
4979    /// * `params` - Prompt message and JSON schema describing the form fields to elicit from the user.
4980    ///
4981    /// # Returns
4982    ///
4983    /// The elicitation response (accept with form values, decline, or cancel)
4984    ///
4985    /// <div class="warning">
4986    ///
4987    /// **Experimental.** This API is part of an experimental wire-protocol surface
4988    /// and may change or be removed in future SDK or CLI releases. Pin both the
4989    /// SDK and CLI versions if your code depends on it.
4990    ///
4991    /// </div>
4992    pub async fn elicitation(
4993        &self,
4994        params: UIElicitationRequest,
4995    ) -> Result<UIElicitationResponse, Error> {
4996        let mut wire_params = serde_json::to_value(params)?;
4997        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
4998        let _value = self
4999            .session
5000            .client()
5001            .call(rpc_methods::SESSION_UI_ELICITATION, Some(wire_params))
5002            .await?;
5003        Ok(serde_json::from_value(_value)?)
5004    }
5005
5006    /// Provides the user response for a pending elicitation request.
5007    ///
5008    /// Wire method: `session.ui.handlePendingElicitation`.
5009    ///
5010    /// # Parameters
5011    ///
5012    /// * `params` - Pending elicitation request ID and the user's response (accept/decline/cancel + form values).
5013    ///
5014    /// # Returns
5015    ///
5016    /// Indicates whether the elicitation response was accepted; false if it was already resolved by another client.
5017    ///
5018    /// <div class="warning">
5019    ///
5020    /// **Experimental.** This API is part of an experimental wire-protocol surface
5021    /// and may change or be removed in future SDK or CLI releases. Pin both the
5022    /// SDK and CLI versions if your code depends on it.
5023    ///
5024    /// </div>
5025    pub async fn handle_pending_elicitation(
5026        &self,
5027        params: UIHandlePendingElicitationRequest,
5028    ) -> Result<UIElicitationResult, Error> {
5029        let mut wire_params = serde_json::to_value(params)?;
5030        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5031        let _value = self
5032            .session
5033            .client()
5034            .call(
5035                rpc_methods::SESSION_UI_HANDLEPENDINGELICITATION,
5036                Some(wire_params),
5037            )
5038            .await?;
5039        Ok(serde_json::from_value(_value)?)
5040    }
5041
5042    /// Resolves a pending `user_input.requested` event with the user's response.
5043    ///
5044    /// Wire method: `session.ui.handlePendingUserInput`.
5045    ///
5046    /// # Parameters
5047    ///
5048    /// * `params` - Request ID of a pending `user_input.requested` event and the user's response.
5049    ///
5050    /// # Returns
5051    ///
5052    /// Indicates whether the pending UI request was resolved by this call.
5053    ///
5054    /// <div class="warning">
5055    ///
5056    /// **Experimental.** This API is part of an experimental wire-protocol surface
5057    /// and may change or be removed in future SDK or CLI releases. Pin both the
5058    /// SDK and CLI versions if your code depends on it.
5059    ///
5060    /// </div>
5061    pub async fn handle_pending_user_input(
5062        &self,
5063        params: UIHandlePendingUserInputRequest,
5064    ) -> Result<UIHandlePendingResult, Error> {
5065        let mut wire_params = serde_json::to_value(params)?;
5066        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5067        let _value = self
5068            .session
5069            .client()
5070            .call(
5071                rpc_methods::SESSION_UI_HANDLEPENDINGUSERINPUT,
5072                Some(wire_params),
5073            )
5074            .await?;
5075        Ok(serde_json::from_value(_value)?)
5076    }
5077
5078    /// Resolves a pending `sampling.requested` event with a sampling result, or rejects it.
5079    ///
5080    /// Wire method: `session.ui.handlePendingSampling`.
5081    ///
5082    /// # Parameters
5083    ///
5084    /// * `params` - Request ID of a pending `sampling.requested` event and an optional sampling result payload (omit to reject).
5085    ///
5086    /// # Returns
5087    ///
5088    /// Indicates whether the pending UI request was resolved by this call.
5089    ///
5090    /// <div class="warning">
5091    ///
5092    /// **Experimental.** This API is part of an experimental wire-protocol surface
5093    /// and may change or be removed in future SDK or CLI releases. Pin both the
5094    /// SDK and CLI versions if your code depends on it.
5095    ///
5096    /// </div>
5097    pub async fn handle_pending_sampling(
5098        &self,
5099        params: UIHandlePendingSamplingRequest,
5100    ) -> Result<UIHandlePendingResult, Error> {
5101        let mut wire_params = serde_json::to_value(params)?;
5102        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5103        let _value = self
5104            .session
5105            .client()
5106            .call(
5107                rpc_methods::SESSION_UI_HANDLEPENDINGSAMPLING,
5108                Some(wire_params),
5109            )
5110            .await?;
5111        Ok(serde_json::from_value(_value)?)
5112    }
5113
5114    /// Resolves a pending `auto_mode_switch.requested` event with the user's accept/decline decision.
5115    ///
5116    /// Wire method: `session.ui.handlePendingAutoModeSwitch`.
5117    ///
5118    /// # Parameters
5119    ///
5120    /// * `params` - Request ID of a pending `auto_mode_switch.requested` event and the user's response.
5121    ///
5122    /// # Returns
5123    ///
5124    /// Indicates whether the pending UI request was resolved by this call.
5125    ///
5126    /// <div class="warning">
5127    ///
5128    /// **Experimental.** This API is part of an experimental wire-protocol surface
5129    /// and may change or be removed in future SDK or CLI releases. Pin both the
5130    /// SDK and CLI versions if your code depends on it.
5131    ///
5132    /// </div>
5133    pub async fn handle_pending_auto_mode_switch(
5134        &self,
5135        params: UIHandlePendingAutoModeSwitchRequest,
5136    ) -> Result<UIHandlePendingResult, Error> {
5137        let mut wire_params = serde_json::to_value(params)?;
5138        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5139        let _value = self
5140            .session
5141            .client()
5142            .call(
5143                rpc_methods::SESSION_UI_HANDLEPENDINGAUTOMODESWITCH,
5144                Some(wire_params),
5145            )
5146            .await?;
5147        Ok(serde_json::from_value(_value)?)
5148    }
5149
5150    /// Resolves a pending `exit_plan_mode.requested` event with the user's response.
5151    ///
5152    /// Wire method: `session.ui.handlePendingExitPlanMode`.
5153    ///
5154    /// # Parameters
5155    ///
5156    /// * `params` - Request ID of a pending `exit_plan_mode.requested` event and the user's response.
5157    ///
5158    /// # Returns
5159    ///
5160    /// Indicates whether the pending UI request was resolved by this call.
5161    ///
5162    /// <div class="warning">
5163    ///
5164    /// **Experimental.** This API is part of an experimental wire-protocol surface
5165    /// and may change or be removed in future SDK or CLI releases. Pin both the
5166    /// SDK and CLI versions if your code depends on it.
5167    ///
5168    /// </div>
5169    pub async fn handle_pending_exit_plan_mode(
5170        &self,
5171        params: UIHandlePendingExitPlanModeRequest,
5172    ) -> Result<UIHandlePendingResult, Error> {
5173        let mut wire_params = serde_json::to_value(params)?;
5174        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5175        let _value = self
5176            .session
5177            .client()
5178            .call(
5179                rpc_methods::SESSION_UI_HANDLEPENDINGEXITPLANMODE,
5180                Some(wire_params),
5181            )
5182            .await?;
5183        Ok(serde_json::from_value(_value)?)
5184    }
5185
5186    /// Registers an in-process handler for auto-mode-switch requests so the server bridge skips dispatch.
5187    ///
5188    /// Wire method: `session.ui.registerDirectAutoModeSwitchHandler`.
5189    ///
5190    /// # Returns
5191    ///
5192    /// 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).
5193    ///
5194    /// <div class="warning">
5195    ///
5196    /// **Experimental.** This API is part of an experimental wire-protocol surface
5197    /// and may change or be removed in future SDK or CLI releases. Pin both the
5198    /// SDK and CLI versions if your code depends on it.
5199    ///
5200    /// </div>
5201    pub async fn register_direct_auto_mode_switch_handler(
5202        &self,
5203    ) -> Result<UIRegisterDirectAutoModeSwitchHandlerResult, Error> {
5204        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
5205        let _value = self
5206            .session
5207            .client()
5208            .call(
5209                rpc_methods::SESSION_UI_REGISTERDIRECTAUTOMODESWITCHHANDLER,
5210                Some(wire_params),
5211            )
5212            .await?;
5213        Ok(serde_json::from_value(_value)?)
5214    }
5215
5216    /// Unregisters a previously-registered in-process auto-mode-switch handler by its opaque handle.
5217    ///
5218    /// Wire method: `session.ui.unregisterDirectAutoModeSwitchHandler`.
5219    ///
5220    /// # Parameters
5221    ///
5222    /// * `params` - Opaque handle previously returned by `registerDirectAutoModeSwitchHandler` to release.
5223    ///
5224    /// # Returns
5225    ///
5226    /// Indicates whether the handle was active and the registration count was decremented.
5227    ///
5228    /// <div class="warning">
5229    ///
5230    /// **Experimental.** This API is part of an experimental wire-protocol surface
5231    /// and may change or be removed in future SDK or CLI releases. Pin both the
5232    /// SDK and CLI versions if your code depends on it.
5233    ///
5234    /// </div>
5235    pub async fn unregister_direct_auto_mode_switch_handler(
5236        &self,
5237        params: UIUnregisterDirectAutoModeSwitchHandlerRequest,
5238    ) -> Result<UIUnregisterDirectAutoModeSwitchHandlerResult, Error> {
5239        let mut wire_params = serde_json::to_value(params)?;
5240        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5241        let _value = self
5242            .session
5243            .client()
5244            .call(
5245                rpc_methods::SESSION_UI_UNREGISTERDIRECTAUTOMODESWITCHHANDLER,
5246                Some(wire_params),
5247            )
5248            .await?;
5249        Ok(serde_json::from_value(_value)?)
5250    }
5251}
5252
5253/// `session.usage.*` RPCs.
5254#[derive(Clone, Copy)]
5255pub struct SessionRpcUsage<'a> {
5256    pub(crate) session: &'a Session,
5257}
5258
5259impl<'a> SessionRpcUsage<'a> {
5260    /// Gets accumulated usage metrics for the session.
5261    ///
5262    /// Wire method: `session.usage.getMetrics`.
5263    ///
5264    /// # Returns
5265    ///
5266    /// Accumulated session usage metrics, including premium request cost, token counts, model breakdown, and code-change totals.
5267    ///
5268    /// <div class="warning">
5269    ///
5270    /// **Experimental.** This API is part of an experimental wire-protocol surface
5271    /// and may change or be removed in future SDK or CLI releases. Pin both the
5272    /// SDK and CLI versions if your code depends on it.
5273    ///
5274    /// </div>
5275    pub async fn get_metrics(&self) -> Result<UsageGetMetricsResult, Error> {
5276        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
5277        let _value = self
5278            .session
5279            .client()
5280            .call(rpc_methods::SESSION_USAGE_GETMETRICS, Some(wire_params))
5281            .await?;
5282        Ok(serde_json::from_value(_value)?)
5283    }
5284}
5285
5286/// `session.workspaces.*` RPCs.
5287#[derive(Clone, Copy)]
5288pub struct SessionRpcWorkspaces<'a> {
5289    pub(crate) session: &'a Session,
5290}
5291
5292impl<'a> SessionRpcWorkspaces<'a> {
5293    /// Gets current workspace metadata for the session.
5294    ///
5295    /// Wire method: `session.workspaces.getWorkspace`.
5296    ///
5297    /// # Returns
5298    ///
5299    /// Current workspace metadata for the session, including its absolute filesystem path when available.
5300    ///
5301    /// <div class="warning">
5302    ///
5303    /// **Experimental.** This API is part of an experimental wire-protocol surface
5304    /// and may change or be removed in future SDK or CLI releases. Pin both the
5305    /// SDK and CLI versions if your code depends on it.
5306    ///
5307    /// </div>
5308    pub async fn get_workspace(&self) -> Result<WorkspacesGetWorkspaceResult, Error> {
5309        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
5310        let _value = self
5311            .session
5312            .client()
5313            .call(
5314                rpc_methods::SESSION_WORKSPACES_GETWORKSPACE,
5315                Some(wire_params),
5316            )
5317            .await?;
5318        Ok(serde_json::from_value(_value)?)
5319    }
5320
5321    /// Lists files stored in the session workspace files directory.
5322    ///
5323    /// Wire method: `session.workspaces.listFiles`.
5324    ///
5325    /// # Returns
5326    ///
5327    /// Relative paths of files stored in the session workspace files directory.
5328    ///
5329    /// <div class="warning">
5330    ///
5331    /// **Experimental.** This API is part of an experimental wire-protocol surface
5332    /// and may change or be removed in future SDK or CLI releases. Pin both the
5333    /// SDK and CLI versions if your code depends on it.
5334    ///
5335    /// </div>
5336    pub async fn list_files(&self) -> Result<WorkspacesListFilesResult, Error> {
5337        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
5338        let _value = self
5339            .session
5340            .client()
5341            .call(rpc_methods::SESSION_WORKSPACES_LISTFILES, Some(wire_params))
5342            .await?;
5343        Ok(serde_json::from_value(_value)?)
5344    }
5345
5346    /// Reads a file from the session workspace files directory.
5347    ///
5348    /// Wire method: `session.workspaces.readFile`.
5349    ///
5350    /// # Parameters
5351    ///
5352    /// * `params` - Relative path of the workspace file to read.
5353    ///
5354    /// # Returns
5355    ///
5356    /// Contents of the requested workspace file as a UTF-8 string.
5357    ///
5358    /// <div class="warning">
5359    ///
5360    /// **Experimental.** This API is part of an experimental wire-protocol surface
5361    /// and may change or be removed in future SDK or CLI releases. Pin both the
5362    /// SDK and CLI versions if your code depends on it.
5363    ///
5364    /// </div>
5365    pub async fn read_file(
5366        &self,
5367        params: WorkspacesReadFileRequest,
5368    ) -> Result<WorkspacesReadFileResult, Error> {
5369        let mut wire_params = serde_json::to_value(params)?;
5370        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5371        let _value = self
5372            .session
5373            .client()
5374            .call(rpc_methods::SESSION_WORKSPACES_READFILE, Some(wire_params))
5375            .await?;
5376        Ok(serde_json::from_value(_value)?)
5377    }
5378
5379    /// Creates or overwrites a file in the session workspace files directory.
5380    ///
5381    /// Wire method: `session.workspaces.createFile`.
5382    ///
5383    /// # Parameters
5384    ///
5385    /// * `params` - Relative path and UTF-8 content for the workspace file to create or overwrite.
5386    ///
5387    /// <div class="warning">
5388    ///
5389    /// **Experimental.** This API is part of an experimental wire-protocol surface
5390    /// and may change or be removed in future SDK or CLI releases. Pin both the
5391    /// SDK and CLI versions if your code depends on it.
5392    ///
5393    /// </div>
5394    pub async fn create_file(&self, params: WorkspacesCreateFileRequest) -> Result<(), Error> {
5395        let mut wire_params = serde_json::to_value(params)?;
5396        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5397        let _value = self
5398            .session
5399            .client()
5400            .call(
5401                rpc_methods::SESSION_WORKSPACES_CREATEFILE,
5402                Some(wire_params),
5403            )
5404            .await?;
5405        Ok(())
5406    }
5407
5408    /// Lists workspace checkpoints in chronological order.
5409    ///
5410    /// Wire method: `session.workspaces.listCheckpoints`.
5411    ///
5412    /// # Returns
5413    ///
5414    /// Workspace checkpoints in chronological order; empty when the workspace is not enabled.
5415    ///
5416    /// <div class="warning">
5417    ///
5418    /// **Experimental.** This API is part of an experimental wire-protocol surface
5419    /// and may change or be removed in future SDK or CLI releases. Pin both the
5420    /// SDK and CLI versions if your code depends on it.
5421    ///
5422    /// </div>
5423    pub async fn list_checkpoints(&self) -> Result<WorkspacesListCheckpointsResult, Error> {
5424        let wire_params = serde_json::json!({ "sessionId": self.session.id() });
5425        let _value = self
5426            .session
5427            .client()
5428            .call(
5429                rpc_methods::SESSION_WORKSPACES_LISTCHECKPOINTS,
5430                Some(wire_params),
5431            )
5432            .await?;
5433        Ok(serde_json::from_value(_value)?)
5434    }
5435
5436    /// Reads the content of a workspace checkpoint by number.
5437    ///
5438    /// Wire method: `session.workspaces.readCheckpoint`.
5439    ///
5440    /// # Parameters
5441    ///
5442    /// * `params` - Checkpoint number to read.
5443    ///
5444    /// # Returns
5445    ///
5446    /// Checkpoint content as a UTF-8 string, or null when the checkpoint or workspace is missing.
5447    ///
5448    /// <div class="warning">
5449    ///
5450    /// **Experimental.** This API is part of an experimental wire-protocol surface
5451    /// and may change or be removed in future SDK or CLI releases. Pin both the
5452    /// SDK and CLI versions if your code depends on it.
5453    ///
5454    /// </div>
5455    pub async fn read_checkpoint(
5456        &self,
5457        params: WorkspacesReadCheckpointRequest,
5458    ) -> Result<WorkspacesReadCheckpointResult, Error> {
5459        let mut wire_params = serde_json::to_value(params)?;
5460        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5461        let _value = self
5462            .session
5463            .client()
5464            .call(
5465                rpc_methods::SESSION_WORKSPACES_READCHECKPOINT,
5466                Some(wire_params),
5467            )
5468            .await?;
5469        Ok(serde_json::from_value(_value)?)
5470    }
5471
5472    /// Saves pasted content as a UTF-8 file in the session workspace.
5473    ///
5474    /// Wire method: `session.workspaces.saveLargePaste`.
5475    ///
5476    /// # Parameters
5477    ///
5478    /// * `params` - Pasted content to save as a UTF-8 file in the session workspace.
5479    ///
5480    /// # Returns
5481    ///
5482    /// Descriptor for the saved paste file, or null when the workspace is unavailable.
5483    ///
5484    /// <div class="warning">
5485    ///
5486    /// **Experimental.** This API is part of an experimental wire-protocol surface
5487    /// and may change or be removed in future SDK or CLI releases. Pin both the
5488    /// SDK and CLI versions if your code depends on it.
5489    ///
5490    /// </div>
5491    pub async fn save_large_paste(
5492        &self,
5493        params: WorkspacesSaveLargePasteRequest,
5494    ) -> Result<WorkspacesSaveLargePasteResult, Error> {
5495        let mut wire_params = serde_json::to_value(params)?;
5496        wire_params["sessionId"] = serde_json::Value::String(self.session.id().to_string());
5497        let _value = self
5498            .session
5499            .client()
5500            .call(
5501                rpc_methods::SESSION_WORKSPACES_SAVELARGEPASTE,
5502                Some(wire_params),
5503            )
5504            .await?;
5505        Ok(serde_json::from_value(_value)?)
5506    }
5507}