MCPcopy Create free account
hub / github.com/cli/cli / CapiClientFunc

Function CapiClientFunc

pkg/cmd/agent-task/shared/capi.go:21–46  ·  view source on GitHub ↗
(f *cmdutil.Factory)

Source from the content-addressed store, hash-verified

19var agentSessionURLRegexp = regexp.MustCompile(fmt.Sprintf("^/agent-sessions/(%s)$", uuidPattern))
20
21func CapiClientFunc(f *cmdutil.Factory) func() (capi.CapiClient, error) {
22 return func() (capi.CapiClient, error) {
23 cfg, err := f.Config()
24 if err != nil {
25 return nil, err
26 }
27
28 httpClient, err := f.HttpClient()
29 if err != nil {
30 return nil, err
31 }
32
33 authCfg := cfg.Authentication()
34 host, _ := authCfg.DefaultHost()
35
36 cachedClient := api.NewCachedHTTPClient(httpClient, time.Minute*10)
37 capiBaseURL, err := resolveCapiURL(cachedClient, host)
38 if err != nil {
39 return nil, fmt.Errorf("failed to resolve Copilot API URL: %w", err)
40 }
41
42 // The CAPI client authenticates by setting the token header itself, which bypasses the base HTTP client's
43 // auto-refresh. Pass authCfg so the CAPI transport can refresh an expiring token on each request.
44 return capi.NewCAPIClient(httpClient, authCfg, host, capiBaseURL), nil
45 }
46}
47
48// resolveCapiURL queries the GitHub API for the Copilot API endpoint URL.
49func resolveCapiURL(httpClient *http.Client, host string) (string, error) {

Callers 2

NewCmdCreateFunction · 0.92

Calls 7

NewCachedHTTPClientFunction · 0.92
NewCAPIClientFunction · 0.92
resolveCapiURLFunction · 0.85
ConfigMethod · 0.65
AuthenticationMethod · 0.65
DefaultHostMethod · 0.65
ErrorfMethod · 0.65

Tested by 1