@nervekit/desktop 0.40.0 → 0.40.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/THIRD-PARTY-LICENSES.txt +5087 -485
  2. package/dist/{chunk-KSZJ3HGD.js → chunk-2BKMOJYJ.js} +1 -1
  3. package/dist/{chunk-5UT23MT6.js → chunk-3JJN36GV.js} +70 -71
  4. package/dist/{chunk-2Z5FLMLE.js → chunk-3SSNDIQT.js} +1 -1
  5. package/dist/{chunk-PUM6UCBT.js → chunk-3VZR3ZUY.js} +55 -8
  6. package/dist/{chunk-BXVRC3HF.js → chunk-4H3WR7IT.js} +1 -1
  7. package/dist/{chunk-QVHYARC2.js → chunk-4VPX67B7.js} +3 -1
  8. package/dist/chunk-5NN7JAJ2.js +258 -0
  9. package/dist/{chunk-BPOIFVQO.js → chunk-6FSDDGFZ.js} +731 -605
  10. package/dist/chunk-6PACEIUY.js +183 -0
  11. package/dist/{chunk-XNYZEQ3U.js → chunk-6TAN6WG6.js} +1 -1
  12. package/dist/{chunk-RWLLVZ7I.js → chunk-7FLZA2BD.js} +31 -15
  13. package/dist/{chunk-WTHP3VH6.js → chunk-7JQBECUL.js} +1 -1
  14. package/dist/{chunk-5Y3NEEOK.js → chunk-AAEIGAGD.js} +9 -9
  15. package/dist/{chunk-UN3GLM4U.js → chunk-ANI6J75M.js} +68 -65
  16. package/dist/chunk-B4IE2GAM.js +14 -0
  17. package/dist/chunk-BNVMNV4O.js +69 -0
  18. package/dist/{chunk-L3YB2QLN.js → chunk-C6RO4LP3.js} +2 -2
  19. package/dist/chunk-DTGL5P2V.js +250 -0
  20. package/dist/{chunk-U4DBQKHO.js → chunk-E4JNHQGT.js} +11 -9
  21. package/dist/chunk-EJM4HMEL.js +45 -0
  22. package/dist/chunk-ER2ES2RH.js +64 -0
  23. package/dist/{chunk-SQ7CWNIT.js → chunk-EX63VKXY.js} +1 -1
  24. package/dist/{chunk-JDI4D5EM.js → chunk-F3MHINI6.js} +19 -23
  25. package/dist/chunk-FGZX4Q7W.js +22828 -0
  26. package/dist/{chunk-LPCHTKEK.js → chunk-FZ5N6WXF.js} +31 -160
  27. package/dist/chunk-H2G55ZPG.js +783 -0
  28. package/dist/chunk-HDBDYGJQ.js +40 -0
  29. package/dist/{chunk-RU6S57LK.js → chunk-HOCODVKL.js} +22 -24
  30. package/dist/chunk-JCF3ZRP4.js +481 -0
  31. package/dist/chunk-K2J2VZXO.js +142 -0
  32. package/dist/chunk-KBNEZR7T.js +135 -0
  33. package/dist/chunk-KSSM6LUI.js +340 -0
  34. package/dist/{chunk-HHUSIAK3.js → chunk-KTGSBL6T.js} +14 -17
  35. package/dist/chunk-L2DHKP5C.js +42 -0
  36. package/dist/{chunk-DBXMYYPJ.js → chunk-M3ELKCNA.js} +1 -1
  37. package/dist/chunk-M7WTH5K5.js +822 -0
  38. package/dist/{chunk-LZRPWVVJ.js → chunk-MWIKZIAI.js} +9 -8
  39. package/dist/{chunk-AON37AL2.js → chunk-O2652RWY.js} +29 -4
  40. package/dist/chunk-O6U226AI.js +249 -0
  41. package/dist/{chunk-5R3UAHXF.js → chunk-OAEV22IW.js} +48 -26
  42. package/dist/chunk-OANTMDXI.js +29 -0
  43. package/dist/{chunk-UGDIHDAR.js → chunk-ODS5QROC.js} +1 -1
  44. package/dist/{chunk-Q7LPOIKN.js → chunk-OQC3F6JA.js} +3 -471
  45. package/dist/{chunk-YA2WJRUO.js → chunk-PST63OUS.js} +5 -5
  46. package/dist/{chunk-S2PITDVA.js → chunk-QBAIDKF6.js} +1 -1
  47. package/dist/chunk-RPLBWENJ.js +224 -0
  48. package/dist/{chunk-GCSWN326.js → chunk-S62LLS4I.js} +33 -55
  49. package/dist/chunk-SHEU5KLD.js +32 -0
  50. package/dist/{chunk-FESN7DND.js → chunk-SU2USXTD.js} +1 -1
  51. package/dist/chunk-T6NRMNLQ.js +22 -0
  52. package/dist/{chunk-NSA42OOT.js → chunk-TGKIV3F4.js} +53 -65
  53. package/dist/{chunk-MN7PZ2PH.js → chunk-TSV3PFU2.js} +2 -2
  54. package/dist/{chunk-D5WJKB4R.js → chunk-UDC7NPQJ.js} +4 -3
  55. package/dist/{chunk-CEX2GWGZ.js → chunk-VBM7TD3X.js} +1 -1
  56. package/dist/chunk-VC6TX2Y2.js +359 -0
  57. package/dist/{chunk-7FI3LC3O.js → chunk-VTDI5KP7.js} +241 -104
  58. package/dist/{chunk-P2GSKP6N.js → chunk-WIN7KHMV.js} +15 -18
  59. package/dist/chunk-WJULIJOU.js +168 -0
  60. package/dist/{chunk-HKLAYK2Z.js → chunk-WRTA5G57.js} +23 -0
  61. package/dist/{chunk-4ZNLXHTH.js → chunk-WYPVD3HW.js} +10 -9
  62. package/dist/{chunk-V7EAFXAX.js → chunk-XE2E2KBP.js} +10 -9
  63. package/dist/chunk-XY53EFK3.js +39 -0
  64. package/dist/chunk-XZYFB566.js +153 -0
  65. package/dist/{chunk-H4CDZRIE.js → chunk-YJT4NXMV.js} +5 -5
  66. package/dist/{chunk-ET5RYBGZ.js → chunk-YQFENES6.js} +3 -3
  67. package/dist/chunk-YUO5V75X.js +128 -0
  68. package/dist/chunk-YYLKI74V.js +8778 -0
  69. package/dist/daemon.js +15 -10
  70. package/dist/git-isolated-reader-helper.js +1 -1
  71. package/dist/main.js +14 -9
  72. package/dist/web/assets/{AsyncBashCenterHost-HGsdxUJ3.js → AsyncBashCenterHost-BvXKoCVr.js} +1 -1
  73. package/dist/web/assets/{ConversationsWorkbenchPanel-B6dzWkG1.js → ConversationsWorkbenchPanel-CIfK_e3I.js} +1 -1
  74. package/dist/web/assets/{DiscoverCenterHost-B186WBRA.js → DiscoverCenterHost-Ep8EN9iJ.js} +1 -1
  75. package/dist/web/assets/{FileCenterHost-DigJOU5M.js → FileCenterHost-C_7XZAFZ.js} +1 -1
  76. package/dist/web/assets/{FilesWorkbenchPanel-VPvx3Bmi.js → FilesWorkbenchPanel-CtXo7ywG.js} +1 -1
  77. package/dist/web/assets/{GitDiffCenterHost-IuZfF3hG.js → GitDiffCenterHost-Cr7lqGI_.js} +1 -1
  78. package/dist/web/assets/{GitWorkbenchPanel-CScC0CfH.js → GitWorkbenchPanel-BFbwUgIN.js} +1 -1
  79. package/dist/web/assets/{LaunchConfigurationNotice-5yb4cH27.js → LaunchConfigurationNotice-CJjWkMhv.js} +1 -1
  80. package/dist/web/assets/{LaunchesWorkbenchPanel-Vy0Gm7gg.js → LaunchesWorkbenchPanel-BqzJvsrj.js} +1 -1
  81. package/dist/web/assets/{LogsCenterHost-BXBozCYw.js → LogsCenterHost-BI1fSxFW.js} +1 -1
  82. package/dist/web/assets/{MermaidCenterHost-DDh4ArdK.js → MermaidCenterHost-DVsZB8nB.js} +1 -1
  83. package/dist/web/assets/{MobileFilesBody-Cda_7gDp.js → MobileFilesBody-BJMoaP9I.js} +1 -1
  84. package/dist/web/assets/{MobileFilesHost-C1jev2Un.js → MobileFilesHost-D843vkDF.js} +1 -1
  85. package/dist/web/assets/{MobileLaunchOutputHost-Bsv12o2H.js → MobileLaunchOutputHost-vpltMcar.js} +1 -1
  86. package/dist/web/assets/{MobileLaunchesHost-C9VH-2bn.js → MobileLaunchesHost-CdDrKASg.js} +1 -1
  87. package/dist/web/assets/{MobileLogsHost-BMDXc-WC.js → MobileLogsHost-qK7N-C1y.js} +1 -1
  88. package/dist/web/assets/{MobileNoteEditorHost-BA6WIY1Y.js → MobileNoteEditorHost-Bg1N8o54.js} +1 -1
  89. package/dist/web/assets/{MobileNotesHost-BZeYpK9H.js → MobileNotesHost-meLV39Yw.js} +1 -1
  90. package/dist/web/assets/{MobileProjectSettingsHost-U3Mx3EN8.js → MobileProjectSettingsHost-A49Fdn54.js} +1 -1
  91. package/dist/web/assets/{MobileProjectSettingsPageHost-CMvxbjfs.js → MobileProjectSettingsPageHost-BXpUqS_N.js} +1 -1
  92. package/dist/web/assets/{MobileSettingsHost-CP8Z_-gH.js → MobileSettingsHost-DPKPajzI.js} +1 -1
  93. package/dist/web/assets/{MobileSettingsPageHost-BPjXKTMV.js → MobileSettingsPageHost-izNWGN0i.js} +1 -1
  94. package/dist/web/assets/{MobileSettingsPageScreen-C5rHdrUU.js → MobileSettingsPageScreen-DWMg4fDo.js} +1 -1
  95. package/dist/web/assets/{ProjectSettingsCenterHost-BVXpBixy.js → ProjectSettingsCenterHost-DHeb274m.js} +1 -1
  96. package/dist/web/assets/{PullRequestCenterHost-CZhXfCX2.js → PullRequestCenterHost-BYkWxXQe.js} +1 -1
  97. package/dist/web/assets/{PullRequestsWorkbenchPanel-BBnZJVnI.js → PullRequestsWorkbenchPanel-ZvGbi1Cr.js} +1 -1
  98. package/dist/web/assets/{SearchWorkbenchPanel-qLgszneN.js → SearchWorkbenchPanel-DaC0smfe.js} +1 -1
  99. package/dist/web/assets/{SettingsCenter-7BfrBfiy.js → SettingsCenter-C_NLBsi6.js} +1 -1
  100. package/dist/web/assets/{SettingsCenterHost-Ck5uHILP.js → SettingsCenterHost-jP8MULEj.js} +1 -1
  101. package/dist/web/assets/{SystemPromptCenterHost-ya5AvXsd.js → SystemPromptCenterHost-B1hfsfAn.js} +1 -1
  102. package/dist/web/assets/{discover-B3I5g1_G.js → discover-B-aZ504j.js} +1 -1
  103. package/dist/web/assets/{index-FJEmK_L5.js → index-TZ1KAAsX.js} +34 -34
  104. package/dist/web/assets/{settings-page-controllers.svelte-CU0i08wo.js → settings-page-controllers.svelte-D_ydJF8u.js} +1 -1
  105. package/dist/web/assets/{shell-layout.svelte-BT2508sa.js → shell-layout.svelte-OoLFwzzJ.js} +2 -2
  106. package/dist/web/assets/{views-Z-n-GTYY.js → views-ByPCKDiZ.js} +1 -1
  107. package/dist/web/index.html +3 -3
  108. package/dist/web/sw.js +1 -1
  109. package/dist/worker.js +14 -9
  110. package/package.json +8 -9
  111. package/dist/chunk-RUZ2UAYH.js +0 -365
  112. package/dist/resize-worker.js +0 -168
  113. /package/dist/{chunk-PUM6UCBT.js.LEGAL.txt → chunk-3VZR3ZUY.js.LEGAL.txt} +0 -0
  114. /package/dist/{chunk-YA2WJRUO.js.LEGAL.txt → chunk-PST63OUS.js.LEGAL.txt} +0 -0
@@ -0,0 +1,359 @@
1
+ import { createRequire as __nerveCreateRequire } from "node:module";
2
+ const require = __nerveCreateRequire(import.meta.url);
3
+ import {
4
+ sleep
5
+ } from "./chunk-T6NRMNLQ.js";
6
+ import {
7
+ trustedHttpUrl
8
+ } from "./chunk-B4IE2GAM.js";
9
+ import {
10
+ pollOAuthDeviceCodeFlow
11
+ } from "./chunk-ER2ES2RH.js";
12
+ import {
13
+ GITHUB_COPILOT_MODELS
14
+ } from "./chunk-SHEU5KLD.js";
15
+ import "./chunk-CWESUMYQ.js";
16
+
17
+ // node_modules/.pnpm/@earendil-works+pi-ai@1.5.1_@aws-sdk+credential-provider-node@3.972.83_@smithy+signatur_e7d72008f907c45a36788e380ed24019/node_modules/@earendil-works/pi-ai/dist/auth/oauth/github-copilot.js
18
+ var decode = (s) => atob(s);
19
+ var CLIENT_ID = decode("SXYxLmI1MDdhMDhjODdlY2ZlOTg=");
20
+ var COPILOT_HEADERS = {
21
+ "User-Agent": "GitHubCopilotChat/0.35.0",
22
+ "Editor-Version": "vscode/1.107.0",
23
+ "Editor-Plugin-Version": "copilot-chat/0.35.0",
24
+ "Copilot-Integration-Id": "vscode-chat"
25
+ };
26
+ var COPILOT_API_VERSION = "2026-06-01";
27
+ function normalizeDomain(input) {
28
+ const trimmed = input.trim();
29
+ if (!trimmed)
30
+ return null;
31
+ try {
32
+ const url = trimmed.includes("://") ? new URL(trimmed) : new URL(`https://${trimmed}`);
33
+ return url.hostname;
34
+ } catch {
35
+ return null;
36
+ }
37
+ }
38
+ function getUrls(domain) {
39
+ return {
40
+ deviceCodeUrl: `https://${domain}/login/device/code`,
41
+ accessTokenUrl: `https://${domain}/login/oauth/access_token`,
42
+ copilotTokenUrl: `https://api.${domain}/copilot_internal/v2/token`
43
+ };
44
+ }
45
+ function getBaseUrlFromToken(token) {
46
+ const match = token.match(/proxy-ep=([^;]+)/);
47
+ if (!match)
48
+ return null;
49
+ const proxyHost = match[1];
50
+ const apiHost = proxyHost.replace(/^proxy\./, "api.");
51
+ return `https://${apiHost}`;
52
+ }
53
+ function getGitHubCopilotBaseUrl(token, enterpriseDomain) {
54
+ if (token) {
55
+ const urlFromToken = getBaseUrlFromToken(token);
56
+ if (urlFromToken)
57
+ return urlFromToken;
58
+ }
59
+ if (enterpriseDomain)
60
+ return `https://copilot-api.${enterpriseDomain}`;
61
+ return "https://api.individual.githubcopilot.com";
62
+ }
63
+ function asRecord(value) {
64
+ return value && typeof value === "object" ? value : void 0;
65
+ }
66
+ function parseGitHubCopilotModelCatalog(raw, allowPolicyFallback) {
67
+ const data = asRecord(raw)?.data;
68
+ if (!Array.isArray(data)) {
69
+ throw new Error("Invalid Copilot models response");
70
+ }
71
+ const accountModels = data.flatMap((rawItem) => {
72
+ const item = asRecord(rawItem);
73
+ const id = item?.id;
74
+ if (!item || typeof id !== "string")
75
+ return [];
76
+ const capabilities = asRecord(item.capabilities);
77
+ const supports = asRecord(capabilities?.supports);
78
+ if (supports?.tool_calls === false)
79
+ return [];
80
+ return [
81
+ {
82
+ id,
83
+ pickerEnabled: item.model_picker_enabled === true,
84
+ policyState: asRecord(item.policy)?.state
85
+ }
86
+ ];
87
+ });
88
+ const pickerModelIds = accountModels.filter((model) => model.pickerEnabled && model.policyState !== "disabled").map((model) => model.id);
89
+ const usePolicyFallback = allowPolicyFallback && pickerModelIds.length === 0;
90
+ const availableModelIds = pickerModelIds.length > 0 || !allowPolicyFallback ? pickerModelIds : accountModels.filter((model) => model.policyState === "enabled").map((model) => model.id);
91
+ const policyModelIds = accountModels.filter((model) => model.policyState === "unconfigured" && Object.hasOwn(GITHUB_COPILOT_MODELS, model.id) && (model.pickerEnabled || usePolicyFallback)).map((model) => model.id);
92
+ return { availableModelIds, policyModelIds };
93
+ }
94
+ async function fetchWithRateLimitRetry(url, init, signal, retryPolicy) {
95
+ const retryBudgetSignal = retryPolicy.maxRetries > 0 && retryPolicy.maxElapsedMs > 0 ? AbortSignal.timeout(retryPolicy.maxElapsedMs) : void 0;
96
+ const requestSignal = retryBudgetSignal ? AbortSignal.any([signal, retryBudgetSignal]) : signal;
97
+ const retryDeadline = retryBudgetSignal ? Date.now() + retryPolicy.maxElapsedMs : void 0;
98
+ for (let retry = 0; ; retry++) {
99
+ const response = await fetch(url, {
100
+ ...init,
101
+ signal: AbortSignal.any([requestSignal, AbortSignal.timeout(5e3)])
102
+ });
103
+ if (response.status !== 429 || retry === retryPolicy.maxRetries)
104
+ return response;
105
+ const retryAfter = response.headers.get("retry-after");
106
+ let delayMs = 500 * 2 ** retry;
107
+ if (retryAfter) {
108
+ const seconds = Number.parseFloat(retryAfter);
109
+ delayMs = Number.isNaN(seconds) ? Date.parse(retryAfter) - Date.now() : seconds * 1e3;
110
+ if (!Number.isFinite(delayMs))
111
+ return response;
112
+ }
113
+ delayMs = Math.max(0, delayMs);
114
+ if (retryDeadline !== void 0 && delayMs >= retryDeadline - Date.now())
115
+ return response;
116
+ await response.body?.cancel();
117
+ await sleep(delayMs, requestSignal);
118
+ }
119
+ }
120
+ async function fetchGitHubCopilotModels(copilotToken, enterpriseDomain, signal, retryPolicy) {
121
+ const baseUrl = getGitHubCopilotBaseUrl(copilotToken, enterpriseDomain);
122
+ const allowPolicyFallback = baseUrl === "https://api.individual.githubcopilot.com";
123
+ const response = await fetchWithRateLimitRetry(`${baseUrl}/models`, {
124
+ headers: {
125
+ Accept: "application/json",
126
+ Authorization: `Bearer ${copilotToken}`,
127
+ ...COPILOT_HEADERS,
128
+ "X-GitHub-Api-Version": COPILOT_API_VERSION
129
+ }
130
+ }, signal, retryPolicy);
131
+ if (!response.ok) {
132
+ throw new Error(`${response.status} ${response.statusText}: ${await response.text()}`);
133
+ }
134
+ return parseGitHubCopilotModelCatalog(await response.json(), allowPolicyFallback);
135
+ }
136
+ async function fetchJson(url, init) {
137
+ const response = await fetch(url, init);
138
+ if (!response.ok) {
139
+ const text = await response.text();
140
+ throw new Error(`${response.status} ${response.statusText}: ${text}`);
141
+ }
142
+ return response.json();
143
+ }
144
+ async function startDeviceFlow(domain, signal) {
145
+ const urls = getUrls(domain);
146
+ const data = await fetchJson(urls.deviceCodeUrl, {
147
+ method: "POST",
148
+ headers: {
149
+ Accept: "application/json",
150
+ "Content-Type": "application/x-www-form-urlencoded",
151
+ "User-Agent": "GitHubCopilotChat/0.35.0"
152
+ },
153
+ body: new URLSearchParams({
154
+ client_id: CLIENT_ID,
155
+ scope: "read:user"
156
+ }),
157
+ signal
158
+ });
159
+ if (!data || typeof data !== "object") {
160
+ throw new Error("Invalid device code response");
161
+ }
162
+ const deviceCode = data.device_code;
163
+ const userCode = data.user_code;
164
+ const verificationUri = data.verification_uri;
165
+ const interval = data.interval;
166
+ const expiresIn = data.expires_in;
167
+ if (typeof deviceCode !== "string" || typeof userCode !== "string" || typeof verificationUri !== "string" || interval !== void 0 && typeof interval !== "number" || typeof expiresIn !== "number") {
168
+ throw new Error("Invalid device code response fields");
169
+ }
170
+ const trustedVerificationUri = trustedHttpUrl(verificationUri);
171
+ if (!trustedVerificationUri) {
172
+ throw new Error("Untrusted verification_uri in device code response");
173
+ }
174
+ return {
175
+ device_code: deviceCode,
176
+ user_code: userCode,
177
+ verification_uri: trustedVerificationUri,
178
+ interval,
179
+ expires_in: expiresIn
180
+ };
181
+ }
182
+ async function pollForGitHubAccessToken(domain, device, signal) {
183
+ const urls = getUrls(domain);
184
+ return pollOAuthDeviceCodeFlow({
185
+ intervalSeconds: device.interval,
186
+ expiresInSeconds: device.expires_in,
187
+ waitBeforeFirstPoll: true,
188
+ signal,
189
+ poll: async () => {
190
+ const raw = await fetchJson(urls.accessTokenUrl, {
191
+ method: "POST",
192
+ headers: {
193
+ Accept: "application/json",
194
+ "Content-Type": "application/x-www-form-urlencoded",
195
+ "User-Agent": "GitHubCopilotChat/0.35.0"
196
+ },
197
+ body: new URLSearchParams({
198
+ client_id: CLIENT_ID,
199
+ device_code: device.device_code,
200
+ grant_type: "urn:ietf:params:oauth:grant-type:device_code"
201
+ }),
202
+ signal
203
+ });
204
+ if (raw && typeof raw === "object" && typeof raw.access_token === "string") {
205
+ return { status: "complete", value: raw.access_token };
206
+ }
207
+ if (raw && typeof raw === "object" && typeof raw.error === "string") {
208
+ const { error, error_description: description, interval } = raw;
209
+ if (error === "authorization_pending") {
210
+ return { status: "pending" };
211
+ }
212
+ if (error === "slow_down") {
213
+ return { status: "slow_down", intervalSeconds: typeof interval === "number" ? interval : void 0 };
214
+ }
215
+ const descriptionSuffix = description ? `: ${description}` : "";
216
+ return { status: "failed", message: `Device flow failed: ${error}${descriptionSuffix}` };
217
+ }
218
+ return { status: "failed", message: "Invalid device token response" };
219
+ }
220
+ });
221
+ }
222
+ async function refreshGitHubCopilotAccessToken(refreshToken, enterpriseDomain, signal) {
223
+ const domain = enterpriseDomain || "github.com";
224
+ const urls = getUrls(domain);
225
+ const raw = await fetchJson(urls.copilotTokenUrl, {
226
+ headers: {
227
+ Accept: "application/json",
228
+ Authorization: `Bearer ${refreshToken}`,
229
+ ...COPILOT_HEADERS
230
+ },
231
+ signal
232
+ });
233
+ if (!raw || typeof raw !== "object") {
234
+ throw new Error("Invalid Copilot token response");
235
+ }
236
+ const token = raw.token;
237
+ const expiresAt = raw.expires_at;
238
+ if (typeof token !== "string" || typeof expiresAt !== "number") {
239
+ throw new Error("Invalid Copilot token response fields");
240
+ }
241
+ return {
242
+ type: "oauth",
243
+ refresh: refreshToken,
244
+ access: token,
245
+ expires: expiresAt * 1e3 - 5 * 60 * 1e3,
246
+ enterpriseUrl: enterpriseDomain
247
+ };
248
+ }
249
+ async function refreshGitHubCopilotToken(refreshToken, enterpriseDomain, signal) {
250
+ const credentials = await refreshGitHubCopilotAccessToken(refreshToken, enterpriseDomain, signal);
251
+ const { availableModelIds } = await fetchGitHubCopilotModels(credentials.access, enterpriseDomain, signal, {
252
+ maxRetries: 0,
253
+ maxElapsedMs: 0
254
+ });
255
+ return {
256
+ ...credentials,
257
+ availableModelIds
258
+ };
259
+ }
260
+ async function enableGitHubCopilotModel(token, modelId, enterpriseDomain, signal) {
261
+ const baseUrl = getGitHubCopilotBaseUrl(token, enterpriseDomain);
262
+ const url = `${baseUrl}/models/${modelId}/policy`;
263
+ let response;
264
+ try {
265
+ response = await fetchWithRateLimitRetry(url, {
266
+ method: "POST",
267
+ headers: {
268
+ "Content-Type": "application/json",
269
+ Authorization: `Bearer ${token}`,
270
+ ...COPILOT_HEADERS,
271
+ "openai-intent": "chat-policy",
272
+ "x-interaction-type": "chat-policy"
273
+ },
274
+ body: JSON.stringify({ state: "enabled" })
275
+ }, signal, { maxRetries: 2, maxElapsedMs: 5e3 });
276
+ } catch (error) {
277
+ if (signal.aborted)
278
+ throw error;
279
+ return false;
280
+ }
281
+ if (response.status === 429) {
282
+ throw new Error(`${response.status} ${response.statusText}: ${await response.text()}`);
283
+ }
284
+ return response.ok;
285
+ }
286
+ async function enableGitHubCopilotModels(token, modelIds, enterpriseDomain, signal) {
287
+ const enabledModelIds = [];
288
+ for (const modelId of modelIds) {
289
+ try {
290
+ if (await enableGitHubCopilotModel(token, modelId, enterpriseDomain, signal)) {
291
+ enabledModelIds.push(modelId);
292
+ }
293
+ } catch (error) {
294
+ if (signal.aborted)
295
+ throw error;
296
+ break;
297
+ }
298
+ }
299
+ return enabledModelIds;
300
+ }
301
+ async function loginGitHubCopilot(interaction) {
302
+ const input = await interaction.prompt({
303
+ type: "text",
304
+ message: "GitHub Enterprise URL/domain (blank for github.com)",
305
+ placeholder: "company.ghe.com"
306
+ });
307
+ if (interaction.signal.aborted)
308
+ throw new Error("Login cancelled");
309
+ const trimmed = input.trim();
310
+ const enterpriseDomain = normalizeDomain(input);
311
+ if (trimmed && !enterpriseDomain)
312
+ throw new Error("Invalid GitHub Enterprise URL/domain");
313
+ const domain = enterpriseDomain || "github.com";
314
+ const device = await startDeviceFlow(domain, interaction.signal);
315
+ interaction.notify({
316
+ type: "device_code",
317
+ userCode: device.user_code,
318
+ verificationUri: device.verification_uri,
319
+ intervalSeconds: device.interval,
320
+ expiresInSeconds: device.expires_in
321
+ });
322
+ const githubAccessToken = await pollForGitHubAccessToken(domain, device, interaction.signal);
323
+ const credentials = await refreshGitHubCopilotAccessToken(githubAccessToken, enterpriseDomain ?? void 0, interaction.signal);
324
+ const models = await fetchGitHubCopilotModels(credentials.access, enterpriseDomain ?? void 0, interaction.signal, {
325
+ maxRetries: 2,
326
+ maxElapsedMs: 5e3
327
+ });
328
+ let enabledModelIds = [];
329
+ if (models.policyModelIds.length > 0) {
330
+ interaction.notify({ type: "progress", message: "Enabling models..." });
331
+ enabledModelIds = await enableGitHubCopilotModels(credentials.access, models.policyModelIds, enterpriseDomain ?? void 0, interaction.signal);
332
+ }
333
+ return {
334
+ ...credentials,
335
+ availableModelIds: [.../* @__PURE__ */ new Set([...models.availableModelIds, ...enabledModelIds])]
336
+ };
337
+ }
338
+ function copilotEnterpriseDomain(credential) {
339
+ const enterpriseUrl = credential.enterpriseUrl;
340
+ if (typeof enterpriseUrl !== "string" || !enterpriseUrl)
341
+ return void 0;
342
+ return normalizeDomain(enterpriseUrl) ?? void 0;
343
+ }
344
+ var githubCopilotOAuth = {
345
+ name: "GitHub Copilot",
346
+ isSubscription: true,
347
+ login: loginGitHubCopilot,
348
+ refresh: (credential, signal) => refreshGitHubCopilotToken(credential.refresh, copilotEnterpriseDomain(credential), signal),
349
+ /** Derive the credential-specific proxy endpoint for each request. */
350
+ async toAuth(credential) {
351
+ return {
352
+ apiKey: credential.access,
353
+ baseUrl: getGitHubCopilotBaseUrl(credential.access, copilotEnterpriseDomain(credential))
354
+ };
355
+ }
356
+ };
357
+ export {
358
+ githubCopilotOAuth
359
+ };