@wirecat/drive-cli 0.59.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 (182) hide show
  1. package/README.md +4 -5
  2. package/dist/bin/drive.js +2 -2
  3. package/dist/bin/drive.js.map +1 -1
  4. package/dist/bundle/{all-profiles-CVISDGMF.js → all-profiles-H4L3Z5UM.js} +14 -14
  5. package/dist/bundle/{anthropic-WLNQC23G.js → anthropic-PPGFISVP.js} +9 -9
  6. package/dist/bundle/{app-server-P2VOONXF.js → app-server-YXVK2FUZ.js} +52 -52
  7. package/dist/bundle/{bun-CDFBNTKV.js → bun-DKZAL6ML.js} +2 -2
  8. package/dist/bundle/{bun-sqlite-MNZICITP.js → bun-sqlite-MTZY36QK.js} +8 -8
  9. package/dist/bundle/{chunk-TFH5X46A.js → chunk-2RJA4BQB.js} +19 -19
  10. package/dist/bundle/{chunk-VVCZS42A.js → chunk-3252WXOL.js} +1 -1
  11. package/dist/bundle/{chunk-H2BKXPBL.js → chunk-36CWGEVX.js} +2 -2
  12. package/dist/bundle/{chunk-HWLLVLAB.js → chunk-3I2D5TK2.js} +14 -11
  13. package/dist/bundle/{chunk-PAEVBAM3.js → chunk-3SJQNS72.js} +5 -5
  14. package/dist/bundle/{chunk-GI5JBGXH.js → chunk-3UPIJ7DW.js} +615 -374
  15. package/dist/bundle/{chunk-EORMZCVF.js → chunk-3WZH3WV3.js} +3 -3
  16. package/dist/bundle/{chunk-ZSMCJKGP.js → chunk-5W56YMQS.js} +28 -27
  17. package/dist/bundle/{chunk-LJ7E4HLQ.js → chunk-5W7D5H2R.js} +1 -1
  18. package/dist/bundle/{chunk-6C6255U6.js → chunk-67HS46KM.js} +12 -12
  19. package/dist/bundle/{chunk-AD62XJKO.js → chunk-6DN4VPA7.js} +25 -25
  20. package/dist/bundle/{chunk-HIP43OGZ.js → chunk-6IBM4Z3V.js} +1 -1
  21. package/dist/bundle/{chunk-QTM7USFA.js → chunk-6SUGANRJ.js} +6 -6
  22. package/dist/bundle/{chunk-II7LST64.js → chunk-6Y2FWJZ4.js} +4 -3
  23. package/dist/bundle/{chunk-XCOCPXCM.js → chunk-73WSULMI.js} +2 -2
  24. package/dist/bundle/{chunk-V42KAPU3.js → chunk-AM4RIWOZ.js} +4 -4
  25. package/dist/bundle/{chunk-DI5Z4SH5.js → chunk-AWN22PJK.js} +3 -3
  26. package/dist/bundle/{chunk-HMZAMHKN.js → chunk-BCWUDTYQ.js} +2 -2
  27. package/dist/bundle/{chunk-EHEZSV6I.js → chunk-BF6TQMNB.js} +8 -8
  28. package/dist/bundle/chunk-BQMIDYBA.js +415 -0
  29. package/dist/bundle/{chunk-FVQCM7IQ.js → chunk-BXR7BKM3.js} +5 -5
  30. package/dist/bundle/{chunk-OKXSTWKW.js → chunk-CACYL36O.js} +8 -8
  31. package/dist/bundle/{chunk-CBM2XAEZ.js → chunk-DCBFNBEB.js} +113 -51
  32. package/dist/bundle/{chunk-GT5KTGCN.js → chunk-DEPMQHXQ.js} +4 -4
  33. package/dist/bundle/{chunk-3KJTJDDT.js → chunk-DXPOVLQC.js} +46 -28
  34. package/dist/bundle/{chunk-P7WPYKSB.js → chunk-E5EXJ2XS.js} +4 -4
  35. package/dist/bundle/{chunk-IGF6EXBR.js → chunk-E6J5YH2N.js} +34 -34
  36. package/dist/bundle/{chunk-IIP43FQJ.js → chunk-ECEYAQGN.js} +2 -2
  37. package/dist/bundle/{chunk-OMMEQJOB.js → chunk-EPCJUL6M.js} +3 -3
  38. package/dist/bundle/{chunk-JSDVK3JA.js → chunk-FE5JJXKA.js} +2 -2
  39. package/dist/bundle/{chunk-FICVPYE4.js → chunk-HFM653T3.js} +49 -49
  40. package/dist/bundle/{chunk-KPRGTTJH.js → chunk-HGOYQUT7.js} +1 -1
  41. package/dist/bundle/{chunk-3VSUT6BD.js → chunk-I26VL4W7.js} +2 -2
  42. package/dist/bundle/{chunk-V36RIXFA.js → chunk-J4HQVHMN.js} +6 -5
  43. package/dist/bundle/{chunk-P3ZTW2ZM.js → chunk-J5UDQD5S.js} +5 -5
  44. package/dist/bundle/{chunk-3KNZADHJ.js → chunk-JVBLXSAA.js} +437 -193
  45. package/dist/bundle/{chunk-TJXPJ3A5.js → chunk-K7LS3NGM.js} +137 -62
  46. package/dist/bundle/{chunk-2AXA5SKP.js → chunk-KV4267S4.js} +1 -1
  47. package/dist/bundle/{chunk-YU3PTU3D.js → chunk-LARQTWIL.js} +1 -1
  48. package/dist/bundle/{chunk-B5GBJ35N.js → chunk-N2RLJTIW.js} +4 -4
  49. package/dist/bundle/{chunk-K4LXGZTE.js → chunk-NIX2MWHZ.js} +242 -344
  50. package/dist/bundle/{chunk-L5SE2XZP.js → chunk-NZ2EIZLX.js} +14 -10
  51. package/dist/bundle/{chunk-F3FOL42A.js → chunk-O5CUFS7T.js} +2 -2
  52. package/dist/bundle/{chunk-UQPKAY6I.js → chunk-OFFA54TW.js} +2 -2
  53. package/dist/bundle/{chunk-W62CON5K.js → chunk-OGNOQDWB.js} +4 -4
  54. package/dist/bundle/{chunk-MUUHUHWC.js → chunk-OLPJRD4S.js} +1 -22
  55. package/dist/bundle/{chunk-YADXWQHV.js → chunk-PJTX2MOI.js} +26 -26
  56. package/dist/bundle/{chunk-M6I2SQN7.js → chunk-PY7LKNOS.js} +2 -2
  57. package/dist/bundle/{chunk-GJ4ZCIOP.js → chunk-Q4XVBKX4.js} +3 -3
  58. package/dist/bundle/{chunk-A6SLYOP2.js → chunk-QR5VQXQ5.js} +69 -36
  59. package/dist/bundle/{chunk-OZH4ALTI.js → chunk-QSGT4ZH4.js} +1 -1
  60. package/dist/bundle/{chunk-UWVNRPT7.js → chunk-RFRCOAWS.js} +22 -22
  61. package/dist/bundle/{chunk-A6EG7ZDS.js → chunk-S4YK6TTG.js} +13 -13
  62. package/dist/bundle/{chunk-LPHMAQJQ.js → chunk-TKGAYKXW.js} +16 -16
  63. package/dist/bundle/{chunk-KFZUODXB.js → chunk-UKOYQC5O.js} +39 -22
  64. package/dist/bundle/{chunk-MEAPA4EZ.js → chunk-UO2IUDVK.js} +2 -2
  65. package/dist/bundle/{chunk-HIOJRPCT.js → chunk-VPDAH7PJ.js} +1 -1
  66. package/dist/bundle/{chunk-3U22QTU6.js → chunk-VYXVPYA3.js} +24 -6
  67. package/dist/bundle/{chunk-VT6GZAF4.js → chunk-W767AUNR.js} +4 -4
  68. package/dist/bundle/{chunk-5C7K6XIT.js → chunk-WIU733D2.js} +1 -1
  69. package/dist/bundle/{chunk-IADOBOKB.js → chunk-WUP2MJDN.js} +2 -2
  70. package/dist/bundle/{chunk-EBLA7GXY.js → chunk-WZ5XK74U.js} +2 -1
  71. package/dist/bundle/{chunk-IBZ3IBO4.js → chunk-X2CXW4HM.js} +7 -7
  72. package/dist/bundle/{chunk-JW2CVCUH.js → chunk-XGMDWIUP.js} +4 -4
  73. package/dist/bundle/{chunk-BSGOM3BD.js → chunk-XGNC5OJG.js} +1 -1
  74. package/dist/bundle/{chunk-TI55J3BA.js → chunk-XLFJLZJL.js} +4 -4
  75. package/dist/bundle/{chunk-7QTVIZII.js → chunk-XYCCGGKN.js} +792 -327
  76. package/dist/bundle/{chunk-6CQO2FIN.js → chunk-XZBR2O63.js} +400 -291
  77. package/dist/bundle/{chunk-EVETU3TF.js → chunk-YMBFZA3H.js} +8 -8
  78. package/dist/bundle/{chunk-ZYCLPJ7U.js → chunk-YPF6OS37.js} +1 -1
  79. package/dist/bundle/{chunk-36B7AIGP.js → chunk-YWIU4HOT.js} +1 -1
  80. package/dist/bundle/{chunk-MKCNUI72.js → chunk-ZHYRHERD.js} +2 -2
  81. package/dist/bundle/{chunk-YV4ABH6J.js → chunk-ZMNYK3FC.js} +5 -5
  82. package/dist/bundle/command-contract-T3EO5AYD.js +39 -0
  83. package/dist/bundle/{decode-XTOMXMGN.js → decode-62A3HGPW.js} +8 -8
  84. package/dist/bundle/{dispatch-T6TW2JJB.js → dispatch-IE7PBEQC.js} +9 -9
  85. package/dist/bundle/drive.js +12 -12
  86. package/dist/bundle/{echarts-RKKIOYVV.js → echarts-BGBPRGR5.js} +2 -2
  87. package/dist/bundle/{embed-STHKKA6G.js → embed-J3IBVV2V.js} +9 -9
  88. package/dist/bundle/{embedder-3XZEWHRO.js → embedder-QFPMDRT2.js} +12 -12
  89. package/dist/bundle/entry-YQSYER66.js +22 -0
  90. package/dist/bundle/{failure-DNQYXP2T.js → failure-BKOGBMIC.js} +4 -4
  91. package/dist/bundle/first-run-ZIFPVZAI.js +30 -0
  92. package/dist/bundle/first-screen-L5U26EY7.js +37 -0
  93. package/dist/bundle/{google-BYNSAIQI.js → google-RXM2XEPD.js} +13 -13
  94. package/dist/bundle/{google-api-4VTZH7OP.js → google-api-NC65BZO4.js} +83 -64
  95. package/dist/bundle/grants-SEWUYYH3.js +105 -0
  96. package/dist/bundle/{identity-ARDPFYV5.js → identity-PI6F2GWA.js} +6 -6
  97. package/dist/bundle/{instructions-N3OH5X2Y.js → instructions-6LPDSKAD.js} +1 -1
  98. package/dist/bundle/{login-4VQEC7VI.js → login-HTY7GT2S.js} +66 -68
  99. package/dist/bundle/{mcp-WBHKX5E3.js → mcp-PPVOM4SE.js} +2 -2
  100. package/dist/bundle/{node-YU5JBNAA.js → node-IB246NCQ.js} +2 -2
  101. package/dist/bundle/{node-sqlite-3C6PSBIW.js → node-sqlite-G2Y5SFJM.js} +9 -9
  102. package/dist/bundle/oauth-MWBKBI4T.js +22 -0
  103. package/dist/bundle/{open-M2V2VYXO.js → open-WD4GFSJD.js} +8 -8
  104. package/dist/bundle/{openai-ST2IWNUX.js → openai-QVM4PMY7.js} +17 -17
  105. package/dist/bundle/{process-PYNNBBTV.js → process-SWPJGPQC.js} +1 -1
  106. package/dist/bundle/{program-Q4VWV2MR.js → program-WHYFAMXR.js} +142 -106
  107. package/dist/bundle/prompt-OVYCGZB7.js +17 -0
  108. package/dist/bundle/{reasons-LOQ5J73F.js → reasons-Q34DQWB6.js} +5 -5
  109. package/dist/bundle/{recognize-FBLMWXNE.js → recognize-DM3YWHSE.js} +7 -7
  110. package/dist/bundle/{remote-XC3OXE4T.js → remote-KXVWRK7J.js} +10 -10
  111. package/dist/bundle/{rerank-2XMKKF4S.js → rerank-TINXM3MY.js} +10 -10
  112. package/dist/bundle/{serve-Q2BQHNZB.js → serve-IY2WL656.js} +12 -12
  113. package/dist/bundle/server-EMWVVT2C.js +70 -0
  114. package/dist/bundle/{server-42HPV3AH.js → server-VPY3OWPC.js} +44 -44
  115. package/dist/bundle/{services-WU22S2MU.js → services-PXNBOCOC.js} +34 -32
  116. package/dist/bundle/{sqlite-runtime-CSO6K6B2.js → sqlite-runtime-5ZK2CV7Y.js} +9 -9
  117. package/dist/bundle/{start-TZWKM4AH.js → start-LDVCN3DK.js} +7 -7
  118. package/dist/bundle/{state-FLUT7U7R.js → state-3MKTT3VS.js} +9 -9
  119. package/dist/bundle/{store-TG6622NG.js → store-4VQOT5IJ.js} +18 -18
  120. package/dist/bundle/{store-HDWMJ44E.js → store-7M4MSUJV.js} +28 -22
  121. package/dist/bundle/store-maintenance-command-NRATYBWD.js +60 -0
  122. package/dist/bundle/tokens-XUKLM3SL.js +103 -0
  123. package/dist/commands/config.d.ts.map +1 -1
  124. package/dist/commands/config.js +15 -6
  125. package/dist/commands/config.js.map +1 -1
  126. package/dist/commands/context.d.ts +4 -2
  127. package/dist/commands/context.d.ts.map +1 -1
  128. package/dist/commands/context.js.map +1 -1
  129. package/dist/commands/session.d.ts.map +1 -1
  130. package/dist/commands/session.js +15 -4
  131. package/dist/commands/session.js.map +1 -1
  132. package/dist/config.d.ts +23 -5
  133. package/dist/config.d.ts.map +1 -1
  134. package/dist/config.js +33 -20
  135. package/dist/config.js.map +1 -1
  136. package/dist/download.d.ts +3 -2
  137. package/dist/download.d.ts.map +1 -1
  138. package/dist/download.js +21 -9
  139. package/dist/download.js.map +1 -1
  140. package/dist/errors.js +4 -4
  141. package/dist/errors.js.map +1 -1
  142. package/dist/google-api.d.ts +3 -1
  143. package/dist/google-api.d.ts.map +1 -1
  144. package/dist/google-api.js +27 -7
  145. package/dist/google-api.js.map +1 -1
  146. package/dist/login.d.ts.map +1 -1
  147. package/dist/login.js +4 -6
  148. package/dist/login.js.map +1 -1
  149. package/dist/program.d.ts.map +1 -1
  150. package/dist/program.js +11 -7
  151. package/dist/program.js.map +1 -1
  152. package/dist/reasons.d.ts +1 -1
  153. package/dist/reasons.d.ts.map +1 -1
  154. package/dist/reasons.js +1 -22
  155. package/dist/reasons.js.map +1 -1
  156. package/dist/registry.d.ts +1 -1
  157. package/dist/registry.d.ts.map +1 -1
  158. package/dist/registry.js +2 -1
  159. package/dist/registry.js.map +1 -1
  160. package/dist/tokens.js +5 -5
  161. package/dist/tokens.js.map +1 -1
  162. package/dist/upload.js +1 -1
  163. package/dist/upload.js.map +1 -1
  164. package/dist/version.d.ts +1 -1
  165. package/dist/version.js +1 -1
  166. package/package.json +3 -3
  167. package/dist/bundle/chunk-PGKIOSN3.js +0 -249
  168. package/dist/bundle/command-contract-LQDNHZJU.js +0 -39
  169. package/dist/bundle/entry-CNOYSSSD.js +0 -22
  170. package/dist/bundle/first-run-F2SI24PK.js +0 -30
  171. package/dist/bundle/first-screen-TYYF6VXY.js +0 -37
  172. package/dist/bundle/grants-EUQXSICG.js +0 -105
  173. package/dist/bundle/oauth-D6NJFPYU.js +0 -22
  174. package/dist/bundle/prompt-MFIOJMAF.js +0 -17
  175. package/dist/bundle/server-EWZYN323.js +0 -70
  176. package/dist/bundle/store-maintenance-command-RHWRUREJ.js +0 -60
  177. package/dist/bundle/tokens-TXYURU4S.js +0 -103
  178. package/dist/oauth-application.d.ts +0 -5
  179. package/dist/oauth-application.d.ts.map +0 -1
  180. package/dist/oauth-application.js +0 -9
  181. package/dist/oauth-application.js.map +0 -1
  182. /package/dist/bundle/{chunk-LK2E2ELG.js → chunk-LU3WKZBA.js} +0 -0
@@ -1,73 +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-6CQO2FIN.js";
4
+ activeProfile,
5
+ paths
6
+ } from "./chunk-BQMIDYBA.js";
7
7
  import {
8
- commandPathKey,
9
- commandPermissions
10
- } from "./chunk-ZSMCJKGP.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
- } from "./chunk-3KNZADHJ.js";
13
+ googleError
14
+ } from "./chunk-BXR7BKM3.js";
18
15
  import {
19
16
  acquireLock
20
- } from "./chunk-A6EG7ZDS.js";
21
- import {
22
- LEVELS
23
- } from "./chunk-AD62XJKO.js";
24
- import {
25
- MAX_TEXT_CHARS
26
- } from "./chunk-IADOBOKB.js";
27
- import {
28
- DRIVE_APP
29
- } from "./chunk-MEAPA4EZ.js";
17
+ } from "./chunk-S4YK6TTG.js";
30
18
  import {
31
19
  Credentials,
32
20
  isMovedRun,
33
21
  keyringService,
34
- resolvePaths,
35
- saveConfigFile,
36
22
  systemKeyring
37
- } from "./chunk-CBM2XAEZ.js";
23
+ } from "./chunk-DCBFNBEB.js";
38
24
  import {
39
- array,
40
- boolean,
41
- integer,
42
- literal,
43
- maxValue,
44
25
  minLength,
45
- minValue,
26
+ nullable,
46
27
  number,
28
+ object,
47
29
  optional,
48
- parse,
49
- picklist,
50
30
  pipe,
51
- record,
52
- regex,
53
- strictObject,
54
- string,
55
- union
56
- } from "./chunk-3U22QTU6.js";
31
+ safeParse,
32
+ string
33
+ } from "./chunk-VYXVPYA3.js";
57
34
  import {
58
35
  CliError,
59
36
  isCliError
60
- } from "./chunk-EBLA7GXY.js";
37
+ } from "./chunk-WZ5XK74U.js";
61
38
  import {
62
39
  __name
63
40
  } from "./chunk-ZVVMGPBJ.js";
64
41
 
65
- // node_modules/.pnpm/@wirecat+cli-core@0.561.0_@wirecat+cli-base@0.75.2_commander@15.0.0_esbuild@0.28.2_type_ef328e5cd047e3c19bb2231542618c08/node_modules/@wirecat/cli-core/dist/oauth/keeper.js
66
- import { createHash as createHash2 } from "node:crypto";
67
- import { join } from "node:path";
68
- import { setTimeout as delay } from "node:timers/promises";
69
-
70
- // node_modules/.pnpm/@wirecat+cli-core@0.561.0_@wirecat+cli-base@0.75.2_commander@15.0.0_esbuild@0.28.2_type_ef328e5cd047e3c19bb2231542618c08/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
71
43
  import { createHash, randomBytes } from "node:crypto";
72
44
  import { createServer } from "node:http";
73
45
  var DEFAULT_TIMEOUT_MS = 3e5;
@@ -203,10 +175,15 @@ var authorize = /* @__PURE__ */ __name(async (options) => {
203
175
  }
204
176
  }, "authorize");
205
177
 
206
- // node_modules/.pnpm/@wirecat+cli-core@0.561.0_@wirecat+cli-base@0.75.2_commander@15.0.0_esbuild@0.28.2_type_ef328e5cd047e3c19bb2231542618c08/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
207
184
  var REQUEST_LIMIT_MS = 3e4;
208
185
  var TOKEN_LOG_EVENT = "oauth.token";
209
- var object = /* @__PURE__ */ __name((value) => {
186
+ var object2 = /* @__PURE__ */ __name((value) => {
210
187
  if (typeof value !== "object" || value === null || Array.isArray(value))
211
188
  throw new Error("not an object");
212
189
  return value;
@@ -238,17 +215,17 @@ var clientFields = /* @__PURE__ */ __name(({ client }) => ({
238
215
  }), "clientFields");
239
216
  var requestTokens = /* @__PURE__ */ __name(async (provider, params, context) => {
240
217
  const operation = params.grant_type ?? "unknown";
241
- 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");
242
219
  const again = `run ${context.signInCommand} again`;
243
220
  const response = await post(provider.tokenUrl, new URLSearchParams({ ...params, ...clientFields(context) }), context);
244
221
  if (!response) {
245
- record2("warn", { outcome: "no_response" });
222
+ record("warn", { outcome: "no_response" });
246
223
  throw new CliError("outcome_unknown", `${provider.name} token request did not finish; ${again} if it keeps failing`, {
247
224
  reason: "oauth.no-response"
248
225
  });
249
226
  }
250
227
  if (!response.ok) {
251
- record2("warn", { outcome: "rejected", status: response.status });
228
+ record("warn", { outcome: "rejected", status: response.status });
252
229
  if (response.status === 429 || response.status >= 500)
253
230
  throw new CliError("provider_unavailable", `${provider.name} token request failed (HTTP ${response.status})`, {
254
231
  status: response.status,
@@ -262,9 +239,9 @@ var requestTokens = /* @__PURE__ */ __name(async (provider, params, context) =>
262
239
  }
263
240
  let body;
264
241
  try {
265
- body = object(await response.json());
242
+ body = object2(await response.json());
266
243
  } catch {
267
- record2("error", { outcome: "unreadable_response", status: response.status });
244
+ record("error", { outcome: "unreadable_response", status: response.status });
268
245
  throw new CliError("invalid_response", `${provider.name} returned an unreadable token response; ${again}`, {
269
246
  reason: "oauth.invalid-response"
270
247
  });
@@ -273,20 +250,20 @@ var requestTokens = /* @__PURE__ */ __name(async (provider, params, context) =>
273
250
  const refreshToken = typeof body.refresh_token === "string" && body.refresh_token ? body.refresh_token : previous?.refreshToken;
274
251
  const expiresIn = body.expires_in;
275
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") {
276
- record2("error", { outcome: "invalid_response", status: response.status });
253
+ record("error", { outcome: "invalid_response", status: response.status });
277
254
  throw new CliError("invalid_response", `${provider.name} returned an invalid token response; ${again}`, {
278
255
  reason: "oauth.invalid-response"
279
256
  });
280
257
  }
281
258
  if (!refreshToken) {
282
- record2("error", { outcome: "no_refresh_token", status: response.status });
259
+ record("error", { outcome: "no_refresh_token", status: response.status });
283
260
  throw new CliError("authentication_error", `${provider.name} returned no offline refresh token; ${again}`, {
284
261
  reason: "oauth.failed"
285
262
  });
286
263
  }
287
264
  const scopes = typeof body.scope === "string" ? body.scope.split(/\s+/).filter(Boolean) : previous?.scopes ?? [];
288
265
  const tokenType = typeof body.token_type === "string" ? body.token_type : previous?.tokenType;
289
- record2("info", {
266
+ record("info", {
290
267
  outcome: "received",
291
268
  status: response.status,
292
269
  ...previous ? { rotated: refreshToken !== previous.refreshToken } : {}
@@ -320,7 +297,7 @@ var revokeToken = /* @__PURE__ */ __name(async (provider, tokens, context) => {
320
297
  });
321
298
  }, "revokeToken");
322
299
 
323
- // node_modules/.pnpm/@wirecat+cli-core@0.561.0_@wirecat+cli-base@0.75.2_commander@15.0.0_esbuild@0.28.2_type_ef328e5cd047e3c19bb2231542618c08/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
324
301
  var inFlight = /* @__PURE__ */ new Map();
325
302
  var refreshedInMemory = /* @__PURE__ */ new Map();
326
303
  var tokenKeeper = /* @__PURE__ */ __name((options) => {
@@ -482,9 +459,9 @@ var tokenKeeper = /* @__PURE__ */ __name((options) => {
482
459
  };
483
460
  }, "tokenKeeper");
484
461
 
485
- // node_modules/.pnpm/@wirecat+cli-core@0.561.0_@wirecat+cli-base@0.75.2_commander@15.0.0_esbuild@0.28.2_type_ef328e5cd047e3c19bb2231542618c08/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
486
463
  var invalid = /* @__PURE__ */ __name(() => new CliError("authentication_error", "the saved sign-in cannot be read; sign in again", { reason: "oauth.invalid" }), "invalid");
487
- var parse2 = /* @__PURE__ */ __name((raw) => {
464
+ var parse = /* @__PURE__ */ __name((raw) => {
488
465
  let value;
489
466
  try {
490
467
  value = JSON.parse(raw);
@@ -501,7 +478,7 @@ var previousOf = /* @__PURE__ */ __name((raw) => {
501
478
  if (raw === void 0)
502
479
  return {};
503
480
  try {
504
- return parse2(raw);
481
+ return parse(raw);
505
482
  } catch {
506
483
  return {};
507
484
  }
@@ -509,7 +486,7 @@ var previousOf = /* @__PURE__ */ __name((raw) => {
509
486
  var defined = /* @__PURE__ */ __name((value) => Object.fromEntries(Object.entries(value).filter(([, field]) => field !== void 0)), "defined");
510
487
  var driveSessionCodec = {
511
488
  decode: /* @__PURE__ */ __name((raw) => {
512
- const value = parse2(raw);
489
+ const value = parse(raw);
513
490
  const tokens = value.tokens;
514
491
  if (typeof tokens !== "object" || tokens === null || Array.isArray(tokens))
515
492
  throw invalid();
@@ -519,7 +496,11 @@ var driveSessionCodec = {
519
496
  if (!refreshToken || !clientId || typeof value.principal !== "string")
520
497
  throw invalid();
521
498
  return {
522
- client: defined({ clientId, clientSecret: text(value.clientSecret) }),
499
+ client: defined({
500
+ clientId,
501
+ clientSecret: text(value.clientSecret),
502
+ source: text(value.clientSource)
503
+ }),
523
504
  tokens: defined({
524
505
  accessToken: text(fields.access_token),
525
506
  refreshToken,
@@ -537,6 +518,7 @@ var driveSessionCodec = {
537
518
  ...extra,
538
519
  clientId: client.clientId,
539
520
  ...client.clientSecret ? { clientSecret: client.clientSecret } : {},
521
+ ...client.source ? { clientSource: client.source } : {},
540
522
  tokens: defined({
541
523
  ...oldTokens,
542
524
  access_token: tokens.accessToken,
@@ -560,20 +542,20 @@ var keyringFailure = /* @__PURE__ */ __name((thrown, secret) => {
560
542
  var credentialStorage = /* @__PURE__ */ __name((options) => {
561
543
  if (!options.credentials.keyring)
562
544
  throw new CliError("configuration_error", "a sign-in store needs its keyring passed in, never a default");
563
- const credentials = new Credentials(options.credentials);
545
+ const credentials2 = new Credentials(options.credentials);
564
546
  const { account, codec } = options;
565
547
  const moved = options.credentials.isolated === true || options.credentials.keyring === systemKeyring && isMovedRun({ appName: options.credentials.service, env: options.credentials.env ?? process.env });
566
548
  const service = keyringService(options.credentials.service, options.credentials.configDir, options.credentials.isolated);
567
549
  const raw = /* @__PURE__ */ __name((name) => {
568
550
  try {
569
- return credentials.read(name)?.secret;
551
+ return credentials2.read(name)?.secret;
570
552
  } catch (error) {
571
553
  throw keyringFailure(error);
572
554
  }
573
555
  }, "raw");
574
556
  const save = /* @__PURE__ */ __name((value, writeOptions) => {
575
557
  try {
576
- credentials.write(account, value, writeOptions);
558
+ credentials2.write(account, value, writeOptions);
577
559
  } catch (error) {
578
560
  throw keyringFailure(error, value);
579
561
  }
@@ -606,7 +588,7 @@ var credentialStorage = /* @__PURE__ */ __name((options) => {
606
588
  write: /* @__PURE__ */ __name((input, writeOptions) => save(codec.encode({ ...input, previous: raw(account) }), writeOptions), "write"),
607
589
  remove: /* @__PURE__ */ __name(() => {
608
590
  try {
609
- return credentials.remove(account);
591
+ return credentials2.remove(account);
610
592
  } catch (error) {
611
593
  throw keyringFailure(error);
612
594
  }
@@ -614,296 +596,212 @@ var credentialStorage = /* @__PURE__ */ __name((options) => {
614
596
  };
615
597
  }, "credentialStorage");
616
598
 
617
- // node_modules/.pnpm/@wirecat+cli-core@0.561.0_@wirecat+cli-base@0.75.2_commander@15.0.0_esbuild@0.28.2_type_ef328e5cd047e3c19bb2231542618c08/node_modules/@wirecat/cli-core/dist/oauth/client-file.js
618
- import { readFileSync } from "node:fs";
619
- var readClientFile = /* @__PURE__ */ __name((location, options = {}) => {
620
- if (!options.shipped && typeof location === "string") {
621
- const mode = privateFiles({ files: [location], dirs: [] }, options.platform);
622
- if (mode.checked && !mode.ok)
623
- 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" });
624
- }
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) => {
625
625
  try {
626
- const { installed } = JSON.parse(readFileSync(location, "utf8"));
627
- const { client_id: clientId, client_secret: clientSecret } = installed;
628
- if (typeof clientId !== "string" || !clientId)
629
- throw new TypeError("client_id");
630
- if (clientSecret !== void 0 && typeof clientSecret !== "string")
631
- throw new TypeError("client_secret");
632
- return { clientId, ...clientSecret ? { clientSecret } : {} };
626
+ credentials(env, storage, keyring).write(name, JSON.stringify(session));
633
627
  } catch {
634
- 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" });
628
+ throw notSaved();
635
629
  }
636
- }, "readClientFile");
637
-
638
- // dist/policy-keys.js
639
- var permissionKeys = /* @__PURE__ */ __name((paths2) => {
640
- const keys = /* @__PURE__ */ new Set([
641
- "mcp.authority",
642
- "mcp",
643
- "sheets.create",
644
- "sheets.rename",
645
- "sheets.insert",
646
- "sheets.format",
647
- "sheets.update"
648
- ]);
649
- for (const path of paths2)
650
- keys.add(path.join("."));
651
- for (const operation of operations)
652
- for (const key of methodPolicyKeys(operation.id))
653
- keys.add(key);
654
- return keys;
655
- }, "permissionKeys");
656
- var permissionNames = /* @__PURE__ */ __name((keys) => {
657
- const names = /* @__PURE__ */ new Set();
658
- for (const key of keys) {
659
- const parts = key.split(".");
660
- for (let end = 1; end <= parts.length; end++)
661
- names.add(parts.slice(0, end).join("."));
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
+ });
662
668
  }
663
- return names;
664
- }, "permissionNames");
665
- var DEFAULT_LEVELS = {
666
- "mcp.authority": "deny",
667
- ...Object.fromEntries(operations.filter((op) => op.effect === "destructive").map((op) => [`api.${op.id}`, "ask"]))
668
- };
669
- var methodPolicyKeys = /* @__PURE__ */ __name((method, body) => {
670
- const parts = method.split(".");
671
- const verb = parts.at(-1);
672
- 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;
673
- const keys = [`api.${method}`, ...alias ? [alias] : []];
674
- if (method === "drive.replies.create" && body)
675
- keys.push(body.action === "resolve" ? "comments.resolve" : body.action === "reopen" ? "comments.reopen" : "comments.reply");
676
- if (method === "drive.replies.create" && body?.content !== void 0)
677
- keys.push("comments.reply");
678
- if (method === "sheets.spreadsheets.batchUpdate" && Array.isArray(body?.requests)) {
679
- const object2 = /* @__PURE__ */ __name((value) => !!value && typeof value === "object" && !Array.isArray(value), "object");
680
- for (const request of body.requests) {
681
- if (!object2(request))
682
- continue;
683
- if (request.addSheet || request.duplicateSheet)
684
- keys.push("sheets.create");
685
- if (object2(request.updateSheetProperties)) {
686
- const update = request.updateSheetProperties;
687
- if (object2(update.properties) && update.properties.title !== void 0 || String(update.fields).split(",").some((field) => field.trim() === "title" || field.trim() === "*"))
688
- keys.push("sheets.rename");
689
- if (object2(update.properties) && update.properties.gridProperties)
690
- keys.push("sheets.insert");
691
- }
692
- if (request.insertDimension || request.appendDimension || request.insertRange)
693
- keys.push("sheets.insert");
694
- if (request.repeatCell || request.updateCells || request.appendCells || request.updateBorders || request.addConditionalFormatRule || request.updateConditionalFormatRule || request.deleteConditionalFormatRule || request.addBanding || request.updateBanding || request.deleteBanding)
695
- keys.push("sheets.format");
696
- if (request.updateCells || request.appendCells || request.findReplace || request.pasteData || request.copyPaste || request.cutPaste || request.autoFill)
697
- keys.push("sheets.update");
698
- if (request.pasteData || request.copyPaste || request.cutPaste || request.autoFill)
699
- keys.push("sheets.format");
700
- 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))
701
- keys.push("sheets.update");
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
+ });
702
699
  }
703
- }
704
- return [...new Set(keys)];
705
- }, "methodPolicyKeys");
706
-
707
- // dist/config.js
708
- import { readFileSync as readFileSync2 } from "node:fs";
709
- import { join as join2 } from "node:path";
710
-
711
- // dist/oauth-application.js
712
- var WIRECAT_APPLICATION = Object.freeze({
713
- clientId: "240274586781-vssrlm9c0l3n1ti12ce7tg95ro4bghal.apps.googleusercontent.com",
714
- // biome-ignore lint/security/noSecrets: public installed-app OAuth identity, non-confidential per Google native-app guidance
715
- clientSecret: "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"
716
- // gitleaks:allow -- public installed-app identity
717
- });
718
-
719
- // dist/config.js
720
- var Common = {
721
- ...AI_ENTRIES,
722
- permissions: optional(record(string(), picklist(LEVELS))),
723
- max_text_chars: optional(pipe(number(), integer(), minValue(1), maxValue(MAX_TEXT_CHARS)))
724
- };
725
- var RunSettings = {
726
- record: optional(boolean()),
727
- keep_runs_for_days: optional(pipe(number(), integer(), minValue(1))),
728
- keep_successful_runs_for_days: optional(pipe(number(), integer(), minValue(1))),
729
- runs_size_limit_mb: optional(pipe(number(), integer(), minValue(1))),
730
- record_input: optional(union([boolean(), literal("failed")]))
731
- };
732
- var SharedDefaults = {
733
- limit: optional(pipe(number(), integer(), minValue(1))),
734
- sends_per_hour: optional(pipe(number(), integer(), minValue(0))),
735
- update_check: optional(boolean()),
736
- skill_hint: optional(boolean())
737
- };
738
- var DEFAULTS_ONLY = /* @__PURE__ */ new Set([...Object.keys(RunSettings), "update_check", "skill_hint"]);
739
- var SETTING_NAMES = /* @__PURE__ */ new Set([...Object.keys(Common), "picture_search", ...DEFAULTS_ONLY]);
740
- var Mirror = strictObject({
741
- id: pipe(string(), regex(/^[a-z0-9-]{1,40}$/)),
742
- path: pipe(string(), minLength(1)),
743
- folder: pipe(string(), regex(/^[A-Za-z0-9_-]{1,200}$/))
744
- });
745
- var Profile = strictObject({
746
- principal: string(),
747
- roots: optional(array(pipe(string(), regex(/^[A-Za-z0-9_-]{1,200}$/))), []),
748
- mirrors: optional(array(Mirror)),
749
- storage: picklist(["keyring", "file"]),
750
- picture_search: optional(boolean()),
751
- ...Common
752
- });
753
- var ConfigSchema = strictObject({
754
- profiles: optional(record(string(), Profile), {}),
755
- defaults: optional(strictObject({ ...Common, ...RunSettings, ...SharedDefaults }))
756
- });
757
- var keyOf = /* @__PURE__ */ __name((path) => {
758
- if (path[0] !== "api" || path[1] === void 0)
759
- return commandPathKey(path);
760
- if (["call", "list", "show"].includes(path[1]))
761
- return null;
762
- const operation = operations.find((one) => one.command === path[1]);
763
- return operation ? `api.${operation.id}` : commandPathKey(path);
764
- }, "keyOf");
765
- var configuration = settingsFor(DRIVE_APP, {
766
- // drive's own schema decides what the file may hold, so `doctor` names a profile that lacks its principal.
767
- schema: ConfigSchema,
768
- profile: {
769
- principal: optional(string()),
770
- roots: optional(array(pipe(string(), regex(/^[A-Za-z0-9_-]{1,200}$/)))),
771
- mirrors: optional(array(Mirror)),
772
- storage: optional(picklist(["keyring", "file"])),
773
- max_text_chars: Common.max_text_chars
774
- },
775
- permissions: commandPermissions({ keyOf, extra: [...permissionKeys([])], defaults: DEFAULT_LEVELS })
776
- });
777
- var paths = /* @__PURE__ */ __name((env) => resolvePaths({ appName: "drive-cli", prefix: "DRIVE", env }), "paths");
778
- var configPath = /* @__PURE__ */ __name((env) => join2(paths(env).config, "config.json"), "configPath");
779
- var TOOL = "drive";
780
- var isNode = /* @__PURE__ */ __name((value) => typeof value === "object" && value !== null && !Array.isArray(value), "isNode");
781
- var withoutIncomplete = /* @__PURE__ */ __name((raw, issues) => {
782
- const incomplete = new Set(issues.flatMap((issue) => issue.kind === "missing_setting" && issue.profile ? [issue.profile] : []));
783
- if (!incomplete.size || !isNode(raw) || !isNode(raw.profiles))
784
- return void 0;
785
- return {
786
- ...raw,
787
- profiles: Object.fromEntries(Object.entries(raw.profiles).filter(([name]) => !incomplete.has(name)))
788
- };
789
- }, "withoutIncomplete");
790
- var examine = /* @__PURE__ */ __name((text2, file, knownPermissions) => {
791
- const check = /* @__PURE__ */ __name((body) => checkConfigText(body, { file, tool: TOOL, schema: ConfigSchema, ...knownPermissions ? { knownPermissions } : {} }), "check");
792
- const first = check(text2);
793
- if (first.issues.some((issue) => issue.kind === "invalid_json"))
794
- return { raw: {}, config: { profiles: {} }, issues: first.issues };
795
- const raw = JSON.parse(text2);
796
- if (first.config)
797
- return { raw, config: first.config, issues: first.issues };
798
- const rest = withoutIncomplete(raw, first.issues);
799
- const second = rest && check(JSON.stringify(rest));
800
- return {
801
- raw,
802
- config: second?.config ?? { profiles: {} },
803
- // Saved permissions are checked only in what loads, and the first pass loaded nothing.
804
- issues: [...first.issues, ...(second?.issues ?? []).filter((issue) => issue.kind === "unknown_permission")]
805
700
  };
806
- }, "examine");
807
- var inspectConfig = /* @__PURE__ */ __name((env, knownPermissions) => {
808
- const path = configPath(env);
809
- 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) => {
810
707
  try {
811
- 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);
812
713
  } catch {
813
- return { path, found: false, raw: {}, config: { profiles: {} }, issues: [] };
714
+ return [];
814
715
  }
815
- return { path, found: true, ...examine(text2, path, knownPermissions) };
816
- }, "inspectConfig");
817
- var configIssues = /* @__PURE__ */ __name((raw, file, knownPermissions) => examine(JSON.stringify(raw), file, knownPermissions).issues, "configIssues");
818
- var refusal = /* @__PURE__ */ __name((issues) => new CliError("configuration_error", issueMessage(issues)), "refusal");
819
- var readConfig = /* @__PURE__ */ __name((env, knownPermissions) => {
820
- const { config, issues } = inspectConfig(env, knownPermissions);
821
- if (issues.length)
822
- throw refusal(issues);
823
- return config;
824
- }, "readConfig");
825
- var writeConfig = /* @__PURE__ */ __name((env, config) => {
826
- const [issue] = configIssues(config, "drive settings");
827
- if (issue)
828
- throw new CliError("configuration_error", `drive settings: ${issue.profile === void 0 ? "" : `profile ${issue.profile}: `}${issue.what}`);
829
- saveConfigFile(configPath(env), parse(ConfigSchema, config));
830
- }, "writeConfig");
831
- var profileName = usableProfileName;
832
- var fileId = /* @__PURE__ */ __name((input) => {
833
- let id = input;
834
- if (input.startsWith("https://")) {
835
- const url = new URL(input);
836
- if (url.hostname !== "drive.google.com" && url.hostname !== "docs.google.com")
837
- throw new CliError("validation_error", "use a Google Drive/Docs URL or file ID");
838
- 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);
839
727
  }
840
- if (!/^[A-Za-z0-9_-]{1,200}$/.test(id))
841
- throw new CliError("validation_error", "invalid Google file ID");
842
- return id;
843
- }, "fileId");
844
- 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");
845
- var activeProfile = /* @__PURE__ */ __name((env, name) => {
846
- const config = readConfig(env);
847
- const profile = config.profiles[profileName(name)];
848
- if (!profile)
849
- throw unknownProfile(name, Object.keys(config.profiles).sort());
850
- return profile;
851
- }, "activeProfile");
852
- var checkTextLimit = /* @__PURE__ */ __name((value) => {
853
- if (typeof value !== "number" || !Number.isInteger(value) || value < 1)
854
- throw new CliError("validation_error", "max_text_chars must be a positive whole number of characters");
855
- if (value > MAX_TEXT_CHARS)
856
- throw new CliError("validation_error", `max_text_chars can be at most ${MAX_TEXT_CHARS}: the document readers return at most that many characters`);
857
- return value;
858
- }, "checkTextLimit");
859
- var textLimit = /* @__PURE__ */ __name((env, name) => activeProfile(env, name).max_text_chars ?? readConfig(env).defaults?.max_text_chars ?? MAX_TEXT_CHARS, "textLimit");
860
- var pictureSearch = /* @__PURE__ */ __name((env, name) => activeProfile(env, name).picture_search ?? false, "pictureSearch");
861
- var application = /* @__PURE__ */ __name((env, file) => {
862
- if (!file) {
863
- if (!env.DRIVE_GOOGLE_CLIENT_ID) {
864
- if (env.DRIVE_GOOGLE_CLIENT_SECRET)
865
- throw new CliError("configuration_error", "DRIVE_GOOGLE_CLIENT_SECRET requires DRIVE_GOOGLE_CLIENT_ID");
866
- return { ...WIRECAT_APPLICATION };
867
- }
868
- return {
869
- clientId: env.DRIVE_GOOGLE_CLIENT_ID,
870
- ...env.DRIVE_GOOGLE_CLIENT_SECRET ? { clientSecret: env.DRIVE_GOOGLE_CLIENT_SECRET } : {}
871
- };
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 {
872
742
  }
873
- return readClientFile(file, {
874
- 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
+ }
875
791
  });
876
- }, "application");
877
- var selectedFolders = /* @__PURE__ */ __name((env, profile, filter = {}) => activeProfile(env, profile).roots.flatMap((id) => filter.id === void 0 || id === filter.id ? [{ id }] : []), "selectedFolders");
878
- var configuredMirrors = /* @__PURE__ */ __name((env, profile, filter = {}) => (activeProfile(env, profile).mirrors ?? []).filter((row) => Object.entries(filter).every(([key, value]) => row[key] === value)), "configuredMirrors");
879
- 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");
880
794
 
881
795
  export {
882
- tokenKeeper,
883
- driveSessionCodec,
884
- credentialStorage,
885
- permissionKeys,
886
- permissionNames,
887
- DEFAULT_LEVELS,
888
- methodPolicyKeys,
889
- DEFAULTS_ONLY,
890
- SETTING_NAMES,
891
- configuration,
892
- paths,
893
- inspectConfig,
894
- configIssues,
895
- refusal,
896
- readConfig,
897
- writeConfig,
898
- profileName,
899
- fileId,
900
- unknownProfile,
901
- activeProfile,
902
- checkTextLimit,
903
- textLimit,
904
- pictureSearch,
905
- application,
906
- selectedFolders,
907
- configuredMirrors,
908
- configuredSessions
796
+ credentials,
797
+ notSaved,
798
+ saveSession,
799
+ googleProvider,
800
+ sessionKeeper,
801
+ authorizedClient,
802
+ covers,
803
+ grantedScopes,
804
+ checkAuthorization,
805
+ operationOf,
806
+ observeRequests
909
807
  };