@wirecat/drive-cli 0.60.0 → 0.61.0

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 (162) hide show
  1. package/README.md +4 -5
  2. package/dist/bin/drive.js +2 -2
  3. package/dist/bundle/{all-profiles-537I27Z4.js → all-profiles-H4L3Z5UM.js} +14 -14
  4. package/dist/bundle/{anthropic-X4NWVHDF.js → anthropic-PPGFISVP.js} +9 -9
  5. package/dist/bundle/{app-server-KSHJKKS7.js → app-server-YXVK2FUZ.js} +52 -52
  6. package/dist/bundle/{bun-WTBGGCUC.js → bun-DKZAL6ML.js} +2 -2
  7. package/dist/bundle/{bun-sqlite-T7Y3JFFD.js → bun-sqlite-MTZY36QK.js} +8 -8
  8. package/dist/bundle/{chunk-VRW6ZDTH.js → chunk-2RJA4BQB.js} +19 -19
  9. package/dist/bundle/{chunk-VVCZS42A.js → chunk-3252WXOL.js} +1 -1
  10. package/dist/bundle/{chunk-3TQHIHZI.js → chunk-36CWGEVX.js} +2 -2
  11. package/dist/bundle/{chunk-AXWXQNTC.js → chunk-3I2D5TK2.js} +10 -10
  12. package/dist/bundle/{chunk-PDYHEWKG.js → chunk-3SJQNS72.js} +5 -5
  13. package/dist/bundle/{chunk-PPL5ASW2.js → chunk-3UPIJ7DW.js} +280 -280
  14. package/dist/bundle/{chunk-PETFPXLU.js → chunk-3WZH3WV3.js} +3 -3
  15. package/dist/bundle/{chunk-5XHLQZAG.js → chunk-5W56YMQS.js} +25 -25
  16. package/dist/bundle/{chunk-IXN7Y6JA.js → chunk-5W7D5H2R.js} +1 -1
  17. package/dist/bundle/{chunk-FZOCQQ66.js → chunk-67HS46KM.js} +12 -12
  18. package/dist/bundle/{chunk-HFGR33KD.js → chunk-6DN4VPA7.js} +25 -25
  19. package/dist/bundle/{chunk-HIP43OGZ.js → chunk-6IBM4Z3V.js} +1 -1
  20. package/dist/bundle/{chunk-V7QMHMR3.js → chunk-6SUGANRJ.js} +6 -6
  21. package/dist/bundle/{chunk-LQSRVQ3V.js → chunk-6Y2FWJZ4.js} +3 -3
  22. package/dist/bundle/{chunk-GVRS5AIH.js → chunk-73WSULMI.js} +2 -2
  23. package/dist/bundle/{chunk-ZPQS7XJA.js → chunk-AM4RIWOZ.js} +4 -4
  24. package/dist/bundle/{chunk-HCJG7ENG.js → chunk-AWN22PJK.js} +3 -3
  25. package/dist/bundle/{chunk-YDN2RH5S.js → chunk-BCWUDTYQ.js} +2 -2
  26. package/dist/bundle/{chunk-GD6TQ6U4.js → chunk-BF6TQMNB.js} +8 -8
  27. package/dist/bundle/chunk-BQMIDYBA.js +415 -0
  28. package/dist/bundle/{chunk-JQLIM6BH.js → chunk-BXR7BKM3.js} +1 -1
  29. package/dist/bundle/{chunk-MVNPE5FZ.js → chunk-CACYL36O.js} +8 -8
  30. package/dist/bundle/{chunk-246P2DCT.js → chunk-DCBFNBEB.js} +113 -51
  31. package/dist/bundle/{chunk-TXMTMEHW.js → chunk-DEPMQHXQ.js} +4 -4
  32. package/dist/bundle/{chunk-O37ESNAP.js → chunk-DXPOVLQC.js} +46 -28
  33. package/dist/bundle/{chunk-CKGHRWVR.js → chunk-E5EXJ2XS.js} +4 -4
  34. package/dist/bundle/{chunk-4CBZEAQ7.js → chunk-E6J5YH2N.js} +34 -34
  35. package/dist/bundle/{chunk-4XZXH2NM.js → chunk-ECEYAQGN.js} +2 -2
  36. package/dist/bundle/{chunk-XDIEQ2CE.js → chunk-EPCJUL6M.js} +3 -3
  37. package/dist/bundle/{chunk-EHAI773E.js → chunk-FE5JJXKA.js} +2 -2
  38. package/dist/bundle/{chunk-DQDKLZAK.js → chunk-HFM653T3.js} +49 -49
  39. package/dist/bundle/{chunk-UVYVIHEA.js → chunk-HGOYQUT7.js} +1 -1
  40. package/dist/bundle/{chunk-KEXTTZJM.js → chunk-I26VL4W7.js} +2 -2
  41. package/dist/bundle/{chunk-LJ77Y3TK.js → chunk-J4HQVHMN.js} +6 -5
  42. package/dist/bundle/{chunk-YGG7UA3C.js → chunk-J5UDQD5S.js} +5 -5
  43. package/dist/bundle/{chunk-73TTP6ET.js → chunk-JVBLXSAA.js} +141 -141
  44. package/dist/bundle/{chunk-N7S2UPF3.js → chunk-K7LS3NGM.js} +55 -55
  45. package/dist/bundle/{chunk-2AXA5SKP.js → chunk-KV4267S4.js} +1 -1
  46. package/dist/bundle/{chunk-IRZ7OF3F.js → chunk-LARQTWIL.js} +1 -1
  47. package/dist/bundle/{chunk-QIJWSKZL.js → chunk-N2RLJTIW.js} +4 -4
  48. package/dist/bundle/{chunk-HQVIK6PM.js → chunk-NIX2MWHZ.js} +242 -362
  49. package/dist/bundle/{chunk-4VHBDVY2.js → chunk-NZ2EIZLX.js} +14 -10
  50. package/dist/bundle/{chunk-SZXI4OXX.js → chunk-O5CUFS7T.js} +2 -2
  51. package/dist/bundle/{chunk-FO4TCH6P.js → chunk-OFFA54TW.js} +2 -2
  52. package/dist/bundle/{chunk-W62CON5K.js → chunk-OGNOQDWB.js} +4 -4
  53. package/dist/bundle/{chunk-OYNUBWD2.js → chunk-OLPJRD4S.js} +1 -1
  54. package/dist/bundle/{chunk-67QXMO2G.js → chunk-PJTX2MOI.js} +26 -26
  55. package/dist/bundle/{chunk-MXP35VPO.js → chunk-PY7LKNOS.js} +2 -2
  56. package/dist/bundle/{chunk-FTZNUZO7.js → chunk-Q4XVBKX4.js} +3 -3
  57. package/dist/bundle/{chunk-5AMRCBMP.js → chunk-QR5VQXQ5.js} +26 -26
  58. package/dist/bundle/{chunk-S36HRPNS.js → chunk-QSGT4ZH4.js} +1 -1
  59. package/dist/bundle/{chunk-57QVQGBE.js → chunk-RFRCOAWS.js} +22 -22
  60. package/dist/bundle/{chunk-DMHGWL5D.js → chunk-S4YK6TTG.js} +13 -13
  61. package/dist/bundle/{chunk-UVLSWLPZ.js → chunk-TKGAYKXW.js} +16 -16
  62. package/dist/bundle/{chunk-SBHSNOU4.js → chunk-UKOYQC5O.js} +19 -18
  63. package/dist/bundle/{chunk-XFXRGQXJ.js → chunk-UO2IUDVK.js} +2 -2
  64. package/dist/bundle/{chunk-UTFATA4K.js → chunk-VPDAH7PJ.js} +1 -1
  65. package/dist/bundle/{chunk-TKW4QWCY.js → chunk-VYXVPYA3.js} +12 -6
  66. package/dist/bundle/{chunk-YYHKVOVK.js → chunk-W767AUNR.js} +4 -4
  67. package/dist/bundle/{chunk-73MNUSP3.js → chunk-WIU733D2.js} +1 -1
  68. package/dist/bundle/{chunk-UNJE63JK.js → chunk-WUP2MJDN.js} +2 -2
  69. package/dist/bundle/{chunk-EBLA7GXY.js → chunk-WZ5XK74U.js} +2 -1
  70. package/dist/bundle/{chunk-77C5XRH3.js → chunk-X2CXW4HM.js} +7 -7
  71. package/dist/bundle/{chunk-D6WIWOQC.js → chunk-XGMDWIUP.js} +4 -4
  72. package/dist/bundle/{chunk-K6XVRA6U.js → chunk-XGNC5OJG.js} +1 -1
  73. package/dist/bundle/{chunk-ALWTUDZF.js → chunk-XLFJLZJL.js} +4 -4
  74. package/dist/bundle/{chunk-JGUJJNGZ.js → chunk-XYCCGGKN.js} +242 -242
  75. package/dist/bundle/{chunk-TVQDMP2F.js → chunk-XZBR2O63.js} +271 -271
  76. package/dist/bundle/{chunk-OMKUBCNN.js → chunk-YMBFZA3H.js} +8 -8
  77. package/dist/bundle/{chunk-ZYCLPJ7U.js → chunk-YPF6OS37.js} +1 -1
  78. package/dist/bundle/{chunk-6HTKB4WC.js → chunk-YWIU4HOT.js} +1 -1
  79. package/dist/bundle/{chunk-V2VMBM7O.js → chunk-ZHYRHERD.js} +2 -2
  80. package/dist/bundle/{chunk-22ATLSNK.js → chunk-ZMNYK3FC.js} +5 -5
  81. package/dist/bundle/command-contract-T3EO5AYD.js +39 -0
  82. package/dist/bundle/{decode-35N57AFW.js → decode-62A3HGPW.js} +8 -8
  83. package/dist/bundle/{dispatch-CWXZW3PL.js → dispatch-IE7PBEQC.js} +9 -9
  84. package/dist/bundle/drive.js +11 -11
  85. package/dist/bundle/{echarts-3P3QZWMU.js → echarts-BGBPRGR5.js} +2 -2
  86. package/dist/bundle/{embed-Q6Q5IOJQ.js → embed-J3IBVV2V.js} +9 -9
  87. package/dist/bundle/{embedder-D44JDTAA.js → embedder-QFPMDRT2.js} +12 -12
  88. package/dist/bundle/entry-YQSYER66.js +22 -0
  89. package/dist/bundle/{failure-GRMMSDCZ.js → failure-BKOGBMIC.js} +4 -4
  90. package/dist/bundle/first-run-ZIFPVZAI.js +30 -0
  91. package/dist/bundle/first-screen-L5U26EY7.js +37 -0
  92. package/dist/bundle/{google-6ZZDKFBN.js → google-RXM2XEPD.js} +13 -13
  93. package/dist/bundle/{google-api-E6MOJ4ZD.js → google-api-NC65BZO4.js} +83 -64
  94. package/dist/bundle/grants-SEWUYYH3.js +105 -0
  95. package/dist/bundle/{identity-TID7S5NE.js → identity-PI6F2GWA.js} +6 -6
  96. package/dist/bundle/{instructions-ANJN4HV3.js → instructions-6LPDSKAD.js} +1 -1
  97. package/dist/bundle/{login-BGMK2ABH.js → login-HTY7GT2S.js} +64 -64
  98. package/dist/bundle/{mcp-WBHKX5E3.js → mcp-PPVOM4SE.js} +2 -2
  99. package/dist/bundle/{node-VOB45ES2.js → node-IB246NCQ.js} +2 -2
  100. package/dist/bundle/{node-sqlite-TSX6XQY2.js → node-sqlite-G2Y5SFJM.js} +9 -9
  101. package/dist/bundle/oauth-MWBKBI4T.js +22 -0
  102. package/dist/bundle/{open-3USWHGNR.js → open-WD4GFSJD.js} +8 -8
  103. package/dist/bundle/{openai-YZ5VGPIP.js → openai-QVM4PMY7.js} +17 -17
  104. package/dist/bundle/{process-44JS2W7L.js → process-SWPJGPQC.js} +1 -1
  105. package/dist/bundle/{program-TZLAFKJV.js → program-WHYFAMXR.js} +117 -98
  106. package/dist/bundle/prompt-OVYCGZB7.js +17 -0
  107. package/dist/bundle/{reasons-ZK3U3CIN.js → reasons-Q34DQWB6.js} +5 -5
  108. package/dist/bundle/{recognize-OFW7HWTM.js → recognize-DM3YWHSE.js} +7 -7
  109. package/dist/bundle/{remote-YBDRZQZ5.js → remote-KXVWRK7J.js} +10 -10
  110. package/dist/bundle/{rerank-TQQNS5FJ.js → rerank-TINXM3MY.js} +10 -10
  111. package/dist/bundle/{serve-OPZXMVLH.js → serve-IY2WL656.js} +12 -12
  112. package/dist/bundle/server-EMWVVT2C.js +70 -0
  113. package/dist/bundle/{server-2D6DDIK5.js → server-VPY3OWPC.js} +44 -44
  114. package/dist/bundle/{services-34WKT3NN.js → services-PXNBOCOC.js} +32 -32
  115. package/dist/bundle/{sqlite-runtime-WPUMKLUV.js → sqlite-runtime-5ZK2CV7Y.js} +9 -9
  116. package/dist/bundle/{start-ZXUJZ4JV.js → start-LDVCN3DK.js} +7 -7
  117. package/dist/bundle/{state-AV2RB3AQ.js → state-3MKTT3VS.js} +9 -9
  118. package/dist/bundle/{store-3M7N2Q5T.js → store-4VQOT5IJ.js} +18 -18
  119. package/dist/bundle/{store-YKV4GAMS.js → store-7M4MSUJV.js} +20 -20
  120. package/dist/bundle/store-maintenance-command-NRATYBWD.js +60 -0
  121. package/dist/bundle/tokens-XUKLM3SL.js +103 -0
  122. package/dist/commands/config.js +1 -1
  123. package/dist/commands/config.js.map +1 -1
  124. package/dist/commands/session.d.ts.map +1 -1
  125. package/dist/commands/session.js +10 -2
  126. package/dist/commands/session.js.map +1 -1
  127. package/dist/config.d.ts +16 -5
  128. package/dist/config.d.ts.map +1 -1
  129. package/dist/config.js +11 -17
  130. package/dist/config.js.map +1 -1
  131. package/dist/download.d.ts +3 -2
  132. package/dist/download.d.ts.map +1 -1
  133. package/dist/download.js +21 -9
  134. package/dist/download.js.map +1 -1
  135. package/dist/google-api.d.ts +3 -1
  136. package/dist/google-api.d.ts.map +1 -1
  137. package/dist/google-api.js +27 -7
  138. package/dist/google-api.js.map +1 -1
  139. package/dist/login.js +1 -1
  140. package/dist/login.js.map +1 -1
  141. package/dist/program.d.ts.map +1 -1
  142. package/dist/program.js +6 -6
  143. package/dist/program.js.map +1 -1
  144. package/dist/version.d.ts +1 -1
  145. package/dist/version.js +1 -1
  146. package/package.json +3 -3
  147. package/dist/bundle/chunk-77YTRBL6.js +0 -249
  148. package/dist/bundle/command-contract-NUIWUVYB.js +0 -39
  149. package/dist/bundle/entry-ZHCNI7XO.js +0 -22
  150. package/dist/bundle/first-run-3DC2SDWM.js +0 -30
  151. package/dist/bundle/first-screen-YJF4YODC.js +0 -37
  152. package/dist/bundle/grants-GWXDH5GM.js +0 -105
  153. package/dist/bundle/oauth-CEOYXW6C.js +0 -22
  154. package/dist/bundle/prompt-SG7LAOXW.js +0 -17
  155. package/dist/bundle/server-R6G2O772.js +0 -70
  156. package/dist/bundle/store-maintenance-command-WDXNY4ZF.js +0 -60
  157. package/dist/bundle/tokens-F63RXXEF.js +0 -103
  158. package/dist/oauth-application.d.ts +0 -5
  159. package/dist/oauth-application.d.ts.map +0 -1
  160. package/dist/oauth-application.js +0 -9
  161. package/dist/oauth-application.js.map +0 -1
  162. /package/dist/bundle/{chunk-LK2E2ELG.js → chunk-LU3WKZBA.js} +0 -0
@@ -1,74 +1,45 @@
1
1
  import { createRequire as __bundleRequire } from "node:module";
2
2
  const require = __bundleRequire(import.meta.url);
3
3
  import {
4
- operations,
5
- privateFiles
6
- } from "./chunk-TVQDMP2F.js";
4
+ activeProfile,
5
+ paths
6
+ } from "./chunk-BQMIDYBA.js";
7
7
  import {
8
- commandPathKey,
9
- commandPermissions
10
- } from "./chunk-5XHLQZAG.js";
8
+ READ_SCOPE,
9
+ WRITE_SCOPE,
10
+ providerRequest
11
+ } from "./chunk-XZBR2O63.js";
11
12
  import {
12
- AI_ENTRIES,
13
- checkConfigText,
14
- issueMessage,
15
- settingsFor,
16
- usableProfileName,
17
- withSettingDefaults
18
- } from "./chunk-73TTP6ET.js";
13
+ googleError
14
+ } from "./chunk-BXR7BKM3.js";
19
15
  import {
20
16
  acquireLock
21
- } from "./chunk-DMHGWL5D.js";
22
- import {
23
- LEVELS
24
- } from "./chunk-HFGR33KD.js";
25
- import {
26
- MAX_TEXT_CHARS
27
- } from "./chunk-UNJE63JK.js";
28
- import {
29
- DRIVE_APP
30
- } from "./chunk-XFXRGQXJ.js";
17
+ } from "./chunk-S4YK6TTG.js";
31
18
  import {
32
19
  Credentials,
33
20
  isMovedRun,
34
21
  keyringService,
35
- resolvePaths,
36
- saveConfigFile,
37
22
  systemKeyring
38
- } from "./chunk-246P2DCT.js";
23
+ } from "./chunk-DCBFNBEB.js";
39
24
  import {
40
- array,
41
- boolean,
42
- integer,
43
- literal,
44
- maxValue,
45
25
  minLength,
46
- minValue,
26
+ nullable,
47
27
  number,
28
+ object,
48
29
  optional,
49
- parse,
50
- picklist,
51
30
  pipe,
52
- record,
53
- regex,
54
- strictObject,
55
- string,
56
- union
57
- } from "./chunk-TKW4QWCY.js";
31
+ safeParse,
32
+ string
33
+ } from "./chunk-VYXVPYA3.js";
58
34
  import {
59
35
  CliError,
60
36
  isCliError
61
- } from "./chunk-EBLA7GXY.js";
37
+ } from "./chunk-WZ5XK74U.js";
62
38
  import {
63
39
  __name
64
40
  } from "./chunk-ZVVMGPBJ.js";
65
41
 
66
- // node_modules/.pnpm/@wirecat+cli-core@0.565.0_@wirecat+cli-base@0.75.2_commander@15.0.0_esbuild@0.28.2_type_ff8e334310c9524b6cc272472a342b2f/node_modules/@wirecat/cli-core/dist/oauth/keeper.js
67
- import { createHash as createHash2 } from "node:crypto";
68
- import { join } from "node:path";
69
- import { setTimeout as delay } from "node:timers/promises";
70
-
71
- // node_modules/.pnpm/@wirecat+cli-core@0.565.0_@wirecat+cli-base@0.75.2_commander@15.0.0_esbuild@0.28.2_type_ff8e334310c9524b6cc272472a342b2f/node_modules/@wirecat/cli-core/dist/oauth/authorize.js
42
+ // node_modules/.pnpm/@wirecat+cli-core@0.566.0_@wirecat+cli-base@0.77.1_commander@15.0.0_esbuild@0.28.2_type_2c70ab84360472ff0036a7904a884c42/node_modules/@wirecat/cli-core/dist/oauth/authorize.js
72
43
  import { createHash, randomBytes } from "node:crypto";
73
44
  import { createServer } from "node:http";
74
45
  var DEFAULT_TIMEOUT_MS = 3e5;
@@ -204,10 +175,15 @@ var authorize = /* @__PURE__ */ __name(async (options) => {
204
175
  }
205
176
  }, "authorize");
206
177
 
207
- // node_modules/.pnpm/@wirecat+cli-core@0.565.0_@wirecat+cli-base@0.75.2_commander@15.0.0_esbuild@0.28.2_type_ff8e334310c9524b6cc272472a342b2f/node_modules/@wirecat/cli-core/dist/oauth/requests.js
178
+ // node_modules/.pnpm/@wirecat+cli-core@0.566.0_@wirecat+cli-base@0.77.1_commander@15.0.0_esbuild@0.28.2_type_2c70ab84360472ff0036a7904a884c42/node_modules/@wirecat/cli-core/dist/oauth/keeper.js
179
+ import { createHash as createHash2 } from "node:crypto";
180
+ import { join } from "node:path";
181
+ import { setTimeout as delay } from "node:timers/promises";
182
+
183
+ // node_modules/.pnpm/@wirecat+cli-core@0.566.0_@wirecat+cli-base@0.77.1_commander@15.0.0_esbuild@0.28.2_type_2c70ab84360472ff0036a7904a884c42/node_modules/@wirecat/cli-core/dist/oauth/requests.js
208
184
  var REQUEST_LIMIT_MS = 3e4;
209
185
  var TOKEN_LOG_EVENT = "oauth.token";
210
- var object = /* @__PURE__ */ __name((value) => {
186
+ var object2 = /* @__PURE__ */ __name((value) => {
211
187
  if (typeof value !== "object" || value === null || Array.isArray(value))
212
188
  throw new Error("not an object");
213
189
  return value;
@@ -239,17 +215,17 @@ var clientFields = /* @__PURE__ */ __name(({ client }) => ({
239
215
  }), "clientFields");
240
216
  var requestTokens = /* @__PURE__ */ __name(async (provider, params, context) => {
241
217
  const operation = params.grant_type ?? "unknown";
242
- const record2 = /* @__PURE__ */ __name((level, fields) => context.log?.[level]({ event: TOKEN_LOG_EVENT, provider: provider.id, operation, pid: process.pid, ...fields }), "record");
218
+ const record = /* @__PURE__ */ __name((level, fields) => context.log?.[level]({ event: TOKEN_LOG_EVENT, provider: provider.id, operation, pid: process.pid, ...fields }), "record");
243
219
  const again = `run ${context.signInCommand} again`;
244
220
  const response = await post(provider.tokenUrl, new URLSearchParams({ ...params, ...clientFields(context) }), context);
245
221
  if (!response) {
246
- record2("warn", { outcome: "no_response" });
222
+ record("warn", { outcome: "no_response" });
247
223
  throw new CliError("outcome_unknown", `${provider.name} token request did not finish; ${again} if it keeps failing`, {
248
224
  reason: "oauth.no-response"
249
225
  });
250
226
  }
251
227
  if (!response.ok) {
252
- record2("warn", { outcome: "rejected", status: response.status });
228
+ record("warn", { outcome: "rejected", status: response.status });
253
229
  if (response.status === 429 || response.status >= 500)
254
230
  throw new CliError("provider_unavailable", `${provider.name} token request failed (HTTP ${response.status})`, {
255
231
  status: response.status,
@@ -263,9 +239,9 @@ var requestTokens = /* @__PURE__ */ __name(async (provider, params, context) =>
263
239
  }
264
240
  let body;
265
241
  try {
266
- body = object(await response.json());
242
+ body = object2(await response.json());
267
243
  } catch {
268
- record2("error", { outcome: "unreadable_response", status: response.status });
244
+ record("error", { outcome: "unreadable_response", status: response.status });
269
245
  throw new CliError("invalid_response", `${provider.name} returned an unreadable token response; ${again}`, {
270
246
  reason: "oauth.invalid-response"
271
247
  });
@@ -274,20 +250,20 @@ var requestTokens = /* @__PURE__ */ __name(async (provider, params, context) =>
274
250
  const refreshToken = typeof body.refresh_token === "string" && body.refresh_token ? body.refresh_token : previous?.refreshToken;
275
251
  const expiresIn = body.expires_in;
276
252
  if (typeof body.access_token !== "string" || !body.access_token || expiresIn !== void 0 && (typeof expiresIn !== "number" || !Number.isFinite(expiresIn) || expiresIn <= 0) || body.scope !== void 0 && typeof body.scope !== "string" || body.token_type !== void 0 && typeof body.token_type !== "string") {
277
- record2("error", { outcome: "invalid_response", status: response.status });
253
+ record("error", { outcome: "invalid_response", status: response.status });
278
254
  throw new CliError("invalid_response", `${provider.name} returned an invalid token response; ${again}`, {
279
255
  reason: "oauth.invalid-response"
280
256
  });
281
257
  }
282
258
  if (!refreshToken) {
283
- record2("error", { outcome: "no_refresh_token", status: response.status });
259
+ record("error", { outcome: "no_refresh_token", status: response.status });
284
260
  throw new CliError("authentication_error", `${provider.name} returned no offline refresh token; ${again}`, {
285
261
  reason: "oauth.failed"
286
262
  });
287
263
  }
288
264
  const scopes = typeof body.scope === "string" ? body.scope.split(/\s+/).filter(Boolean) : previous?.scopes ?? [];
289
265
  const tokenType = typeof body.token_type === "string" ? body.token_type : previous?.tokenType;
290
- record2("info", {
266
+ record("info", {
291
267
  outcome: "received",
292
268
  status: response.status,
293
269
  ...previous ? { rotated: refreshToken !== previous.refreshToken } : {}
@@ -321,7 +297,7 @@ var revokeToken = /* @__PURE__ */ __name(async (provider, tokens, context) => {
321
297
  });
322
298
  }, "revokeToken");
323
299
 
324
- // node_modules/.pnpm/@wirecat+cli-core@0.565.0_@wirecat+cli-base@0.75.2_commander@15.0.0_esbuild@0.28.2_type_ff8e334310c9524b6cc272472a342b2f/node_modules/@wirecat/cli-core/dist/oauth/keeper.js
300
+ // node_modules/.pnpm/@wirecat+cli-core@0.566.0_@wirecat+cli-base@0.77.1_commander@15.0.0_esbuild@0.28.2_type_2c70ab84360472ff0036a7904a884c42/node_modules/@wirecat/cli-core/dist/oauth/keeper.js
325
301
  var inFlight = /* @__PURE__ */ new Map();
326
302
  var refreshedInMemory = /* @__PURE__ */ new Map();
327
303
  var tokenKeeper = /* @__PURE__ */ __name((options) => {
@@ -483,9 +459,9 @@ var tokenKeeper = /* @__PURE__ */ __name((options) => {
483
459
  };
484
460
  }, "tokenKeeper");
485
461
 
486
- // node_modules/.pnpm/@wirecat+cli-core@0.565.0_@wirecat+cli-base@0.75.2_commander@15.0.0_esbuild@0.28.2_type_ff8e334310c9524b6cc272472a342b2f/node_modules/@wirecat/cli-core/dist/oauth/storage.js
462
+ // node_modules/.pnpm/@wirecat+cli-core@0.566.0_@wirecat+cli-base@0.77.1_commander@15.0.0_esbuild@0.28.2_type_2c70ab84360472ff0036a7904a884c42/node_modules/@wirecat/cli-core/dist/oauth/storage.js
487
463
  var invalid = /* @__PURE__ */ __name(() => new CliError("authentication_error", "the saved sign-in cannot be read; sign in again", { reason: "oauth.invalid" }), "invalid");
488
- var parse2 = /* @__PURE__ */ __name((raw) => {
464
+ var parse = /* @__PURE__ */ __name((raw) => {
489
465
  let value;
490
466
  try {
491
467
  value = JSON.parse(raw);
@@ -502,7 +478,7 @@ var previousOf = /* @__PURE__ */ __name((raw) => {
502
478
  if (raw === void 0)
503
479
  return {};
504
480
  try {
505
- return parse2(raw);
481
+ return parse(raw);
506
482
  } catch {
507
483
  return {};
508
484
  }
@@ -510,7 +486,7 @@ var previousOf = /* @__PURE__ */ __name((raw) => {
510
486
  var defined = /* @__PURE__ */ __name((value) => Object.fromEntries(Object.entries(value).filter(([, field]) => field !== void 0)), "defined");
511
487
  var driveSessionCodec = {
512
488
  decode: /* @__PURE__ */ __name((raw) => {
513
- const value = parse2(raw);
489
+ const value = parse(raw);
514
490
  const tokens = value.tokens;
515
491
  if (typeof tokens !== "object" || tokens === null || Array.isArray(tokens))
516
492
  throw invalid();
@@ -520,7 +496,11 @@ var driveSessionCodec = {
520
496
  if (!refreshToken || !clientId || typeof value.principal !== "string")
521
497
  throw invalid();
522
498
  return {
523
- client: defined({ clientId, clientSecret: text(value.clientSecret) }),
499
+ client: defined({
500
+ clientId,
501
+ clientSecret: text(value.clientSecret),
502
+ source: text(value.clientSource)
503
+ }),
524
504
  tokens: defined({
525
505
  accessToken: text(fields.access_token),
526
506
  refreshToken,
@@ -538,6 +518,7 @@ var driveSessionCodec = {
538
518
  ...extra,
539
519
  clientId: client.clientId,
540
520
  ...client.clientSecret ? { clientSecret: client.clientSecret } : {},
521
+ ...client.source ? { clientSource: client.source } : {},
541
522
  tokens: defined({
542
523
  ...oldTokens,
543
524
  access_token: tokens.accessToken,
@@ -561,20 +542,20 @@ var keyringFailure = /* @__PURE__ */ __name((thrown, secret) => {
561
542
  var credentialStorage = /* @__PURE__ */ __name((options) => {
562
543
  if (!options.credentials.keyring)
563
544
  throw new CliError("configuration_error", "a sign-in store needs its keyring passed in, never a default");
564
- const credentials = new Credentials(options.credentials);
545
+ const credentials2 = new Credentials(options.credentials);
565
546
  const { account, codec } = options;
566
547
  const moved = options.credentials.isolated === true || options.credentials.keyring === systemKeyring && isMovedRun({ appName: options.credentials.service, env: options.credentials.env ?? process.env });
567
548
  const service = keyringService(options.credentials.service, options.credentials.configDir, options.credentials.isolated);
568
549
  const raw = /* @__PURE__ */ __name((name) => {
569
550
  try {
570
- return credentials.read(name)?.secret;
551
+ return credentials2.read(name)?.secret;
571
552
  } catch (error) {
572
553
  throw keyringFailure(error);
573
554
  }
574
555
  }, "raw");
575
556
  const save = /* @__PURE__ */ __name((value, writeOptions) => {
576
557
  try {
577
- credentials.write(account, value, writeOptions);
558
+ credentials2.write(account, value, writeOptions);
578
559
  } catch (error) {
579
560
  throw keyringFailure(error, value);
580
561
  }
@@ -607,7 +588,7 @@ var credentialStorage = /* @__PURE__ */ __name((options) => {
607
588
  write: /* @__PURE__ */ __name((input, writeOptions) => save(codec.encode({ ...input, previous: raw(account) }), writeOptions), "write"),
608
589
  remove: /* @__PURE__ */ __name(() => {
609
590
  try {
610
- return credentials.remove(account);
591
+ return credentials2.remove(account);
611
592
  } catch (error) {
612
593
  throw keyringFailure(error);
613
594
  }
@@ -615,313 +596,212 @@ var credentialStorage = /* @__PURE__ */ __name((options) => {
615
596
  };
616
597
  }, "credentialStorage");
617
598
 
618
- // node_modules/.pnpm/@wirecat+cli-core@0.565.0_@wirecat+cli-base@0.75.2_commander@15.0.0_esbuild@0.28.2_type_ff8e334310c9524b6cc272472a342b2f/node_modules/@wirecat/cli-core/dist/oauth/client-file.js
619
- import { readFileSync } from "node:fs";
620
- var readClientFile = /* @__PURE__ */ __name((location, options = {}) => {
621
- if (!options.shipped && typeof location === "string") {
622
- const mode = privateFiles({ files: [location], dirs: [] }, options.platform);
623
- if (mode.checked && !mode.ok)
624
- throw new CliError("configuration_error", `the client file can be read by other users of this computer; run chmod 600 ${location} and try again`, { reason: "sign-in.client-file-open" });
625
- }
599
+ // dist/tokens.js
600
+ import { OAuth2Client } from "google-auth-library";
601
+ var Session = object({
602
+ principal: string(),
603
+ clientId: string(),
604
+ clientSecret: optional(string()),
605
+ tokens: object({
606
+ access_token: optional(nullable(string())),
607
+ refresh_token: pipe(string(), minLength(1)),
608
+ expiry_date: optional(nullable(number())),
609
+ scope: optional(string()),
610
+ token_type: optional(nullable(string()))
611
+ })
612
+ });
613
+ var credentialOptions = /* @__PURE__ */ __name((env, storage, keyring) => ({
614
+ configDir: paths(env).config,
615
+ service: "drive-cli",
616
+ // The keyring falls back to the private file by itself (WC-SECR-4); `file` skips the keyring.
617
+ storage: storage === "keyring" ? "auto" : storage,
618
+ env,
619
+ isolated: isMovedRun({ appName: "drive-cli", prefix: "DRIVE", env }),
620
+ ...keyring ? { keyring } : {}
621
+ }), "credentialOptions");
622
+ var credentials = /* @__PURE__ */ __name((env, storage, keyring) => new Credentials(credentialOptions(env, storage, keyring)), "credentials");
623
+ var notSaved = /* @__PURE__ */ __name(() => new CliError("configuration_error", "could not save Google sign-in: the private credentials file cannot be read; move it aside and sign in again", { reason: "oauth.not-saved" }), "notSaved");
624
+ var saveSession = /* @__PURE__ */ __name((env, name, session, storage, keyring) => {
626
625
  try {
627
- const { installed } = JSON.parse(readFileSync(location, "utf8"));
628
- const { client_id: clientId, client_secret: clientSecret } = installed;
629
- if (typeof clientId !== "string" || !clientId)
630
- throw new TypeError("client_id");
631
- if (clientSecret !== void 0 && typeof clientSecret !== "string")
632
- throw new TypeError("client_secret");
633
- return { clientId, ...clientSecret ? { clientSecret } : {} };
626
+ credentials(env, storage, keyring).write(name, JSON.stringify(session));
634
627
  } catch {
635
- throw options.invalid ?? new CliError("configuration_error", "could not read a Desktop app OAuth client JSON from the client file; its contents were not logged", { reason: "sign-in.client-file-invalid" });
636
- }
637
- }, "readClientFile");
638
-
639
- // dist/policy-keys.js
640
- var permissionKeys = /* @__PURE__ */ __name((paths2) => {
641
- const keys = /* @__PURE__ */ new Set([
642
- "mcp.authority",
643
- "mcp",
644
- "sheets.create",
645
- "sheets.rename",
646
- "sheets.insert",
647
- "sheets.format",
648
- "sheets.update"
649
- ]);
650
- for (const path of paths2)
651
- keys.add(path.join("."));
652
- for (const operation of operations)
653
- for (const key of methodPolicyKeys(operation.id))
654
- keys.add(key);
655
- return keys;
656
- }, "permissionKeys");
657
- var permissionNames = /* @__PURE__ */ __name((keys) => {
658
- const names = /* @__PURE__ */ new Set();
659
- for (const key of keys) {
660
- const parts = key.split(".");
661
- for (let end = 1; end <= parts.length; end++)
662
- names.add(parts.slice(0, end).join("."));
628
+ throw notSaved();
663
629
  }
664
- return names;
665
- }, "permissionNames");
666
- var DEFAULT_LEVELS = {
667
- "mcp.authority": "deny",
668
- ...Object.fromEntries(operations.filter((op) => op.effect === "destructive").map((op) => [`api.${op.id}`, "ask"]))
669
- };
670
- var methodPolicyKeys = /* @__PURE__ */ __name((method, body) => {
671
- const parts = method.split(".");
672
- const verb = parts.at(-1);
673
- const alias = method.startsWith("drive.files.") ? `files.${verb}` : method.startsWith("docs.documents.") ? `documents.${verb === "batchUpdate" ? "update" : verb}` : method.startsWith("sheets.spreadsheets.") ? `sheets.${method === "sheets.spreadsheets.get" ? "info" : method === "sheets.spreadsheets.values.get" ? "show" : verb === "append" ? "add" : verb}` : method === "driveactivity.activity.query" ? "documents.history" : method.startsWith("drive.") ? `${parts[1]}.${verb}` : void 0;
674
- const keys = [`api.${method}`, ...alias ? [alias] : []];
675
- if (method === "drive.replies.create" && body)
676
- keys.push(body.action === "resolve" ? "comments.resolve" : body.action === "reopen" ? "comments.reopen" : "comments.reply");
677
- if (method === "drive.replies.create" && body?.content !== void 0)
678
- keys.push("comments.reply");
679
- if (method === "sheets.spreadsheets.batchUpdate" && Array.isArray(body?.requests)) {
680
- const object2 = /* @__PURE__ */ __name((value) => !!value && typeof value === "object" && !Array.isArray(value), "object");
681
- for (const request of body.requests) {
682
- if (!object2(request))
683
- continue;
684
- if (request.addSheet || request.duplicateSheet)
685
- keys.push("sheets.create");
686
- if (object2(request.updateSheetProperties)) {
687
- const update = request.updateSheetProperties;
688
- if (object2(update.properties) && update.properties.title !== void 0 || String(update.fields).split(",").some((field) => field.trim() === "title" || field.trim() === "*"))
689
- keys.push("sheets.rename");
690
- if (object2(update.properties) && update.properties.gridProperties)
691
- keys.push("sheets.insert");
692
- }
693
- if (request.insertDimension || request.appendDimension || request.insertRange)
694
- keys.push("sheets.insert");
695
- if (request.repeatCell || request.updateCells || request.appendCells || request.updateBorders || request.addConditionalFormatRule || request.updateConditionalFormatRule || request.deleteConditionalFormatRule || request.addBanding || request.updateBanding || request.deleteBanding)
696
- keys.push("sheets.format");
697
- if (request.updateCells || request.appendCells || request.findReplace || request.pasteData || request.copyPaste || request.cutPaste || request.autoFill)
698
- keys.push("sheets.update");
699
- if (request.pasteData || request.copyPaste || request.cutPaste || request.autoFill)
700
- keys.push("sheets.format");
701
- if (object2(request.repeatCell) && (String(request.repeatCell.fields).split(",").some((field) => field.trim() === "*" || field.includes("userEnteredValue")) || object2(request.repeatCell.cell) && request.repeatCell.cell.userEnteredValue !== void 0))
702
- keys.push("sheets.update");
703
- }
630
+ }, "saveSession");
631
+ var googleProvider = /* @__PURE__ */ __name((client) => ({
632
+ id: "google",
633
+ name: "Google",
634
+ authorizeUrl: "https://accounts.google.com/o/oauth2/v2/auth",
635
+ tokenUrl: "https://oauth2.googleapis.com/token",
636
+ revokeUrl: "https://oauth2.googleapis.com/revoke",
637
+ client,
638
+ redirect: { kind: "loopback" },
639
+ // Without offline access Google returns no refresh token; without consent it does not return one again.
640
+ authorizeParams: { access_type: "offline", prompt: "select_account consent" }
641
+ }), "googleProvider");
642
+ var sessionKeeper = /* @__PURE__ */ __name((options) => tokenKeeper({
643
+ provider: googleProvider(options.client),
644
+ storage: credentialStorage({
645
+ credentials: { ...credentialOptions(options.env, options.storage), keyring: options.keyring ?? systemKeyring },
646
+ account: options.name,
647
+ codec: driveSessionCodec
648
+ }),
649
+ lockDir: paths(options.env).config,
650
+ fetch: options.fetch ?? globalThis.fetch,
651
+ signInCommand: `drive ${options.name} session start`,
652
+ // Above the client's own 5-minute early refresh, so a token it asks to replace is replaced.
653
+ freshForMs: 6 * 6e4,
654
+ ...options.signal ? { signal: options.signal } : {}
655
+ }), "sessionKeeper");
656
+ var authorizedClient = /* @__PURE__ */ __name((env, name, keyring, signal) => {
657
+ const profile = activeProfile(env, name);
658
+ let parsed;
659
+ try {
660
+ const secret = credentials(env, profile.storage, keyring).read(name)?.secret;
661
+ if (!secret)
662
+ throw new Error("missing login");
663
+ parsed = safeParse(Session, JSON.parse(secret));
664
+ } catch {
665
+ throw new CliError("authentication_error", `could not load Google sign-in \u2014 run drive ${name} session start again`, {
666
+ reason: "oauth.expired"
667
+ });
704
668
  }
705
- return [...new Set(keys)];
706
- }, "methodPolicyKeys");
707
-
708
- // dist/config.js
709
- import { readFileSync as readFileSync2 } from "node:fs";
710
- import { join as join2 } from "node:path";
711
-
712
- // dist/oauth-application.js
713
- var WIRECAT_APPLICATION = Object.freeze({
714
- clientId: "240274586781-vssrlm9c0l3n1ti12ce7tg95ro4bghal.apps.googleusercontent.com",
715
- // biome-ignore lint/security/noSecrets: public installed-app OAuth identity, non-confidential per Google native-app guidance
716
- clientSecret: "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"
717
- // gitleaks:allow -- public installed-app identity
718
- });
719
-
720
- // dist/config.js
721
- var Common = {
722
- ...AI_ENTRIES,
723
- permissions: optional(record(string(), picklist(LEVELS))),
724
- max_text_chars: optional(pipe(number(), integer(), minValue(1), maxValue(MAX_TEXT_CHARS)))
725
- };
726
- var RunSettings = {
727
- record: optional(boolean()),
728
- keep_runs_for_days: optional(pipe(number(), integer(), minValue(1))),
729
- keep_successful_runs_for_days: optional(pipe(number(), integer(), minValue(1))),
730
- runs_size_limit_mb: optional(pipe(number(), integer(), minValue(1))),
731
- record_input: optional(union([boolean(), literal("failed")]))
732
- };
733
- var SharedDefaults = {
734
- limit: optional(pipe(number(), integer(), minValue(1))),
735
- sends_per_hour: optional(pipe(number(), integer(), minValue(0))),
736
- update_check: optional(boolean()),
737
- skill_hint: optional(boolean())
738
- };
739
- var DEFAULTS_ONLY = /* @__PURE__ */ new Set([...Object.keys(RunSettings), "update_check", "skill_hint"]);
740
- var SETTING_NAMES = /* @__PURE__ */ new Set([...Object.keys(Common), "picture_search", ...DEFAULTS_ONLY]);
741
- var Mirror = strictObject({
742
- id: pipe(string(), regex(/^[a-z0-9-]{1,40}$/)),
743
- path: pipe(string(), minLength(1)),
744
- folder: pipe(string(), regex(/^[A-Za-z0-9_-]{1,200}$/))
745
- });
746
- var Profile = strictObject({
747
- principal: string(),
748
- roots: optional(array(pipe(string(), regex(/^[A-Za-z0-9_-]{1,200}$/))), []),
749
- mirrors: optional(array(Mirror)),
750
- storage: picklist(["keyring", "file"]),
751
- picture_search: optional(boolean()),
752
- ...Common
753
- });
754
- var ConfigSchema = strictObject({
755
- profiles: optional(record(string(), Profile), {}),
756
- defaults: optional(strictObject({ ...Common, ...RunSettings, ...SharedDefaults }))
757
- });
758
- var keyOf = /* @__PURE__ */ __name((path) => {
759
- if (path[0] !== "api" || path[1] === void 0)
760
- return commandPathKey(path);
761
- if (["call", "list", "show"].includes(path[1]))
762
- return null;
763
- const operation = operations.find((one) => one.command === path[1]);
764
- return operation ? `api.${operation.id}` : commandPathKey(path);
765
- }, "keyOf");
766
- var configuration = settingsFor(DRIVE_APP, {
767
- configRepair: false,
768
- // drive's own schema decides what the file may hold, so `doctor` names a profile that lacks its principal.
769
- schema: ConfigSchema,
770
- profile: {
771
- principal: optional(string()),
772
- roots: optional(array(pipe(string(), regex(/^[A-Za-z0-9_-]{1,200}$/)))),
773
- mirrors: optional(array(Mirror)),
774
- storage: optional(picklist(["keyring", "file"])),
775
- max_text_chars: Common.max_text_chars
776
- },
777
- settings: [
778
- {
779
- key: "max_text_chars",
780
- default: MAX_TEXT_CHARS,
781
- description: "the most characters of text one file may have to be imported"
669
+ if (!parsed.success || parsed.output.principal !== profile.principal)
670
+ throw new CliError("authentication_error", "saved sign-in is invalid or belongs to another account", {
671
+ reason: "oauth.expired"
672
+ });
673
+ const session = parsed.output;
674
+ const keeper = sessionKeeper({
675
+ env,
676
+ name,
677
+ storage: profile.storage,
678
+ client: { clientId: session.clientId, ...session.clientSecret ? { clientSecret: session.clientSecret } : {} },
679
+ ...keyring ? { keyring } : {},
680
+ ...signal ? { signal } : {}
681
+ });
682
+ const client = new OAuth2Client({
683
+ clientId: session.clientId,
684
+ clientSecret: session.clientSecret,
685
+ transporterOptions: { timeout: 3e4, ...signal ? { signal } : {} }
686
+ });
687
+ client.refreshHandler = async () => {
688
+ try {
689
+ const tokens = await keeper.tokens();
690
+ if (!tokens.accessToken || tokens.expiresAt === void 0)
691
+ throw new Error("no access token");
692
+ return { access_token: tokens.accessToken, expiry_date: tokens.expiresAt };
693
+ } catch (error) {
694
+ if (isCliError(error) && error.code !== "authentication_error")
695
+ throw error;
696
+ throw new CliError("authentication_error", `Google sign-in expired \u2014 run drive ${name} session start again`, {
697
+ reason: "oauth.expired"
698
+ });
782
699
  }
783
- ],
784
- permissions: commandPermissions({ keyOf, extra: [...permissionKeys([])], defaults: DEFAULT_LEVELS })
785
- });
786
- var paths = /* @__PURE__ */ __name((env) => resolvePaths({ appName: "drive-cli", prefix: "DRIVE", env }), "paths");
787
- var configPath = /* @__PURE__ */ __name((env) => join2(paths(env).config, "config.json"), "configPath");
788
- var TOOL = "drive";
789
- var isNode = /* @__PURE__ */ __name((value) => typeof value === "object" && value !== null && !Array.isArray(value), "isNode");
790
- var withoutIncomplete = /* @__PURE__ */ __name((raw, issues) => {
791
- const incomplete = new Set(issues.flatMap((issue) => issue.kind === "missing_setting" && issue.profile ? [issue.profile] : []));
792
- if (!incomplete.size || !isNode(raw) || !isNode(raw.profiles))
793
- return void 0;
794
- return {
795
- ...raw,
796
- profiles: Object.fromEntries(Object.entries(raw.profiles).filter(([name]) => !incomplete.has(name)))
797
- };
798
- }, "withoutIncomplete");
799
- var examine = /* @__PURE__ */ __name((text2, file, knownPermissions) => {
800
- const check = /* @__PURE__ */ __name((body) => checkConfigText(body, {
801
- file,
802
- tool: TOOL,
803
- schema: ConfigSchema,
804
- repair: false,
805
- ...knownPermissions ? { knownPermissions } : {}
806
- }), "check");
807
- const first = check(text2);
808
- if (first.issues.some((issue) => issue.kind === "invalid_json"))
809
- return { raw: {}, config: { profiles: {} }, issues: first.issues };
810
- const raw = JSON.parse(text2);
811
- if (first.config)
812
- return { raw, config: first.config, issues: first.issues };
813
- const rest = withoutIncomplete(raw, first.issues);
814
- const second = rest && check(JSON.stringify(rest));
815
- return {
816
- raw,
817
- config: second?.config ?? { profiles: {} },
818
- // Saved permissions are checked only in what loads, and the first pass loaded nothing.
819
- issues: [...first.issues, ...(second?.issues ?? []).filter((issue) => issue.kind === "unknown_permission")]
820
700
  };
821
- }, "examine");
822
- var inspectConfig = /* @__PURE__ */ __name((env, knownPermissions) => {
823
- const path = configPath(env);
824
- let text2;
701
+ const { refresh_token: _refresh, ...current } = session.tokens;
702
+ client.setCredentials(current);
703
+ return observeRequests(client);
704
+ }, "authorizedClient");
705
+ var covers = /* @__PURE__ */ __name((granted, required) => granted.includes(required) || required === READ_SCOPE && granted.includes(WRITE_SCOPE), "covers");
706
+ var grantedScopes = /* @__PURE__ */ __name((env, name, keyring) => {
825
707
  try {
826
- text2 = readFileSync2(path, "utf8");
708
+ const secret = credentials(env, activeProfile(env, name).storage, keyring).read(name)?.secret;
709
+ const parsed = secret ? safeParse(Session, JSON.parse(secret)) : void 0;
710
+ if (!parsed?.success)
711
+ return [];
712
+ return parsed.output.tokens.scope?.split(/\s+/).filter(Boolean);
827
713
  } catch {
828
- return { path, found: false, raw: {}, config: { profiles: {} }, issues: [] };
714
+ return [];
829
715
  }
830
- return { path, found: true, ...examine(text2, path, knownPermissions) };
831
- }, "inspectConfig");
832
- var configIssues = /* @__PURE__ */ __name((raw, file, knownPermissions) => examine(JSON.stringify(raw), file, knownPermissions).issues, "configIssues");
833
- var refusal = /* @__PURE__ */ __name((issues) => new CliError("configuration_error", issueMessage(issues)), "refusal");
834
- var readConfig = /* @__PURE__ */ __name((env, knownPermissions) => {
835
- const { config, issues } = inspectConfig(env, knownPermissions);
836
- if (issues.length)
837
- throw refusal(issues);
838
- return config;
839
- }, "readConfig");
840
- var writeConfig = /* @__PURE__ */ __name((env, config) => {
841
- const [issue] = configIssues(config, "drive settings");
842
- if (issue)
843
- throw new CliError("configuration_error", `drive settings: ${issue.profile === void 0 ? "" : `profile ${issue.profile}: `}${issue.what}`);
844
- saveConfigFile(configPath(env), withDefaults(parse(ConfigSchema, config)));
845
- }, "writeConfig");
846
- var withDefaults = /* @__PURE__ */ __name((raw, except = []) => withSettingDefaults(isNode(raw) && !Object.hasOwn(raw, "defaults") ? { ...raw, defaults: {} } : raw, configuration.declaredSettings.filter(({ key }) => !except.includes(key))).config, "withDefaults");
847
- var profileName = usableProfileName;
848
- var fileId = /* @__PURE__ */ __name((input) => {
849
- let id = input;
850
- if (input.startsWith("https://")) {
851
- const url = new URL(input);
852
- if (url.hostname !== "drive.google.com" && url.hostname !== "docs.google.com")
853
- throw new CliError("validation_error", "use a Google Drive/Docs URL or file ID");
854
- id = url.pathname.match(/\/(?:folders|d)\/([^/]+)/)?.[1] ?? "";
716
+ }, "grantedScopes");
717
+ var checkAuthorization = /* @__PURE__ */ __name(async (client, required = READ_SCOPE) => {
718
+ try {
719
+ const { token } = await client.getAccessToken();
720
+ if (!token)
721
+ throw new CliError("authentication_error", "Google returned no access token");
722
+ const info = await client.getTokenInfo(token);
723
+ if (!covers(info.scopes, required))
724
+ throw new CliError("permission_error", "sign-in lacks the required permission; run drive <profile> session start --grant write, activity or apps when needed", { reason: "oauth.scope-missing" });
725
+ } catch (error) {
726
+ throw googleError(error);
855
727
  }
856
- if (!/^[A-Za-z0-9_-]{1,200}$/.test(id))
857
- throw new CliError("validation_error", "invalid Google file ID");
858
- return id;
859
- }, "fileId");
860
- var unknownProfile = /* @__PURE__ */ __name((name, profiles) => new CliError("validation_error", profiles.length ? `no profile ${name} here \u2014 profiles here: ${profiles.join(", ")}; a new one signs in with drive ${name} session start` : `no profiles here yet; create one with drive ${name} session start`, { reason: "profile.unknown", profiles }), "unknownProfile");
861
- var activeProfile = /* @__PURE__ */ __name((env, name) => {
862
- const config = readConfig(env);
863
- const profile = config.profiles[profileName(name)];
864
- if (!profile)
865
- throw unknownProfile(name, Object.keys(config.profiles).sort());
866
- return profile;
867
- }, "activeProfile");
868
- var checkTextLimit = /* @__PURE__ */ __name((value) => {
869
- if (typeof value !== "number" || !Number.isInteger(value) || value < 1)
870
- throw new CliError("validation_error", "max_text_chars must be a positive whole number of characters");
871
- if (value > MAX_TEXT_CHARS)
872
- throw new CliError("validation_error", `max_text_chars can be at most ${MAX_TEXT_CHARS}: the document readers return at most that many characters`);
873
- return value;
874
- }, "checkTextLimit");
875
- var textLimit = /* @__PURE__ */ __name((env, name) => activeProfile(env, name).max_text_chars ?? readConfig(env).defaults?.max_text_chars ?? MAX_TEXT_CHARS, "textLimit");
876
- var pictureSearch = /* @__PURE__ */ __name((env, name) => activeProfile(env, name).picture_search ?? false, "pictureSearch");
877
- var application = /* @__PURE__ */ __name((env, file) => {
878
- if (!file) {
879
- if (!env.DRIVE_GOOGLE_CLIENT_ID) {
880
- if (env.DRIVE_GOOGLE_CLIENT_SECRET)
881
- throw new CliError("configuration_error", "DRIVE_GOOGLE_CLIENT_SECRET requires DRIVE_GOOGLE_CLIENT_ID");
882
- return { ...WIRECAT_APPLICATION };
883
- }
884
- return {
885
- clientId: env.DRIVE_GOOGLE_CLIENT_ID,
886
- ...env.DRIVE_GOOGLE_CLIENT_SECRET ? { clientSecret: env.DRIVE_GOOGLE_CLIENT_SECRET } : {}
887
- };
728
+ }, "checkAuthorization");
729
+ var WORD = /^[a-z][a-z_]{0,23}$/;
730
+ var VERB = /^[a-z][A-Za-z]{0,31}$/;
731
+ var segment = /* @__PURE__ */ __name((part) => {
732
+ if (/^v\d+$/.test(part) || WORD.test(part))
733
+ return part;
734
+ const verb = part.split(":")[1];
735
+ return verb !== void 0 && VERB.test(verb) ? `:id:${verb}` : ":id";
736
+ }, "segment");
737
+ var operationOf = /* @__PURE__ */ __name((method, url) => {
738
+ let path = "";
739
+ try {
740
+ path = new URL(String(url ?? "")).pathname;
741
+ } catch {
888
742
  }
889
- return readClientFile(file, {
890
- invalid: new CliError("configuration_error", "could not read a valid Desktop OAuth client JSON; file contents were not logged", { reason: "sign-in.client-file-invalid" })
743
+ const template = path.split("/").filter(Boolean).map((part) => segment(decodeURIComponent(part))).join("/");
744
+ return `${(method ?? "GET").toUpperCase()} /${template}`;
745
+ }, "operationOf");
746
+ var reasonOf = /* @__PURE__ */ __name((data) => {
747
+ const error = data?.error;
748
+ const reason = error?.errors?.[0]?.reason ?? error?.status;
749
+ return typeof reason === "string" ? reason : void 0;
750
+ }, "reasonOf");
751
+ var observeRequests = /* @__PURE__ */ __name((client) => {
752
+ const transporter = client.transporter;
753
+ const request = transporter.request.bind(transporter);
754
+ transporter.request = (async (options) => {
755
+ const method = (options.method ?? "GET").toUpperCase();
756
+ const operation = operationOf(method, options.url);
757
+ const call = { method, endpointTemplate: operation.slice(method.length + 1), transport: "http" };
758
+ let ended;
759
+ const adapter = /* @__PURE__ */ __name(async (prepared, next) => {
760
+ const attempt = (prepared.retryConfig?.currentRetryAttempt ?? 0) + 1;
761
+ const waitMs = ended === void 0 ? void 0 : Math.round(performance.now() - ended);
762
+ const answered = providerRequest(operation, void 0, {
763
+ ...call,
764
+ attempt,
765
+ ...waitMs === void 0 ? {} : { waitMs }
766
+ });
767
+ try {
768
+ const response = await (options.adapter ? options.adapter(prepared, next) : next(prepared));
769
+ const failed = !(prepared.validateStatus?.(response.status) ?? response.status < 400);
770
+ const providerError = failed ? reasonOf(response.data) : void 0;
771
+ answered({
772
+ status: response.status,
773
+ ...failed ? { errorCode: "provider_error" } : {},
774
+ ...providerError ? { providerError } : {}
775
+ });
776
+ return response;
777
+ } catch (error) {
778
+ answered({ error, errorCode: googleError(error).code });
779
+ throw error;
780
+ } finally {
781
+ ended = performance.now();
782
+ }
783
+ }, "adapter");
784
+ try {
785
+ return await request({ ...options, adapter });
786
+ } catch (error) {
787
+ if (ended === void 0)
788
+ providerRequest(operation, void 0, { ...call, attempt: 1 })({ error, errorCode: googleError(error).code });
789
+ throw error;
790
+ }
891
791
  });
892
- }, "application");
893
- var selectedFolders = /* @__PURE__ */ __name((env, profile, filter = {}) => activeProfile(env, profile).roots.flatMap((id) => filter.id === void 0 || id === filter.id ? [{ id }] : []), "selectedFolders");
894
- var configuredMirrors = /* @__PURE__ */ __name((env, profile, filter = {}) => (activeProfile(env, profile).mirrors ?? []).filter((row) => Object.entries(filter).every(([key, value]) => row[key] === value)), "configuredMirrors");
895
- var configuredSessions = /* @__PURE__ */ __name((env, filter, knownPermissions) => Object.entries(readConfig(env, knownPermissions).profiles).flatMap(([name, row]) => (filter.profile === void 0 || filter.profile === name) && (filter.storage === void 0 || filter.storage === row.storage) ? [{ profile: name, selected_folders: row.roots.length, storage: row.storage }] : []), "configuredSessions");
792
+ return client;
793
+ }, "observeRequests");
896
794
 
897
795
  export {
898
- tokenKeeper,
899
- driveSessionCodec,
900
- credentialStorage,
901
- permissionKeys,
902
- permissionNames,
903
- DEFAULT_LEVELS,
904
- methodPolicyKeys,
905
- DEFAULTS_ONLY,
906
- SETTING_NAMES,
907
- configuration,
908
- paths,
909
- configPath,
910
- inspectConfig,
911
- configIssues,
912
- refusal,
913
- readConfig,
914
- writeConfig,
915
- withDefaults,
916
- profileName,
917
- fileId,
918
- unknownProfile,
919
- activeProfile,
920
- checkTextLimit,
921
- textLimit,
922
- pictureSearch,
923
- application,
924
- selectedFolders,
925
- configuredMirrors,
926
- configuredSessions
796
+ credentials,
797
+ notSaved,
798
+ saveSession,
799
+ googleProvider,
800
+ sessionKeeper,
801
+ authorizedClient,
802
+ covers,
803
+ grantedScopes,
804
+ checkAuthorization,
805
+ operationOf,
806
+ observeRequests
927
807
  };