@nervekit/desktop 0.40.1 → 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 (109) hide show
  1. package/THIRD-PARTY-LICENSES.txt +7 -29
  2. package/dist/{chunk-KSZJ3HGD.js → chunk-2BKMOJYJ.js} +1 -1
  3. package/dist/{chunk-4MMJDHFX.js → chunk-3JJN36GV.js} +70 -71
  4. package/dist/{chunk-2Z5FLMLE.js → chunk-3SSNDIQT.js} +1 -1
  5. package/dist/{chunk-CKVFGRVV.js → chunk-3VZR3ZUY.js} +54 -7
  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-AJGPULMX.js → chunk-6FSDDGFZ.js} +815 -3108
  10. package/dist/chunk-6PACEIUY.js +183 -0
  11. package/dist/{chunk-XNYZEQ3U.js → chunk-6TAN6WG6.js} +1 -1
  12. package/dist/{chunk-55OGZFNA.js → chunk-7FLZA2BD.js} +31 -15
  13. package/dist/{chunk-XBHEYY65.js → chunk-7JQBECUL.js} +1 -1
  14. package/dist/{chunk-5Y3NEEOK.js → chunk-AAEIGAGD.js} +9 -9
  15. package/dist/{chunk-H5UKINTD.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-QWTKCUIZ.js → chunk-E4JNHQGT.js} +11 -9
  21. package/dist/chunk-ER2ES2RH.js +64 -0
  22. package/dist/{chunk-SQ7CWNIT.js → chunk-EX63VKXY.js} +1 -1
  23. package/dist/{chunk-KQPEOUCA.js → chunk-F3MHINI6.js} +19 -23
  24. package/dist/{chunk-KAZFF2RD.js → chunk-FGZX4Q7W.js} +137 -113
  25. package/dist/{chunk-I6NVW4NX.js → chunk-FZ5N6WXF.js} +29 -33
  26. package/dist/chunk-H2G55ZPG.js +783 -0
  27. package/dist/chunk-HDBDYGJQ.js +40 -0
  28. package/dist/{chunk-TJR6ASRW.js → chunk-HOCODVKL.js} +22 -24
  29. package/dist/chunk-K2J2VZXO.js +142 -0
  30. package/dist/{chunk-MH3SUHI2.js → chunk-KBNEZR7T.js} +2 -2
  31. package/dist/chunk-KSSM6LUI.js +340 -0
  32. package/dist/{chunk-QFXKQNMT.js → chunk-KTGSBL6T.js} +14 -17
  33. package/dist/chunk-L2DHKP5C.js +42 -0
  34. package/dist/{chunk-DBXMYYPJ.js → chunk-M3ELKCNA.js} +1 -1
  35. package/dist/{chunk-KIGB3FK6.js → chunk-MWIKZIAI.js} +9 -8
  36. package/dist/{chunk-AON37AL2.js → chunk-O2652RWY.js} +29 -4
  37. package/dist/chunk-O6U226AI.js +249 -0
  38. package/dist/{chunk-N5B2RRSS.js → chunk-OAEV22IW.js} +47 -26
  39. package/dist/chunk-OANTMDXI.js +29 -0
  40. package/dist/{chunk-UGDIHDAR.js → chunk-ODS5QROC.js} +1 -1
  41. package/dist/{chunk-TW6FURZ7.js → chunk-PST63OUS.js} +5 -5
  42. package/dist/{chunk-S2PITDVA.js → chunk-QBAIDKF6.js} +1 -1
  43. package/dist/chunk-RPLBWENJ.js +224 -0
  44. package/dist/{chunk-CWHAK2HX.js → chunk-S62LLS4I.js} +33 -55
  45. package/dist/chunk-SHEU5KLD.js +32 -0
  46. package/dist/{chunk-FESN7DND.js → chunk-SU2USXTD.js} +1 -1
  47. package/dist/chunk-T6NRMNLQ.js +22 -0
  48. package/dist/{chunk-WXRYBXYR.js → chunk-TGKIV3F4.js} +53 -65
  49. package/dist/{chunk-MN7PZ2PH.js → chunk-TSV3PFU2.js} +2 -2
  50. package/dist/{chunk-24GQ74HM.js → chunk-UDC7NPQJ.js} +3 -3
  51. package/dist/{chunk-CEX2GWGZ.js → chunk-VBM7TD3X.js} +1 -1
  52. package/dist/chunk-VC6TX2Y2.js +359 -0
  53. package/dist/{chunk-V53CETNZ.js → chunk-VTDI5KP7.js} +241 -104
  54. package/dist/{chunk-ONWQH2W6.js → chunk-WIN7KHMV.js} +15 -18
  55. package/dist/chunk-WJULIJOU.js +168 -0
  56. package/dist/{chunk-HKLAYK2Z.js → chunk-WRTA5G57.js} +23 -0
  57. package/dist/{chunk-FOFVPPPV.js → chunk-WYPVD3HW.js} +10 -9
  58. package/dist/{chunk-D7WIIZAV.js → chunk-XE2E2KBP.js} +10 -9
  59. package/dist/chunk-XY53EFK3.js +39 -0
  60. package/dist/chunk-XZYFB566.js +153 -0
  61. package/dist/{chunk-OY6PIAR7.js → chunk-YJT4NXMV.js} +5 -5
  62. package/dist/{chunk-3DGBM7UW.js → chunk-YQFENES6.js} +3 -3
  63. package/dist/chunk-YUO5V75X.js +128 -0
  64. package/dist/daemon.js +15 -10
  65. package/dist/git-isolated-reader-helper.js +1 -1
  66. package/dist/main.js +14 -9
  67. package/dist/web/assets/{AsyncBashCenterHost-HGsdxUJ3.js → AsyncBashCenterHost-BvXKoCVr.js} +1 -1
  68. package/dist/web/assets/{ConversationsWorkbenchPanel-B6dzWkG1.js → ConversationsWorkbenchPanel-CIfK_e3I.js} +1 -1
  69. package/dist/web/assets/{DiscoverCenterHost-B186WBRA.js → DiscoverCenterHost-Ep8EN9iJ.js} +1 -1
  70. package/dist/web/assets/{FileCenterHost-DigJOU5M.js → FileCenterHost-C_7XZAFZ.js} +1 -1
  71. package/dist/web/assets/{FilesWorkbenchPanel-VPvx3Bmi.js → FilesWorkbenchPanel-CtXo7ywG.js} +1 -1
  72. package/dist/web/assets/{GitDiffCenterHost-IuZfF3hG.js → GitDiffCenterHost-Cr7lqGI_.js} +1 -1
  73. package/dist/web/assets/{GitWorkbenchPanel-CScC0CfH.js → GitWorkbenchPanel-BFbwUgIN.js} +1 -1
  74. package/dist/web/assets/{LaunchConfigurationNotice-5yb4cH27.js → LaunchConfigurationNotice-CJjWkMhv.js} +1 -1
  75. package/dist/web/assets/{LaunchesWorkbenchPanel-Vy0Gm7gg.js → LaunchesWorkbenchPanel-BqzJvsrj.js} +1 -1
  76. package/dist/web/assets/{LogsCenterHost-BXBozCYw.js → LogsCenterHost-BI1fSxFW.js} +1 -1
  77. package/dist/web/assets/{MermaidCenterHost-DDh4ArdK.js → MermaidCenterHost-DVsZB8nB.js} +1 -1
  78. package/dist/web/assets/{MobileFilesBody-Cda_7gDp.js → MobileFilesBody-BJMoaP9I.js} +1 -1
  79. package/dist/web/assets/{MobileFilesHost-C1jev2Un.js → MobileFilesHost-D843vkDF.js} +1 -1
  80. package/dist/web/assets/{MobileLaunchOutputHost-Bsv12o2H.js → MobileLaunchOutputHost-vpltMcar.js} +1 -1
  81. package/dist/web/assets/{MobileLaunchesHost-C9VH-2bn.js → MobileLaunchesHost-CdDrKASg.js} +1 -1
  82. package/dist/web/assets/{MobileLogsHost-BMDXc-WC.js → MobileLogsHost-qK7N-C1y.js} +1 -1
  83. package/dist/web/assets/{MobileNoteEditorHost-BA6WIY1Y.js → MobileNoteEditorHost-Bg1N8o54.js} +1 -1
  84. package/dist/web/assets/{MobileNotesHost-BZeYpK9H.js → MobileNotesHost-meLV39Yw.js} +1 -1
  85. package/dist/web/assets/{MobileProjectSettingsHost-U3Mx3EN8.js → MobileProjectSettingsHost-A49Fdn54.js} +1 -1
  86. package/dist/web/assets/{MobileProjectSettingsPageHost-CMvxbjfs.js → MobileProjectSettingsPageHost-BXpUqS_N.js} +1 -1
  87. package/dist/web/assets/{MobileSettingsHost-CP8Z_-gH.js → MobileSettingsHost-DPKPajzI.js} +1 -1
  88. package/dist/web/assets/{MobileSettingsPageHost-BPjXKTMV.js → MobileSettingsPageHost-izNWGN0i.js} +1 -1
  89. package/dist/web/assets/{MobileSettingsPageScreen-C5rHdrUU.js → MobileSettingsPageScreen-DWMg4fDo.js} +1 -1
  90. package/dist/web/assets/{ProjectSettingsCenterHost-BVXpBixy.js → ProjectSettingsCenterHost-DHeb274m.js} +1 -1
  91. package/dist/web/assets/{PullRequestCenterHost-CZhXfCX2.js → PullRequestCenterHost-BYkWxXQe.js} +1 -1
  92. package/dist/web/assets/{PullRequestsWorkbenchPanel-BBnZJVnI.js → PullRequestsWorkbenchPanel-ZvGbi1Cr.js} +1 -1
  93. package/dist/web/assets/{SearchWorkbenchPanel-qLgszneN.js → SearchWorkbenchPanel-DaC0smfe.js} +1 -1
  94. package/dist/web/assets/{SettingsCenter-7BfrBfiy.js → SettingsCenter-C_NLBsi6.js} +1 -1
  95. package/dist/web/assets/{SettingsCenterHost-Ck5uHILP.js → SettingsCenterHost-jP8MULEj.js} +1 -1
  96. package/dist/web/assets/{SystemPromptCenterHost-ya5AvXsd.js → SystemPromptCenterHost-B1hfsfAn.js} +1 -1
  97. package/dist/web/assets/{discover-B3I5g1_G.js → discover-B-aZ504j.js} +1 -1
  98. package/dist/web/assets/{index-FJEmK_L5.js → index-TZ1KAAsX.js} +34 -34
  99. package/dist/web/assets/{settings-page-controllers.svelte-CU0i08wo.js → settings-page-controllers.svelte-D_ydJF8u.js} +1 -1
  100. package/dist/web/assets/{shell-layout.svelte-BT2508sa.js → shell-layout.svelte-OoLFwzzJ.js} +2 -2
  101. package/dist/web/assets/{views-Z-n-GTYY.js → views-ByPCKDiZ.js} +1 -1
  102. package/dist/web/index.html +3 -3
  103. package/dist/web/sw.js +1 -1
  104. package/dist/worker.js +14 -9
  105. package/package.json +8 -9
  106. package/dist/chunk-RUZ2UAYH.js +0 -365
  107. package/dist/resize-worker.js +0 -168
  108. /package/dist/{chunk-CKVFGRVV.js.LEGAL.txt → chunk-3VZR3ZUY.js.LEGAL.txt} +0 -0
  109. /package/dist/{chunk-TW6FURZ7.js.LEGAL.txt → chunk-PST63OUS.js.LEGAL.txt} +0 -0
@@ -0,0 +1,250 @@
1
+ import { createRequire as __nerveCreateRequire } from "node:module";
2
+ const require = __nerveCreateRequire(import.meta.url);
3
+ import {
4
+ generatePKCE,
5
+ oauthErrorHtml,
6
+ oauthSuccessHtml
7
+ } from "./chunk-YUO5V75X.js";
8
+ import {
9
+ getProviderEnvValue
10
+ } from "./chunk-SU2USXTD.js";
11
+ import "./chunk-CWESUMYQ.js";
12
+
13
+ // 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/openai-chatgpt.js
14
+ import { randomBytes } from "node:crypto";
15
+ import { createServer } from "node:http";
16
+ var DYNAMIC_CLIENT_ID = "dynamic_agent_client";
17
+ var AGENT_NAME_HINT = "Pi";
18
+ var UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
19
+ var AUTHORIZE_URL = "https://auth.openai.com/api/accounts/authorize";
20
+ var TOKEN_URL = "https://auth.openai.com/api/accounts/oauth/token";
21
+ var RESOURCE = "https://api.openai.com/v1";
22
+ var CALLBACK_HOST = getProviderEnvValue("PI_OAUTH_CALLBACK_HOST") || "127.0.0.1";
23
+ var CALLBACK_PORT = 1455;
24
+ var CALLBACK_PATH = "/auth/callback";
25
+ var REDIRECT_URI = `http://127.0.0.1:${CALLBACK_PORT}${CALLBACK_PATH}`;
26
+ var DIRECT_TOKEN_SCOPE = "chatgpt.tokens.use.direct";
27
+ var SCOPE = `openid profile email offline_access resource.invoke ${DIRECT_TOKEN_SCOPE}`;
28
+ var EXPIRY_MARGIN_MS = 3 * 60 * 1e3;
29
+ function randomValue() {
30
+ return randomBytes(32).toString("base64url");
31
+ }
32
+ function authorizationResultFromCallback(url, expectedState) {
33
+ const code = url.searchParams.get("code");
34
+ if (!code)
35
+ throw new Error("Missing authorization code");
36
+ const state = url.searchParams.get("state");
37
+ if (!state)
38
+ throw new Error("Missing OAuth state");
39
+ if (state !== expectedState)
40
+ throw new Error("OAuth state mismatch");
41
+ const clientId = url.searchParams.get("client_id")?.trim();
42
+ if (!clientId)
43
+ throw new Error("OpenAI OAuth registration callback did not contain an issued client ID");
44
+ return { code, clientId };
45
+ }
46
+ function authorizationResultFromManualInput(input, expectedState) {
47
+ let url;
48
+ try {
49
+ url = new URL(input.trim());
50
+ } catch {
51
+ throw new Error("Paste the full callback URL from the browser");
52
+ }
53
+ const expected = new URL(REDIRECT_URI);
54
+ if (url.origin !== expected.origin || url.pathname !== expected.pathname) {
55
+ throw new Error(`The pasted callback URL must start with ${REDIRECT_URI}`);
56
+ }
57
+ const error = url.searchParams.get("error");
58
+ if (error)
59
+ throw new Error(`ChatGPT authorization failed: ${error}`);
60
+ return authorizationResultFromCallback(url, expectedState);
61
+ }
62
+ function sendHtml(response, status, body) {
63
+ response.writeHead(status, { "Content-Type": "text/html; charset=utf-8" });
64
+ response.end(body);
65
+ }
66
+ function startCallbackServer(expectedState) {
67
+ return new Promise((resolve, reject) => {
68
+ let resolveResult;
69
+ let rejectResult;
70
+ const result = new Promise((resolveAuthorization, rejectAuthorization) => {
71
+ resolveResult = resolveAuthorization;
72
+ rejectResult = rejectAuthorization;
73
+ });
74
+ const server = createServer((request, response) => {
75
+ try {
76
+ const url = new URL(request.url || "", REDIRECT_URI);
77
+ if (url.pathname !== CALLBACK_PATH) {
78
+ sendHtml(response, 404, oauthErrorHtml("Callback route not found."));
79
+ return;
80
+ }
81
+ const error = url.searchParams.get("error");
82
+ if (error) {
83
+ sendHtml(response, 400, oauthErrorHtml("ChatGPT was not connected.", `Error: ${error}`));
84
+ rejectResult(new Error(`ChatGPT authorization failed: ${error}`));
85
+ return;
86
+ }
87
+ let authorizationResult;
88
+ try {
89
+ authorizationResult = authorizationResultFromCallback(url, expectedState);
90
+ } catch (error2) {
91
+ const message = error2 instanceof Error ? error2.message : "Invalid callback";
92
+ sendHtml(response, 400, oauthErrorHtml(message));
93
+ return;
94
+ }
95
+ sendHtml(response, 200, oauthSuccessHtml("ChatGPT authentication completed. You can close this window."));
96
+ resolveResult(authorizationResult);
97
+ } catch {
98
+ sendHtml(response, 500, oauthErrorHtml("Internal error while processing the callback."));
99
+ }
100
+ });
101
+ server.once("error", reject);
102
+ server.listen(CALLBACK_PORT, CALLBACK_HOST, () => {
103
+ server.removeListener("error", reject);
104
+ server.on("error", rejectResult);
105
+ resolve({ server, result });
106
+ });
107
+ });
108
+ }
109
+ async function requestToken(body, signal) {
110
+ const response = await fetch(TOKEN_URL, {
111
+ method: "POST",
112
+ headers: {
113
+ accept: "application/json",
114
+ "content-type": "application/x-www-form-urlencoded"
115
+ },
116
+ body,
117
+ signal
118
+ });
119
+ if (!response.ok) {
120
+ const responseBody = await response.text().catch(() => "");
121
+ throw new Error(`OpenAI OAuth token request failed (${response.status}): ${responseBody || response.statusText}`);
122
+ }
123
+ const data = await response.json();
124
+ if (typeof data !== "object" || data === null || Array.isArray(data)) {
125
+ throw new Error("OpenAI OAuth token response must be an object");
126
+ }
127
+ return data;
128
+ }
129
+ function requireTokenString(value, field) {
130
+ if (typeof value !== "string" || value.trim().length === 0) {
131
+ throw new Error(`OpenAI OAuth token response has invalid ${field}`);
132
+ }
133
+ return value;
134
+ }
135
+ function credentialFromTokenResponse(token, clientId) {
136
+ const access = requireTokenString(token.access_token, "access_token");
137
+ const refresh = requireTokenString(token.refresh_token, "refresh_token");
138
+ const scope = requireTokenString(token.scope, "scope");
139
+ if (typeof token.expires_in !== "number" || !Number.isFinite(token.expires_in) || token.expires_in <= 0) {
140
+ throw new Error("OpenAI OAuth token response has invalid expires_in");
141
+ }
142
+ const scopes = scope.trim().split(/\s+/).filter(Boolean);
143
+ if (!scopes.includes(DIRECT_TOKEN_SCOPE)) {
144
+ throw new Error(`OpenAI OAuth grant did not include ${DIRECT_TOKEN_SCOPE}`);
145
+ }
146
+ return {
147
+ type: "oauth",
148
+ access,
149
+ refresh,
150
+ expires: Date.now() + token.expires_in * 1e3 - EXPIRY_MARGIN_MS,
151
+ clientId,
152
+ scopes
153
+ };
154
+ }
155
+ async function exchangeAuthorizationCode(code, verifier, clientId, signal) {
156
+ const token = await requestToken(new URLSearchParams({
157
+ grant_type: "authorization_code",
158
+ client_id: clientId,
159
+ code,
160
+ code_verifier: verifier,
161
+ redirect_uri: REDIRECT_URI,
162
+ resource: RESOURCE
163
+ }), signal);
164
+ if (typeof token.id_token !== "string" || token.id_token.trim().length === 0) {
165
+ throw new Error("OpenAI OAuth token response did not contain an ID token");
166
+ }
167
+ return credentialFromTokenResponse(token, clientId);
168
+ }
169
+ async function refreshAccessToken(credential, signal) {
170
+ const clientId = credential.clientId;
171
+ if (typeof clientId !== "string" || clientId.trim().length === 0) {
172
+ throw new Error("Stored OpenAI OAuth credential does not contain an issued client ID; reconnect ChatGPT");
173
+ }
174
+ const token = await requestToken(new URLSearchParams({
175
+ grant_type: "refresh_token",
176
+ client_id: clientId,
177
+ refresh_token: credential.refresh,
178
+ resource: RESOURCE
179
+ }), signal);
180
+ return credentialFromTokenResponse(token, clientId);
181
+ }
182
+ function agentHostId(deviceId) {
183
+ if (!deviceId || !UUID_PATTERN.test(deviceId)) {
184
+ throw new Error("Sign in with ChatGPT requires a device ID (UUID) for this installation");
185
+ }
186
+ return `urn:uuid:${deviceId.toLowerCase()}`;
187
+ }
188
+ async function loginOpenAIChatGPT(interaction, options) {
189
+ const hostId = agentHostId(options?.getDeviceId?.());
190
+ const { verifier, challenge } = await generatePKCE();
191
+ const state = randomValue();
192
+ const nonce = randomValue();
193
+ const callback = await startCallbackServer(state).catch((error) => {
194
+ if (!(error instanceof Error && "code" in error && error.code === "EADDRINUSE"))
195
+ throw error;
196
+ throw new Error(`Port ${CALLBACK_PORT} is in use, probably by an unfinished login in another pi session or by the Codex CLI. Cancel that login and try again.`);
197
+ });
198
+ const authorizationUrl = new URL(AUTHORIZE_URL);
199
+ authorizationUrl.search = new URLSearchParams({
200
+ client_id: DYNAMIC_CLIENT_ID,
201
+ agent_name_hint: options?.agentName ?? AGENT_NAME_HINT,
202
+ ext_agent_host_id: hostId,
203
+ response_type: "code",
204
+ redirect_uri: REDIRECT_URI,
205
+ resource: RESOURCE,
206
+ scope: SCOPE,
207
+ state,
208
+ code_challenge: challenge,
209
+ code_challenge_method: "S256",
210
+ nonce
211
+ }).toString();
212
+ interaction.notify({
213
+ type: "auth_url",
214
+ url: authorizationUrl.toString(),
215
+ instructions: "Complete sign-in in your browser. If the callback does not complete, paste the final redirect URL here."
216
+ });
217
+ const manualAbort = new AbortController();
218
+ const manualCode = interaction.prompt({
219
+ type: "manual_code",
220
+ message: "Complete login in your browser, or paste the final redirect URL here:",
221
+ placeholder: REDIRECT_URI,
222
+ signal: AbortSignal.any([manualAbort.signal, interaction.signal])
223
+ }).then((input) => authorizationResultFromManualInput(input, state));
224
+ try {
225
+ const result = await Promise.race([callback.result, manualCode]);
226
+ interaction.notify({ type: "progress", message: "Exchanging authorization code for tokens..." });
227
+ return await exchangeAuthorizationCode(result.code, verifier, result.clientId, interaction.signal);
228
+ } catch (error) {
229
+ if (interaction.signal.aborted)
230
+ throw new Error("Login cancelled");
231
+ throw error;
232
+ } finally {
233
+ manualAbort.abort();
234
+ callback.server.close();
235
+ callback.server.closeAllConnections();
236
+ }
237
+ }
238
+ var openaiChatGPTOAuth = {
239
+ name: "OpenAI (ChatGPT subscription)",
240
+ isSubscription: true,
241
+ loginLabel: "Sign in with ChatGPT",
242
+ login: loginOpenAIChatGPT,
243
+ refresh: refreshAccessToken,
244
+ async toAuth(credential) {
245
+ return { apiKey: credential.access };
246
+ }
247
+ };
248
+ export {
249
+ openaiChatGPTOAuth
250
+ };
@@ -5,24 +5,25 @@ import {
5
5
  } from "./chunk-NW3DH7IK.js";
6
6
  import {
7
7
  sanitizeSurrogates
8
- } from "./chunk-2Z5FLMLE.js";
8
+ } from "./chunk-3SSNDIQT.js";
9
+ import {
10
+ retryProviderRequest
11
+ } from "./chunk-EX63VKXY.js";
9
12
  import {
10
13
  formatProviderError,
11
14
  normalizeProviderError
12
- } from "./chunk-AON37AL2.js";
13
- import {
14
- retryProviderRequest
15
- } from "./chunk-SQ7CWNIT.js";
15
+ } from "./chunk-O2652RWY.js";
16
16
  import {
17
17
  headersToRecord,
18
18
  providerHeadersToRecord
19
- } from "./chunk-CEX2GWGZ.js";
19
+ } from "./chunk-VBM7TD3X.js";
20
20
  import {
21
21
  getIdentityHeaders
22
- } from "./chunk-24GQ74HM.js";
22
+ } from "./chunk-UDC7NPQJ.js";
23
+ import "./chunk-XY53EFK3.js";
23
24
  import "./chunk-CWESUMYQ.js";
24
25
 
25
- // node_modules/.pnpm/@earendil-works+pi-ai@1.4.0_@aws-sdk+credential-provider-node@3.972.83_@smithy+signatur_c4dd529f1cf5cdf12d9a6e2070ccac62/node_modules/@earendil-works/pi-ai/dist/api/openrouter-images.js
26
+ // 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/api/openrouter-images.js
26
27
  var generateImages = async (model, context, options) => {
27
28
  const output = {
28
29
  api: model.api,
@@ -140,7 +141,8 @@ function parseUsage(rawUsage, model) {
140
141
  output: model.cost.output / 1e6 * output,
141
142
  cacheRead: model.cost.cacheRead / 1e6 * cacheReadTokens,
142
143
  cacheWrite: model.cost.cacheWrite / 1e6 * cacheWriteTokens,
143
- total: 0
144
+ total: 0,
145
+ totalFromProvider: false
144
146
  }
145
147
  };
146
148
  usage.cost.total = usage.cost.input + usage.cost.output + usage.cost.cacheRead + usage.cost.cacheWrite;
@@ -0,0 +1,64 @@
1
+ import { createRequire as __nerveCreateRequire } from "node:module";
2
+ const require = __nerveCreateRequire(import.meta.url);
3
+
4
+ // 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/device-code.js
5
+ var CANCEL_MESSAGE = "Login cancelled";
6
+ var TIMEOUT_MESSAGE = "Device flow timed out";
7
+ var SLOW_DOWN_TIMEOUT_MESSAGE = "Device flow timed out after one or more slow_down responses. This is often caused by clock drift in WSL or VM environments. Please sync or restart the VM clock and try again.";
8
+ var MINIMUM_INTERVAL_MS = 1e3;
9
+ var DEFAULT_POLL_INTERVAL_SECONDS = 5;
10
+ var SLOW_DOWN_INTERVAL_INCREMENT_MS = 5e3;
11
+ function abortableSleep(ms, signal, cancelMessage) {
12
+ return new Promise((resolve, reject) => {
13
+ if (signal.aborted) {
14
+ reject(new Error(cancelMessage));
15
+ return;
16
+ }
17
+ const onAbort = () => {
18
+ clearTimeout(timeout);
19
+ reject(new Error(cancelMessage));
20
+ };
21
+ const timeout = setTimeout(() => {
22
+ signal.removeEventListener("abort", onAbort);
23
+ resolve();
24
+ }, ms);
25
+ signal.addEventListener("abort", onAbort, { once: true });
26
+ });
27
+ }
28
+ async function pollOAuthDeviceCodeFlow(options) {
29
+ const deadline = typeof options.expiresInSeconds === "number" ? Date.now() + options.expiresInSeconds * 1e3 : Number.POSITIVE_INFINITY;
30
+ let intervalMs = Math.max(MINIMUM_INTERVAL_MS, Math.floor((options.intervalSeconds ?? DEFAULT_POLL_INTERVAL_SECONDS) * 1e3));
31
+ let slowDownResponses = 0;
32
+ if (options.waitBeforeFirstPoll) {
33
+ const remainingMs = deadline - Date.now();
34
+ if (remainingMs > 0) {
35
+ await abortableSleep(Math.min(intervalMs, remainingMs), options.signal, CANCEL_MESSAGE);
36
+ }
37
+ }
38
+ while (Date.now() < deadline) {
39
+ if (options.signal.aborted) {
40
+ throw new Error(CANCEL_MESSAGE);
41
+ }
42
+ const result = await options.poll();
43
+ if (result.status === "complete") {
44
+ return result.value;
45
+ }
46
+ if (result.status === "failed") {
47
+ throw new Error(result.message);
48
+ }
49
+ if (result.status === "slow_down") {
50
+ slowDownResponses += 1;
51
+ intervalMs = typeof result.intervalSeconds === "number" && Number.isFinite(result.intervalSeconds) && result.intervalSeconds > 0 ? Math.max(MINIMUM_INTERVAL_MS, Math.floor(result.intervalSeconds * 1e3)) : Math.max(MINIMUM_INTERVAL_MS, intervalMs + SLOW_DOWN_INTERVAL_INCREMENT_MS);
52
+ }
53
+ const remainingMs = deadline - Date.now();
54
+ if (remainingMs <= 0) {
55
+ break;
56
+ }
57
+ await abortableSleep(Math.min(intervalMs, remainingMs), options.signal, CANCEL_MESSAGE);
58
+ }
59
+ throw new Error(slowDownResponses > 0 ? SLOW_DOWN_TIMEOUT_MESSAGE : TIMEOUT_MESSAGE);
60
+ }
61
+
62
+ export {
63
+ pollOAuthDeviceCodeFlow
64
+ };
@@ -1,7 +1,7 @@
1
1
  import { createRequire as __nerveCreateRequire } from "node:module";
2
2
  const require = __nerveCreateRequire(import.meta.url);
3
3
 
4
- // node_modules/.pnpm/@earendil-works+pi-ai@1.4.0_@aws-sdk+credential-provider-node@3.972.83_@smithy+signatur_c4dd529f1cf5cdf12d9a6e2070ccac62/node_modules/@earendil-works/pi-ai/dist/utils/provider-retry.js
4
+ // 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/utils/provider-retry.js
5
5
  var DEFAULT_MAX_RETRY_DELAY_MS = 6e4;
6
6
  function isProviderError(error) {
7
7
  if (!(error instanceof Error) || !("status" in error) || !("headers" in error))
@@ -5,51 +5,52 @@ import {
5
5
  convertResponsesTools,
6
6
  getResponsesToolSupport,
7
7
  processResponsesStream
8
- } from "./chunk-H5UKINTD.js";
8
+ } from "./chunk-ANI6J75M.js";
9
9
  import {
10
10
  resolveAzureConfig,
11
11
  resolveDeploymentName
12
- } from "./chunk-L3YB2QLN.js";
12
+ } from "./chunk-C6RO4LP3.js";
13
13
  import {
14
14
  clampOpenAIPromptCacheKey
15
- } from "./chunk-UGDIHDAR.js";
16
- import "./chunk-KSZJ3HGD.js";
15
+ } from "./chunk-ODS5QROC.js";
17
16
  import {
18
17
  AzureOpenAI
19
18
  } from "./chunk-NW3DH7IK.js";
20
- import "./chunk-RUZ2UAYH.js";
19
+ import "./chunk-2BKMOJYJ.js";
21
20
  import {
22
21
  buildBaseOptions,
23
22
  createGrammarToolInputProperties,
24
23
  resolveSamplingParams
25
- } from "./chunk-N5B2RRSS.js";
26
- import "./chunk-2Z5FLMLE.js";
24
+ } from "./chunk-OAEV22IW.js";
25
+ import "./chunk-3SSNDIQT.js";
26
+ import {
27
+ retryProviderRequest
28
+ } from "./chunk-EX63VKXY.js";
27
29
  import {
28
30
  formatProviderError,
29
31
  normalizeProviderError
30
- } from "./chunk-AON37AL2.js";
31
- import {
32
- retryProviderRequest
33
- } from "./chunk-SQ7CWNIT.js";
32
+ } from "./chunk-O2652RWY.js";
34
33
  import {
35
34
  headersToRecord
36
- } from "./chunk-CEX2GWGZ.js";
37
- import "./chunk-FESN7DND.js";
35
+ } from "./chunk-VBM7TD3X.js";
36
+ import "./chunk-SU2USXTD.js";
37
+ import "./chunk-H2G55ZPG.js";
38
38
  import {
39
39
  clampThinkingLevel,
40
40
  getDeclaredTools,
41
41
  resolveTranscript,
42
42
  resolveTranscriptTools
43
- } from "./chunk-WXRYBXYR.js";
43
+ } from "./chunk-TGKIV3F4.js";
44
44
  import {
45
45
  AssistantMessageEventStream
46
- } from "./chunk-MN7PZ2PH.js";
46
+ } from "./chunk-TSV3PFU2.js";
47
47
  import {
48
48
  getIdentityHeaders
49
- } from "./chunk-24GQ74HM.js";
49
+ } from "./chunk-UDC7NPQJ.js";
50
+ import "./chunk-XY53EFK3.js";
50
51
  import "./chunk-CWESUMYQ.js";
51
52
 
52
- // node_modules/.pnpm/@earendil-works+pi-ai@1.4.0_@aws-sdk+credential-provider-node@3.972.83_@smithy+signatur_c4dd529f1cf5cdf12d9a6e2070ccac62/node_modules/@earendil-works/pi-ai/dist/api/azure-openai-responses.js
53
+ // 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/api/azure-openai-responses.js
53
54
  var AZURE_TOOL_CALL_PROVIDERS = /* @__PURE__ */ new Set(["openai", "openai-codex", "opencode", "azure"]);
54
55
  var OPENAI_RESPONSES_MIN_OUTPUT_TOKENS = 16;
55
56
  function formatAzureOpenAIError(error) {
@@ -117,11 +118,6 @@ var stream = (model, context, options) => {
117
118
  stream2.push({ type: "done", reason: output.stopReason, message: output });
118
119
  stream2.end();
119
120
  } catch (error) {
120
- for (const block of output.content) {
121
- delete block.index;
122
- delete block.partialJson;
123
- delete block.customInput;
124
- }
125
121
  output.stopReason = options?.signal?.aborted ? "aborted" : "error";
126
122
  output.errorMessage = formatAzureOpenAIError(error);
127
123
  stream2.push({ type: "error", reason: output.stopReason, error: output });
@@ -183,7 +179,7 @@ function buildParams(model, context, options, deploymentName, grammarToolInputPr
183
179
  model: deploymentName,
184
180
  input: messages,
185
181
  stream: true,
186
- prompt_cache_key: clampOpenAIPromptCacheKey(options?.sessionId),
182
+ prompt_cache_key: model.compat?.promptCacheKeyMode === "disabled" ? void 0 : clampOpenAIPromptCacheKey(options?.sessionId),
187
183
  store: false
188
184
  };
189
185
  if (options?.maxTokens) {