github-copilot-sdk 1.0.32-preview.0

Rust SDK for programmatic control of the GitHub Copilot CLI via JSON-RPC.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
//! Auto-generated typed JSON-RPC namespace — do not edit manually.
//!
//! Generated from `api.schema.json` by `scripts/codegen/rust.ts`. The
//! [`ClientRpc`] and [`SessionRpc`] view structs let callers reach every
//! protocol method through a typed namespace tree, so wire method names
//! and request/response shapes live in exactly one place — this file.

#![allow(missing_docs)]
#![allow(clippy::too_many_arguments)]
#![allow(deprecated)]
#![allow(dead_code)]

use super::cli_api_types::{rpc_methods, *};
use crate::session::Session;
use crate::{Client, Error};

/// Typed view over the [`Client`]'s server-level RPC namespace.
#[derive(Clone, Copy)]
pub struct ClientRpc<'a> {
    pub(crate) client: &'a Client,
}

impl<'a> ClientRpc<'a> {
    /// `cafeMetrics.*` sub-namespace.
    pub fn cafe_metrics(&self) -> ClientRpcCafeMetrics<'a> {
        ClientRpcCafeMetrics {
            client: self.client,
        }
    }

    /// `providersSource.*` sub-namespace.
    pub fn providers_source(&self) -> ClientRpcProvidersSource<'a> {
        ClientRpcProvidersSource {
            client: self.client,
        }
    }

    /// `session.*` sub-namespace.
    pub fn session(&self) -> ClientRpcSession<'a> {
        ClientRpcSession {
            client: self.client,
        }
    }
}

/// `cafeMetrics.*` RPCs.
#[derive(Clone, Copy)]
pub struct ClientRpcCafeMetrics<'a> {
    pub(crate) client: &'a Client,
}

impl<'a> ClientRpcCafeMetrics<'a> {
    /// Starts anonymous CAFE metrics for this process. The runtime selects the endpoint from COPILOT_CAFE_METRICS_URL or this connection's original auth owner. Offline and unsupported platforms refuse startup. Release eligibility must resolve before samples are sent. Requires the private trusted CLI host capability.
    ///
    /// Wire method: `cafeMetrics.start`.
    ///
    /// # Parameters
    ///
    /// * `params` - Versions and provider configuration for CAFE.
    ///
    /// # Returns
    ///
    /// CAFE startup result.
    ///
    /// <div class="warning">
    ///
    /// **Experimental.** This API is part of an experimental wire-protocol surface
    /// and may change or be removed in future SDK or CLI releases. Pin both the
    /// SDK and CLI versions if your code depends on it.
    ///
    /// </div>
    pub async fn start(
        &self,
        params: CafeMetricsStartRequest,
    ) -> Result<CafeMetricsStartResult, Error> {
        let wire_params = serde_json::to_value(params)?;
        self.client
            .call_typed(rpc_methods::CAFEMETRICS_START, Some(wire_params))
            .await
    }

    /// Resolves release eligibility once from the immutable release lookup shared with auto-update. Requires the private trusted CLI host capability.
    ///
    /// Wire method: `cafeMetrics.resolveAdmission`.
    ///
    /// # Parameters
    ///
    /// * `params` - Immutable release lookup result.
    ///
    /// # Returns
    ///
    /// Admission result.
    ///
    /// <div class="warning">
    ///
    /// **Experimental.** This API is part of an experimental wire-protocol surface
    /// and may change or be removed in future SDK or CLI releases. Pin both the
    /// SDK and CLI versions if your code depends on it.
    ///
    /// </div>
    pub async fn resolve_admission(
        &self,
        params: CafeMetricsResolveAdmissionRequest,
    ) -> Result<CafeMetricsResolveAdmissionResult, Error> {
        let wire_params = serde_json::to_value(params)?;
        self.client
            .call_typed(rpc_methods::CAFEMETRICS_RESOLVEADMISSION, Some(wire_params))
            .await
    }

    /// Records one terminal resume result. Does nothing before startup. Requires the private trusted CLI host capability.
    ///
    /// Wire method: `cafeMetrics.recordResumeResult`.
    ///
    /// # Parameters
    ///
    /// * `params` - Terminal result of one resume attempt.
    ///
    /// <div class="warning">
    ///
    /// **Experimental.** This API is part of an experimental wire-protocol surface
    /// and may change or be removed in future SDK or CLI releases. Pin both the
    /// SDK and CLI versions if your code depends on it.
    ///
    /// </div>
    pub async fn record_resume_result(
        &self,
        params: CafeMetricsRecordResumeResultRequest,
    ) -> Result<(), Error> {
        let wire_params = serde_json::to_value(params)?;
        let _: serde::de::IgnoredAny = self
            .client
            .call_typed(
                rpc_methods::CAFEMETRICS_RECORDRESUMERESULT,
                Some(wire_params),
            )
            .await?;
        Ok(())
    }

    /// Stops recording and drains within one 1.5-second deadline. flushOnly sends at most one batch without stopping recording. Requires the private trusted CLI host capability.
    ///
    /// Wire method: `cafeMetrics.shutdown`.
    ///
    /// <div class="warning">
    ///
    /// **Experimental.** This API is part of an experimental wire-protocol surface
    /// and may change or be removed in future SDK or CLI releases. Pin both the
    /// SDK and CLI versions if your code depends on it.
    ///
    /// </div>
    pub async fn shutdown(&self) -> Result<(), Error> {
        let wire_params = serde_json::json!({});
        let _: serde::de::IgnoredAny = self
            .client
            .call_typed(rpc_methods::CAFEMETRICS_SHUTDOWN, Some(wire_params))
            .await?;
        Ok(())
    }

    /// Stops recording and drains within one 1.5-second deadline. flushOnly sends at most one batch without stopping recording. Requires the private trusted CLI host capability.
    ///
    /// Wire method: `cafeMetrics.shutdown`.
    ///
    /// # Parameters
    ///
    /// * `params` - Preliminary flush or final disposal.
    ///
    /// <div class="warning">
    ///
    /// **Experimental.** This API is part of an experimental wire-protocol surface
    /// and may change or be removed in future SDK or CLI releases. Pin both the
    /// SDK and CLI versions if your code depends on it.
    ///
    /// </div>
    pub async fn shutdown_with_params(
        &self,
        params: CafeMetricsShutdownRequest,
    ) -> Result<(), Error> {
        let wire_params = serde_json::to_value(params)?;
        let _: serde::de::IgnoredAny = self
            .client
            .call_typed(rpc_methods::CAFEMETRICS_SHUTDOWN, Some(wire_params))
            .await?;
        Ok(())
    }
}

/// `providersSource.*` RPCs.
#[derive(Clone, Copy)]
pub struct ClientRpcProvidersSource<'a> {
    pub(crate) client: &'a Client,
}

impl<'a> ClientRpcProvidersSource<'a> {
    /// Forwards a saved-model addition over the original authenticated local attachment to its owning server. Requires private CLI-host admission and fails if that attachment is no longer active; never saves to the controller as a fallback.
    ///
    /// Wire method: `providersSource.addModel`.
    ///
    /// # Parameters
    ///
    /// * `params` - Saves through the exact authenticated local attachment that discovered a model.
    ///
    /// # Returns
    ///
    /// Result of adding a model to the saved provider configuration.
    ///
    /// <div class="warning">
    ///
    /// **Experimental.** This API is part of an experimental wire-protocol surface
    /// and may change or be removed in future SDK or CLI releases. Pin both the
    /// SDK and CLI versions if your code depends on it.
    ///
    /// </div>
    pub async fn add_model(
        &self,
        params: AttachedProviderConfigurationAddModelRequest,
    ) -> Result<SavedProviderConfigurationAddModelResult, Error> {
        let wire_params = serde_json::to_value(params)?;
        self.client
            .call_typed(rpc_methods::PROVIDERSSOURCE_ADDMODEL, Some(wire_params))
            .await
    }
}

/// `session.*` RPCs.
#[derive(Clone, Copy)]
pub struct ClientRpcSession<'a> {
    pub(crate) client: &'a Client,
}

impl<'a> ClientRpcSession<'a> {
    /// `session.cafeMetrics.*` sub-namespace.
    pub fn cafe_metrics(&self) -> ClientRpcSessionCafeMetrics<'a> {
        ClientRpcSessionCafeMetrics {
            client: self.client,
        }
    }

    /// `session.canvasSource.*` sub-namespace.
    pub fn canvas_source(&self) -> ClientRpcSessionCanvasSource<'a> {
        ClientRpcSessionCanvasSource {
            client: self.client,
        }
    }

    /// `session.mcp.*` sub-namespace.
    pub fn mcp(&self) -> ClientRpcSessionMcp<'a> {
        ClientRpcSessionMcp {
            client: self.client,
        }
    }
}

/// `session.cafeMetrics.*` RPCs.
#[derive(Clone, Copy)]
pub struct ClientRpcSessionCafeMetrics<'a> {
    pub(crate) client: &'a Client,
}

impl<'a> ClientRpcSessionCafeMetrics<'a> {
    /// Records live model-call events, including subagents, and root compaction events. Replaces any earlier recorder. Requires the private trusted CLI host capability.
    ///
    /// Wire method: `session.cafeMetrics.attach`.
    ///
    /// # Parameters
    ///
    /// * `params` - Identifies the target session.
    ///
    /// <div class="warning">
    ///
    /// **Experimental.** This API is part of an experimental wire-protocol surface
    /// and may change or be removed in future SDK or CLI releases. Pin both the
    /// SDK and CLI versions if your code depends on it.
    ///
    /// </div>
    pub async fn attach(&self, params: SessionCafeMetricsAttachParams) -> Result<(), Error> {
        let wire_params = serde_json::to_value(params)?;
        let _: serde::de::IgnoredAny = self
            .client
            .call_typed(rpc_methods::SESSION_CAFEMETRICS_ATTACH, Some(wire_params))
            .await?;
        Ok(())
    }

    /// Stops recording this session. Does nothing if it has no recorder. Requires the private trusted CLI host capability.
    ///
    /// Wire method: `session.cafeMetrics.detach`.
    ///
    /// # Parameters
    ///
    /// * `params` - Identifies the target session.
    ///
    /// <div class="warning">
    ///
    /// **Experimental.** This API is part of an experimental wire-protocol surface
    /// and may change or be removed in future SDK or CLI releases. Pin both the
    /// SDK and CLI versions if your code depends on it.
    ///
    /// </div>
    pub async fn detach(&self, params: SessionCafeMetricsDetachParams) -> Result<(), Error> {
        let wire_params = serde_json::to_value(params)?;
        let _: serde::de::IgnoredAny = self
            .client
            .call_typed(rpc_methods::SESSION_CAFEMETRICS_DETACH, Some(wire_params))
            .await?;
        Ok(())
    }
}

/// `session.canvasSource.*` RPCs.
#[derive(Clone, Copy)]
pub struct ClientRpcSessionCanvasSource<'a> {
    pub(crate) client: &'a Client,
}

impl<'a> ClientRpcSessionCanvasSource<'a> {
    /// Closes a canvas through its original session source. Requires the privately admitted in-process CLI host.
    ///
    /// Wire method: `session.canvasSource.close`.
    ///
    /// # Parameters
    ///
    /// * `params` - Closes a canvas through its original owned or attached session namespace.
    ///
    /// <div class="warning">
    ///
    /// **Experimental.** This API is part of an experimental wire-protocol surface
    /// and may change or be removed in future SDK or CLI releases. Pin both the
    /// SDK and CLI versions if your code depends on it.
    ///
    /// </div>
    pub async fn close(&self, params: CanvasSourceCloseRequest) -> Result<(), Error> {
        let wire_params = serde_json::to_value(params)?;
        let _: serde::de::IgnoredAny = self
            .client
            .call_typed(rpc_methods::SESSION_CANVASSOURCE_CLOSE, Some(wire_params))
            .await?;
        Ok(())
    }
}

/// `session.mcp.*` RPCs.
#[derive(Clone, Copy)]
pub struct ClientRpcSessionMcp<'a> {
    pub(crate) client: &'a Client,
}

impl<'a> ClientRpcSessionMcp<'a> {
    /// `mcp.oauth.*` sub-namespace.
    pub fn oauth(&self) -> ClientRpcSessionMcpOauth<'a> {
        ClientRpcSessionMcpOauth {
            client: self.client,
        }
    }
}

/// `mcp.oauth.*` RPCs.
#[derive(Clone, Copy)]
pub struct ClientRpcSessionMcpOauth<'a> {
    pub(crate) client: &'a Client,
}

impl<'a> ClientRpcSessionMcpOauth<'a> {
    /// Reserves a host-driven OAuth flow identity before authentication or cancellation.
    ///
    /// Wire method: `session.mcp.oauth.prepareFlow`.
    ///
    /// # Parameters
    ///
    /// * `params` - Correlation identity reserved before an effectful authentication request.
    ///
    /// <div class="warning">
    ///
    /// **Experimental.** This API is part of an experimental wire-protocol surface
    /// and may change or be removed in future SDK or CLI releases. Pin both the
    /// SDK and CLI versions if your code depends on it.
    ///
    /// </div>
    pub async fn prepare_flow(
        &self,
        params: SessionMcpOauthPrepareFlowParams,
    ) -> Result<(), Error> {
        let wire_params = serde_json::to_value(params)?;
        let _: serde::de::IgnoredAny = self
            .client
            .call_typed(
                rpc_methods::SESSION_MCP_OAUTH_PREPAREFLOW,
                Some(wire_params),
            )
            .await?;
        Ok(())
    }

    /// Cancels an exact host-driven OAuth flow on its original session requester.
    ///
    /// Wire method: `session.mcp.oauth.cancelFlow`.
    ///
    /// # Parameters
    ///
    /// * `params` - Correlation identity reserved before an effectful authentication request.
    ///
    /// <div class="warning">
    ///
    /// **Experimental.** This API is part of an experimental wire-protocol surface
    /// and may change or be removed in future SDK or CLI releases. Pin both the
    /// SDK and CLI versions if your code depends on it.
    ///
    /// </div>
    pub async fn cancel_flow(&self, params: SessionMcpOauthCancelFlowParams) -> Result<(), Error> {
        let wire_params = serde_json::to_value(params)?;
        let _: serde::de::IgnoredAny = self
            .client
            .call_typed(rpc_methods::SESSION_MCP_OAUTH_CANCELFLOW, Some(wire_params))
            .await?;
        Ok(())
    }

    /// Authenticates an arbitrary MCP URL through the original session credential owner, with correlated host progress and authorization callbacks.
    ///
    /// Wire method: `session.mcp.oauth.authenticate`.
    ///
    /// # Parameters
    ///
    /// * `params` - Full host-driven authentication for an arbitrary, possibly unsaved, MCP URL.
    ///
    /// # Returns
    ///
    /// Token projection for the existing host-delegated provider.
    ///
    /// <div class="warning">
    ///
    /// **Experimental.** This API is part of an experimental wire-protocol surface
    /// and may change or be removed in future SDK or CLI releases. Pin both the
    /// SDK and CLI versions if your code depends on it.
    ///
    /// </div>
    pub async fn authenticate(
        &self,
        params: SessionMcpOauthAuthenticateParams,
    ) -> Result<McpOauthAuthenticateResult, Error> {
        let wire_params = serde_json::to_value(params)?;
        self.client
            .call_typed(
                rpc_methods::SESSION_MCP_OAUTH_AUTHENTICATE,
                Some(wire_params),
            )
            .await
    }

    /// Checks whether the selected MCP credential owner has a valid access token.
    ///
    /// Wire method: `session.mcp.oauth.hasValidTokens`.
    ///
    /// # Parameters
    ///
    /// * `params` - A narrow token-validity query against the chosen credential owner.
    ///
    /// # Returns
    ///
    /// Whether the credential operation succeeded.
    ///
    /// <div class="warning">
    ///
    /// **Experimental.** This API is part of an experimental wire-protocol surface
    /// and may change or be removed in future SDK or CLI releases. Pin both the
    /// SDK and CLI versions if your code depends on it.
    ///
    /// </div>
    pub async fn has_valid_tokens(
        &self,
        params: SessionMcpOauthHasValidTokensParams,
    ) -> Result<SessionMcpOauthHasValidTokensResult, Error> {
        let wire_params = serde_json::to_value(params)?;
        self.client
            .call_typed(
                rpc_methods::SESSION_MCP_OAUTH_HASVALIDTOKENS,
                Some(wire_params),
            )
            .await
    }

    /// Attempts silent MCP token refresh without opening a browser.
    ///
    /// Wire method: `session.mcp.oauth.tryRefreshTokens`.
    ///
    /// # Parameters
    ///
    /// * `params` - A narrow token-validity query against the chosen credential owner.
    ///
    /// # Returns
    ///
    /// Whether the credential operation succeeded.
    ///
    /// <div class="warning">
    ///
    /// **Experimental.** This API is part of an experimental wire-protocol surface
    /// and may change or be removed in future SDK or CLI releases. Pin both the
    /// SDK and CLI versions if your code depends on it.
    ///
    /// </div>
    pub async fn try_refresh_tokens(
        &self,
        params: SessionMcpOauthTryRefreshTokensParams,
    ) -> Result<SessionMcpOauthTryRefreshTokensResult, Error> {
        let wire_params = serde_json::to_value(params)?;
        self.client
            .call_typed(
                rpc_methods::SESSION_MCP_OAUTH_TRYREFRESHTOKENS,
                Some(wire_params),
            )
            .await
    }

    /// Stores a confidential MCP client's static secret in its selected credential owner.
    ///
    /// Wire method: `session.mcp.oauth.saveStaticClientSecret`.
    ///
    /// # Parameters
    ///
    /// * `params` - Persist a confidential client's static secret without exposing token-store CRUD.
    ///
    /// <div class="warning">
    ///
    /// **Experimental.** This API is part of an experimental wire-protocol surface
    /// and may change or be removed in future SDK or CLI releases. Pin both the
    /// SDK and CLI versions if your code depends on it.
    ///
    /// </div>
    pub async fn save_static_client_secret(
        &self,
        params: SessionMcpOauthSaveStaticClientSecretParams,
    ) -> Result<(), Error> {
        let wire_params = serde_json::to_value(params)?;
        let _: serde::de::IgnoredAny = self
            .client
            .call_typed(
                rpc_methods::SESSION_MCP_OAUTH_SAVESTATICCLIENTSECRET,
                Some(wire_params),
            )
            .await?;
        Ok(())
    }

    /// Releases an explicit host-owned MCP OAuth store on its original session requester.
    ///
    /// Wire method: `session.mcp.oauth.disposeStore`.
    ///
    /// # Parameters
    ///
    /// * `params` - Dispose an explicit host store without altering the session authorizer's owner.
    ///
    /// <div class="warning">
    ///
    /// **Experimental.** This API is part of an experimental wire-protocol surface
    /// and may change or be removed in future SDK or CLI releases. Pin both the
    /// SDK and CLI versions if your code depends on it.
    ///
    /// </div>
    pub async fn dispose_store(
        &self,
        params: SessionMcpOauthDisposeStoreParams,
    ) -> Result<(), Error> {
        let wire_params = serde_json::to_value(params)?;
        let _: serde::de::IgnoredAny = self
            .client
            .call_typed(
                rpc_methods::SESSION_MCP_OAUTH_DISPOSESTORE,
                Some(wire_params),
            )
            .await?;
        Ok(())
    }

    /// Completes a tokenless initialize handshake for an unsaved remote MCP URL, preserving session egress and the refusing authentication challenge.
    ///
    /// Wire method: `session.mcp.oauth.testConnection`.
    ///
    /// # Parameters
    ///
    /// * `params` - Tokenless initialize handshake for a possibly unsaved remote MCP server.
    ///
    /// # Returns
    ///
    /// Outcome of the tokenless handshake, with the original challenge when available.
    ///
    /// <div class="warning">
    ///
    /// **Experimental.** This API is part of an experimental wire-protocol surface
    /// and may change or be removed in future SDK or CLI releases. Pin both the
    /// SDK and CLI versions if your code depends on it.
    ///
    /// </div>
    pub async fn test_connection(
        &self,
        params: SessionMcpOauthTestConnectionParams,
    ) -> Result<McpOauthTestConnectionResult, Error> {
        let wire_params = serde_json::to_value(params)?;
        self.client
            .call_typed(
                rpc_methods::SESSION_MCP_OAUTH_TESTCONNECTION,
                Some(wire_params),
            )
            .await
    }

    /// Derives an MCP credential key through the selected session account and store owner.
    ///
    /// Wire method: `session.mcp.oauth.storeKey`.
    ///
    /// # Parameters
    ///
    /// * `params` - Derive a credential key through the selected account and store owner.
    ///
    /// # Returns
    ///
    /// The selected owner's OAuth credential key.
    ///
    /// <div class="warning">
    ///
    /// **Experimental.** This API is part of an experimental wire-protocol surface
    /// and may change or be removed in future SDK or CLI releases. Pin both the
    /// SDK and CLI versions if your code depends on it.
    ///
    /// </div>
    pub async fn store_key(
        &self,
        params: SessionMcpOauthStoreKeyParams,
    ) -> Result<SessionMcpOauthStoreKeyResult, Error> {
        let wire_params = serde_json::to_value(params)?;
        self.client
            .call_typed(rpc_methods::SESSION_MCP_OAUTH_STOREKEY, Some(wire_params))
            .await
    }
}

/// Typed view over a [`Session`]'s RPC namespace.
#[derive(Clone, Copy)]
pub(crate) struct SessionRpc<'a> {
    pub(crate) session: &'a Session,
}

impl<'a> SessionRpc<'a> {}