@wirecat/mail-cli 0.23.1 → 0.25.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 (117) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/bin/mail.js +2 -2
  3. package/dist/bundle/{all-profiles-FJHJCGRU.js → all-profiles-QEV2PSOR.js} +11 -11
  4. package/dist/bundle/{anthropic-AFL7NKVZ.js → anthropic-5NKQXIHM.js} +28 -12
  5. package/dist/bundle/{app-server-WKCBJMHI.js → app-server-G2CJNT4R.js} +62 -50
  6. package/dist/bundle/{bun-HQATAQJQ.js → bun-6HBYWQIX.js} +2 -2
  7. package/dist/bundle/{bun-sqlite-4ECAV7OU.js → bun-sqlite-DXIQ7BVR.js} +9 -5
  8. package/dist/bundle/{chunk-MUDHCYN4.js → chunk-37F6QYTO.js} +6 -6
  9. package/dist/bundle/{chunk-NMGF3UOZ.js → chunk-3XVR2ROR.js} +50 -46
  10. package/dist/bundle/{chunk-QUKD5SO2.js → chunk-434YOD6A.js} +4 -4
  11. package/dist/bundle/{chunk-7SWWVDEZ.js → chunk-4W4EVVL4.js} +61 -21
  12. package/dist/bundle/{chunk-CCYHBNRL.js → chunk-5QYK3LWS.js} +326 -56
  13. package/dist/bundle/{chunk-7YRKUEYE.js → chunk-5ZYFV6FD.js} +694 -228
  14. package/dist/bundle/chunk-7GLJSJ7M.js +16 -0
  15. package/dist/bundle/{chunk-NOA6E6MM.js → chunk-A6BPOX5O.js} +38841 -24161
  16. package/dist/bundle/{chunk-34743C4C.js → chunk-ADKMBXY4.js} +1 -1
  17. package/dist/bundle/{chunk-2HXHAFRP.js → chunk-B7SWTH5O.js} +2 -2
  18. package/dist/bundle/{chunk-NKBAZ4VC.js → chunk-BC7PFQL7.js} +2 -2
  19. package/dist/bundle/{chunk-ROKTS7WM.js → chunk-CBYBZCQP.js} +1 -1
  20. package/dist/bundle/chunk-CIWWNBVW.js +188 -0
  21. package/dist/bundle/{chunk-SBGXKM4U.js → chunk-DIA56CS7.js} +8 -7
  22. package/dist/bundle/{chunk-VYHIX3OP.js → chunk-EXVY76VO.js} +61 -607
  23. package/dist/bundle/{chunk-BVJQBAGL.js → chunk-FZZD4AFY.js} +14 -14
  24. package/dist/bundle/{chunk-VFKX5UMJ.js → chunk-G5LHHAW2.js} +6 -6
  25. package/dist/bundle/{chunk-QV3M2MHG.js → chunk-GJRYZXBN.js} +13 -136
  26. package/dist/bundle/{chunk-GJNFNC76.js → chunk-GY4XCLCO.js} +10 -15
  27. package/dist/bundle/{chunk-V7CFZ773.js → chunk-HEIDAHRC.js} +2 -2
  28. package/dist/bundle/{chunk-AGNAT7CM.js → chunk-HEYVMAAQ.js} +2 -2
  29. package/dist/bundle/{chunk-HOKGIYUO.js → chunk-HJSJBNCJ.js} +119 -9
  30. package/dist/bundle/{chunk-KKGX7JMX.js → chunk-HLXVUMZJ.js} +2 -2
  31. package/dist/bundle/{chunk-OU5CWCG2.js → chunk-IACWKZWS.js} +1 -1
  32. package/dist/bundle/{chunk-QR7JZM3D.js → chunk-IXO4SCKE.js} +1 -1
  33. package/dist/bundle/{chunk-GOMJNH56.js → chunk-IZOYW4Z4.js} +32 -8
  34. package/dist/bundle/{chunk-WN4HP7IZ.js → chunk-J4OYK4WL.js} +14 -14
  35. package/dist/bundle/{chunk-76RTQYJQ.js → chunk-JG4MNYG2.js} +1 -1
  36. package/dist/bundle/{chunk-VAMCRP47.js → chunk-K2OGF7KC.js} +2 -2
  37. package/dist/bundle/chunk-K6HR6HCO.js +32 -0
  38. package/dist/bundle/{chunk-B6QMMRIM.js → chunk-KFB2X6KE.js} +1530 -1525
  39. package/dist/bundle/{chunk-3UFD76IR.js → chunk-KK4HD3SI.js} +6 -6
  40. package/dist/bundle/{chunk-3QVGB2CI.js → chunk-L4QVOEOB.js} +4 -4
  41. package/dist/bundle/chunk-LGZPKKBN.js +53 -0
  42. package/dist/bundle/chunk-LVGX7VTD.js +138 -0
  43. package/dist/bundle/chunk-MBFPFWCO.js +1243 -0
  44. package/dist/bundle/{chunk-3DQYO7FB.js → chunk-MCPOZNWG.js} +1 -1
  45. package/dist/bundle/{chunk-SR3ADLGX.js → chunk-MWGH3M46.js} +3 -3
  46. package/dist/bundle/{chunk-OJCUSHZG.js → chunk-ND5H5ADM.js} +4 -4
  47. package/dist/bundle/chunk-NMZQTYKJ.js +18 -0
  48. package/dist/bundle/{chunk-4YJJQNNJ.js → chunk-OLKCJBZY.js} +5 -5
  49. package/dist/bundle/{chunk-E7ZVKQHG.js → chunk-OLLIWNFG.js} +3 -3
  50. package/dist/bundle/{chunk-R5MYOLQP.js → chunk-P6GXNT7Z.js} +13 -13
  51. package/dist/bundle/{chunk-M7RGG3UU.js → chunk-PGC5TRH6.js} +3 -3
  52. package/dist/bundle/{chunk-3OZKDC6Y.js → chunk-PHHH2NQP.js} +15 -9
  53. package/dist/bundle/{chunk-S5OTP7XS.js → chunk-PP3YOAWG.js} +3 -3
  54. package/dist/bundle/{chunk-4IFX4HV2.js → chunk-PQMJ5BXH.js} +4 -4
  55. package/dist/bundle/{chunk-ZXIPJF3Y.js → chunk-QB3DP2TN.js} +2 -2
  56. package/dist/bundle/{chunk-4IWJARFA.js → chunk-QQUY4MZY.js} +1 -1
  57. package/dist/bundle/{chunk-UHC5I3JV.js → chunk-RX5CJ55S.js} +1 -1
  58. package/dist/bundle/{chunk-CYQVWITQ.js → chunk-S2QRAKQI.js} +99 -42
  59. package/dist/bundle/{chunk-V3TDQUXD.js → chunk-SMTBV62X.js} +44 -60
  60. package/dist/bundle/{chunk-SNTLN2QT.js → chunk-T27IMG6X.js} +3 -1
  61. package/dist/bundle/{chunk-LLYVBO3R.js → chunk-TY644DKQ.js} +19 -19
  62. package/dist/bundle/{chunk-R554W7ZO.js → chunk-U6IQ6YQ2.js} +2 -2
  63. package/dist/bundle/{chunk-MBKNL5TX.js → chunk-VFU7PVPQ.js} +373 -133
  64. package/dist/bundle/{chunk-UMXVQIGD.js → chunk-VL6H2BND.js} +377 -12
  65. package/dist/bundle/{chunk-DALBYUPC.js → chunk-VUBZFMGP.js} +2 -2
  66. package/dist/bundle/{chunk-VYIIX6VN.js → chunk-WOAYHCM2.js} +1 -1
  67. package/dist/bundle/{chunk-LQDMUMA2.js → chunk-WX6OYVCH.js} +5370 -3700
  68. package/dist/bundle/chunk-XMDEM6BZ.js +2094 -0
  69. package/dist/bundle/{chunk-CUOCDJFI.js → chunk-XQYKIZMG.js} +13 -9
  70. package/dist/bundle/{chunk-PMIKRELC.js → chunk-YNS2YVUR.js} +69 -6
  71. package/dist/bundle/{chunk-CBWA2T3N.js → chunk-Z5T6OW3V.js} +14 -5
  72. package/dist/bundle/command-contract-XSW2Q33S.js +36 -0
  73. package/dist/bundle/command-server-entry-XMSSY5ID.js +165 -0
  74. package/dist/bundle/{decode-QXKTMOTH.js → decode-RYGB4PGT.js} +5 -5
  75. package/dist/bundle/{dispatch-G4CYFWQ2.js → dispatch-PLQOIZG5.js} +10 -10
  76. package/dist/bundle/{dist-5FX36DAW.js → dist-GY2AQETI.js} +79 -46
  77. package/dist/bundle/{echarts-HHUM43TU.js → echarts-7CM2MCMW.js} +2 -2
  78. package/dist/bundle/{embed-SRZSDZVI.js → embed-FTBDPOPT.js} +6 -6
  79. package/dist/bundle/{embedder-WZIZCWLX.js → embedder-B43WGNBD.js} +9 -9
  80. package/dist/bundle/{failure-FFPK2WYB.js → failure-XP5QYV2T.js} +2 -2
  81. package/dist/bundle/{first-run-6DVWZ3JQ.js → first-run-XIIUARNM.js} +12 -11
  82. package/dist/bundle/first-screen-Z7HC6PQU.js +34 -0
  83. package/dist/bundle/{instructions-UWONE6UT.js → instructions-R7OHVAWH.js} +1 -1
  84. package/dist/bundle/mail.js +37 -13
  85. package/dist/bundle/{mcp-CFVG2OUS.js → mcp-7KQUJNFN.js} +2 -2
  86. package/dist/bundle/{node-HLAOYJDB.js → node-3N2JGZ7V.js} +2 -2
  87. package/dist/bundle/{node-sqlite-RO66I7W6.js → node-sqlite-WFJXW3CZ.js} +10 -6
  88. package/dist/bundle/{oauth-VNLB2TET.js → oauth-SVJLQTWV.js} +7 -7
  89. package/dist/bundle/{open-QQSG343L.js → open-ZDONVKSX.js} +5 -5
  90. package/dist/bundle/{openai-JTFC7OGF.js → openai-XVEW6XOU.js} +21 -38
  91. package/dist/bundle/{process-3CZAXR6P.js → process-YAHHUFR5.js} +1 -1
  92. package/dist/bundle/{program-XTOS4RAM.js → program-HU2UVMJE.js} +7071 -5421
  93. package/dist/bundle/{prompt-HGQ6GPYL.js → prompt-JAJ2CUJI.js} +5 -5
  94. package/dist/bundle/{recognize-2SHMNEIZ.js → recognize-UFBWUNFR.js} +4 -4
  95. package/dist/bundle/{remote-GBQC3433.js → remote-2GFOVLCR.js} +9 -7
  96. package/dist/bundle/{rerank-FQHQXFNR.js → rerank-BGPSMXTL.js} +7 -7
  97. package/dist/bundle/{serve-THU67QUZ.js → serve-CB3XJTH3.js} +9 -9
  98. package/dist/bundle/server-34GEF22R.js +68 -0
  99. package/dist/bundle/{server-LOT3CLYX.js → server-M7FQY7TX.js} +42 -40
  100. package/dist/bundle/{sqlite-runtime-NOOUMBC4.js → sqlite-runtime-AEV6PGDR.js} +6 -6
  101. package/dist/bundle/{state-KSKZCV2U.js → state-YLBEQLBI.js} +6 -6
  102. package/dist/bundle/{store-BAKSHTKF.js → store-CDUL3HKK.js} +19 -16
  103. package/dist/bundle/{store-OHNZOQ7U.js → store-EKWKY6GG.js} +49 -20
  104. package/dist/bundle/store-maintenance-command-XH2JUM5F.js +58 -0
  105. package/dist/config.d.ts +4 -0
  106. package/dist/config.d.ts.map +1 -1
  107. package/dist/version.d.ts +1 -1
  108. package/dist/version.js +1 -1
  109. package/package.json +3 -3
  110. package/dist/bundle/chunk-5UKBUI4I.js +0 -35
  111. package/dist/bundle/chunk-EXPR6QAX.js +0 -394
  112. package/dist/bundle/chunk-FWFNUJQD.js +0 -12172
  113. package/dist/bundle/command-contract-IIHBNF7J.js +0 -35
  114. package/dist/bundle/first-screen-SRZ7NYHZ.js +0 -33
  115. package/dist/bundle/server-VKMUX7ZT.js +0 -65
  116. package/dist/bundle/store-maintenance-command-ROQHJVEA.js +0 -54
  117. /package/dist/bundle/{chunk-QZLK2ISN.js → chunk-YVNHQFLC.js} +0 -0
@@ -2,23 +2,23 @@ import { createRequire as __bundleRequire } from "node:module";
2
2
  const require = __bundleRequire(import.meta.url);
3
3
  import {
4
4
  storePath
5
- } from "./chunk-5UKBUI4I.js";
5
+ } from "./chunk-LGZPKKBN.js";
6
6
  import {
7
7
  resolvePaths
8
- } from "./chunk-LLYVBO3R.js";
8
+ } from "./chunk-TY644DKQ.js";
9
9
  import {
10
10
  CliError,
11
11
  singleLine
12
- } from "./chunk-DALBYUPC.js";
12
+ } from "./chunk-VUBZFMGP.js";
13
13
  import {
14
14
  __name
15
15
  } from "./chunk-ZVVMGPBJ.js";
16
16
 
17
- // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_89df442a19027064da492ef27322716d/node_modules/@wirecat/cli-core/dist/store/shared-config.js
17
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/store/shared-config.js
18
18
  import { mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
19
19
  import { dirname, join, resolve } from "node:path";
20
20
 
21
- // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_89df442a19027064da492ef27322716d/node_modules/@wirecat/cli-core/dist/domain/task-categories.js
21
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/domain/task-categories.js
22
22
  var DEFAULT_TASK_CATEGORIES = [
23
23
  {
24
24
  name: "taxes",
@@ -773,7 +773,7 @@ var storedTaskCategories = /* @__PURE__ */ __name((json) => {
773
773
  }
774
774
  }, "storedTaskCategories");
775
775
 
776
- // node_modules/.pnpm/@wirecat+cli-core@0.618.0_@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_type_89df442a19027064da492ef27322716d/node_modules/@wirecat/cli-core/dist/store/shared-config.js
776
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/store/shared-config.js
777
777
  var SECTION = "task_categories";
778
778
  var sharedConfigPath = /* @__PURE__ */ __name((store, env = process.env) => {
779
779
  const paths = resolvePaths({ appName: "WireCat", prefix: "WIRECAT", env });
@@ -3,26 +3,26 @@ const require = __bundleRequire(import.meta.url);
3
3
  import {
4
4
  executableEnvironment,
5
5
  executableOnPath
6
- } from "./chunk-3DQYO7FB.js";
6
+ } from "./chunk-MCPOZNWG.js";
7
7
  import {
8
8
  require_cross_spawn
9
9
  } from "./chunk-D72URWJE.js";
10
10
  import {
11
11
  loadConfigFile,
12
12
  saveConfigFile
13
- } from "./chunk-LLYVBO3R.js";
13
+ } from "./chunk-TY644DKQ.js";
14
14
  import {
15
15
  number,
16
16
  object,
17
17
  optional,
18
18
  string
19
- } from "./chunk-GOMJNH56.js";
19
+ } from "./chunk-IZOYW4Z4.js";
20
20
  import {
21
21
  __name,
22
22
  __toESM
23
23
  } from "./chunk-ZVVMGPBJ.js";
24
24
 
25
- // node_modules/.pnpm/@wirecat+cli-base@0.80.7_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/update/index.js
25
+ // node_modules/.pnpm/@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/update/index.js
26
26
  var import_cross_spawn = __toESM(require_cross_spawn(), 1);
27
27
  import { existsSync } from "node:fs";
28
28
  var updateCommand = /* @__PURE__ */ __name((installer, packageName) => {
@@ -0,0 +1,53 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ resolvePaths
5
+ } from "./chunk-TY644DKQ.js";
6
+ import {
7
+ __name
8
+ } from "./chunk-ZVVMGPBJ.js";
9
+
10
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/store/path.js
11
+ import { realpathSync } from "node:fs";
12
+ import { userInfo } from "node:os";
13
+ import { basename, dirname, isAbsolute, join, relative, resolve } from "node:path";
14
+ var wirecatDirectory = /* @__PURE__ */ __name((env = process.env, platform) => resolvePaths({ appName: "WireCat", prefix: "WIRECAT", env, ...platform ? { platform } : {} }).state, "wirecatDirectory");
15
+ var storePath = /* @__PURE__ */ __name((env = process.env) => env.MESSAGING_STORE ?? join(wirecatDirectory(env), "wirecat.db"), "storePath");
16
+ var accountHome = /* @__PURE__ */ __name(() => {
17
+ try {
18
+ return userInfo().homedir;
19
+ } catch {
20
+ return void 0;
21
+ }
22
+ }, "accountHome");
23
+ var inOwnerFolder = /* @__PURE__ */ __name((file, home = accountHome()) => {
24
+ if (!home || file === ":memory:")
25
+ return false;
26
+ const owner = wirecatDirectory({ HOME: home, USERPROFILE: home });
27
+ const within = /* @__PURE__ */ __name((path, folder) => {
28
+ const inside = relative(folder, path);
29
+ return !(inside.startsWith("..") || isAbsolute(inside));
30
+ }, "within");
31
+ return within(resolve(file), owner) || within(settled(resolve(file)), settled(owner));
32
+ }, "inOwnerFolder");
33
+ var settled = /* @__PURE__ */ __name((path) => {
34
+ try {
35
+ return realpathSync(path);
36
+ } catch {
37
+ const parent = dirname(path);
38
+ return parent === path ? path : join(settled(parent), basename(path));
39
+ }
40
+ }, "settled");
41
+ var refuseOwnerStoreInTests = /* @__PURE__ */ __name((file, env = process.env, home = accountHome()) => {
42
+ if (!env.VITEST || !inOwnerFolder(file, home))
43
+ return;
44
+ throw new Error(`a test tried to open ${file}, in the owner's real WireCat folder; give it a MESSAGING_STORE or HOME of its own`);
45
+ }, "refuseOwnerStoreInTests");
46
+
47
+ export {
48
+ wirecatDirectory,
49
+ storePath,
50
+ accountHome,
51
+ inOwnerFolder,
52
+ refuseOwnerStoreInTests
53
+ };
@@ -0,0 +1,138 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ CliError,
5
+ isCliError
6
+ } from "./chunk-VUBZFMGP.js";
7
+ import {
8
+ __name
9
+ } from "./chunk-ZVVMGPBJ.js";
10
+
11
+ // node_modules/.pnpm/@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/http/hosts.js
12
+ var LABEL = "[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?";
13
+ var HOST_PATTERN = new RegExp(`^(?:${LABEL}(?:\\.${LABEL})*|\\*\\.${LABEL}(?:\\.${LABEL})+)$`);
14
+ var hostProblems = /* @__PURE__ */ __name((hosts) => [
15
+ ...hosts.filter((host) => !HOST_PATTERN.test(host) || host.length > 253).map((host) => `${JSON.stringify(host)} is not a host: a lower-case hostname with no scheme, port or path, or one leading *. before two labels or more`),
16
+ ...hosts.filter((host, at) => hosts.indexOf(host) !== at).map((host) => `${JSON.stringify(host)} is listed twice`)
17
+ ], "hostProblems");
18
+ var hostCovered = /* @__PURE__ */ __name((hostname, hosts) => {
19
+ const name = hostname.toLowerCase().replace(/\.$/, "");
20
+ return hosts.some((host) => host.startsWith("*.") ? name.endsWith(host.slice(1)) : name === host);
21
+ }, "hostCovered");
22
+
23
+ // node_modules/.pnpm/@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/http/fetch.js
24
+ var HOST_FETCH_TIMEOUT_MS = 3e4;
25
+ var REDIRECTS = 5;
26
+ var REDIRECT_STATUSES = /* @__PURE__ */ new Set([301, 302, 303, 307, 308]);
27
+ var CREDENTIAL_HEADERS = ["authorization", "cookie", "proxy-authorization"];
28
+ var NO_BODY = /* @__PURE__ */ new Set([204, 205, 304]);
29
+ var deadline = /* @__PURE__ */ __name((ms) => {
30
+ const controller = new AbortController();
31
+ const timer = setTimeout(() => controller.abort(new DOMException(`no answer within ${ms} ms`, "TimeoutError")), ms);
32
+ timer.unref?.();
33
+ return { signal: controller.signal, clear: /* @__PURE__ */ __name(() => clearTimeout(timer), "clear") };
34
+ }, "deadline");
35
+ var released = /* @__PURE__ */ __name((response, clear) => {
36
+ if (!response.body || NO_BODY.has(response.status) || response.status < 200 || response.status > 599) {
37
+ clear();
38
+ return response;
39
+ }
40
+ const { status, statusText, headers, url, redirected } = response;
41
+ const wrapped = new Response(response.body.pipeThrough(new TransformStream({ flush: clear })), {
42
+ status,
43
+ statusText,
44
+ headers
45
+ });
46
+ return Object.defineProperties(wrapped, { url: { value: url }, redirected: { value: redirected } });
47
+ }, "released");
48
+ var undeclared = /* @__PURE__ */ __name((url) => new CliError("configuration_error", `${url.hostname} is not a host this CLI declares: add "${url.hostname}" to \`hosts\` in its WCAT identity and run cli-dev manifest`, { reason: "network.host-undeclared", sent: false }), "undeclared");
49
+ var checked = /* @__PURE__ */ __name((url, hosts) => {
50
+ if (url.protocol !== "https:" && url.protocol !== "http:")
51
+ throw new CliError("validation_error", `only http and https are fetched, not ${url.protocol.replace(/:$/, "")}`, {
52
+ sent: false
53
+ });
54
+ if (!hostCovered(url.hostname, hosts))
55
+ throw undeclared(url);
56
+ return url;
57
+ }, "checked");
58
+ var hostFetch = /* @__PURE__ */ __name((options) => {
59
+ const problems = hostProblems(options.hosts);
60
+ if (problems.length > 0)
61
+ throw new CliError("configuration_error", problems.join("; "));
62
+ const { hosts, fetch: send = globalThis.fetch, timeoutMs = HOST_FETCH_TIMEOUT_MS, redirects = REDIRECTS } = options;
63
+ return async (input, init = {}) => {
64
+ const request = input instanceof Request ? input : void 0;
65
+ let url = checked(new URL(request?.url ?? String(input)), hosts);
66
+ const caller = init.signal ?? request?.signal;
67
+ const timeout = deadline(timeoutMs);
68
+ const signal = caller ? AbortSignal.any([caller, timeout.signal]) : timeout.signal;
69
+ const follow = (init.redirect ?? request?.redirect ?? "follow") === "follow";
70
+ let method = (init.method ?? request?.method ?? "GET").toUpperCase();
71
+ let body = init.body ?? request?.body ?? void 0;
72
+ const headers = new Headers(init.headers ?? request?.headers);
73
+ try {
74
+ let response = await send(input, { ...init, signal, ...follow ? { redirect: "manual" } : {} });
75
+ for (let hop = 0; follow && REDIRECT_STATUSES.has(response.status); hop += 1) {
76
+ const location = response.headers.get("location");
77
+ if (!location)
78
+ return released(response, timeout.clear);
79
+ if (hop >= redirects)
80
+ throw new CliError("invalid_response", `more than ${redirects} redirects from ${url.hostname}`);
81
+ void response.body?.cancel().catch(() => {
82
+ });
83
+ const next = checked(new URL(location, url), hosts);
84
+ if (response.status === 303 || (response.status === 301 || response.status === 302) && method === "POST") {
85
+ method = method === "HEAD" ? "HEAD" : "GET";
86
+ body = void 0;
87
+ headers.delete("content-type");
88
+ headers.delete("content-length");
89
+ } else if (body instanceof ReadableStream)
90
+ throw new CliError("invalid_response", `${url.hostname} redirected a streamed body, which cannot be sent again`);
91
+ if (next.origin !== url.origin)
92
+ for (const name of CREDENTIAL_HEADERS)
93
+ headers.delete(name);
94
+ url = next;
95
+ response = await send(url, { ...init, method, headers, body, signal, redirect: "manual" });
96
+ }
97
+ return released(response, timeout.clear);
98
+ } catch (error) {
99
+ timeout.clear();
100
+ if (isCliError(error))
101
+ throw error;
102
+ if (caller?.aborted)
103
+ throw isCliError(caller.reason) ? caller.reason : new CliError("cancelled", "request cancelled");
104
+ if (timeout.signal.aborted)
105
+ throw new CliError("timeout", `${url.hostname} did not answer within ${timeoutMs} ms`, { retryable: true });
106
+ throw new CliError("network_error", `${url.hostname} could not be reached`, { retryable: true });
107
+ }
108
+ };
109
+ }, "hostFetch");
110
+
111
+ // node_modules/.pnpm/@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_typescript@7.0.2_vitest@5.0.5/node_modules/@wirecat/cli-base/dist/http/index.js
112
+ var parseRetryAfter = /* @__PURE__ */ __name((header, now) => {
113
+ if (!header)
114
+ return void 0;
115
+ const trimmed = header.trim();
116
+ if (/^\d+$/.test(trimmed))
117
+ return Number(trimmed) * 1e3;
118
+ const at = Date.parse(trimmed);
119
+ if (Number.isNaN(at))
120
+ return void 0;
121
+ const delta = at - now().getTime();
122
+ return delta > 0 ? delta : void 0;
123
+ }, "parseRetryAfter");
124
+ var parseRateLimitReset = /* @__PURE__ */ __name((header, now) => {
125
+ if (!header)
126
+ return void 0;
127
+ const seconds = Number(header.trim());
128
+ if (!Number.isFinite(seconds))
129
+ return void 0;
130
+ const delta = seconds * 1e3 - now().getTime();
131
+ return delta > 0 ? delta : void 0;
132
+ }, "parseRateLimitReset");
133
+ var providerWaitMs = /* @__PURE__ */ __name((headers, now) => parseRetryAfter(headers.get("retry-after"), now) ?? parseRateLimitReset(headers.get("x-ratelimit-reset"), now), "providerWaitMs");
134
+
135
+ export {
136
+ hostFetch,
137
+ providerWaitMs
138
+ };