@pen.dev/cli 0.2.8 → 0.3.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 (113) hide show
  1. package/dist/all-BRgnaRVf.mjs +2 -0
  2. package/dist/anthropic-messages-B0UGUOMk.mjs +40 -0
  3. package/dist/anthropic-messages-Bdjz4-4h.mjs +40 -0
  4. package/dist/azure-openai-responses-DGGHC-S9.mjs +2 -0
  5. package/dist/azure-openai-responses-Dcn9uJAW.mjs +2 -0
  6. package/dist/browserAll-B9bGRQuq.mjs +2 -0
  7. package/dist/deferred-tools-B1EgE_tY.mjs +2 -0
  8. package/dist/deferred-tools-DowE4eb1.mjs +2 -0
  9. package/dist/diagnostics-D0oRYjyK.mjs +2 -0
  10. package/dist/diagnostics-DZacjHpY.mjs +2 -0
  11. package/dist/{dist-BMO4tFTj.mjs → dist-YY0wuD4v.mjs} +361 -416
  12. package/dist/error-body-RPMBLEAJ.mjs +2 -0
  13. package/dist/event-stream-BrGAtXMV.mjs +2 -0
  14. package/dist/event-stream-CXocIcc6.mjs +2 -0
  15. package/dist/google-generative-ai-6QyLi6xj.mjs +2 -0
  16. package/dist/google-generative-ai-BG0mJ2Yd.mjs +2 -0
  17. package/dist/{google-shared-YCDndJGN.mjs → google-shared-BIfd6JKP.mjs} +2 -2
  18. package/dist/{google-shared-TkwodIGJ.mjs → google-shared-CgKgcf0q.mjs} +2 -2
  19. package/dist/google-vertex-CBwir-qy.mjs +2 -0
  20. package/dist/google-vertex-DlS7-xf8.mjs +2 -0
  21. package/dist/index.mjs +2 -2
  22. package/dist/{mistral-conversations-DIR6EyvH.mjs → mistral-conversations-BS3W7xJY.mjs} +2 -2
  23. package/dist/{mistral-conversations-JED5QLUZ.mjs → mistral-conversations-Bm5cpZKX.mjs} +1 -1
  24. package/dist/models-BZPNtJp1.mjs +2 -0
  25. package/dist/models-bnt621e8.mjs +2 -0
  26. package/dist/{multipart-parser-CYJPmLQW.mjs → multipart-parser-Ce015IGH.mjs} +1 -1
  27. package/dist/{multipart-parser-4wzMiNnD.mjs → multipart-parser-u0QlX_zW.mjs} +1 -1
  28. package/dist/openai-codex-responses-BJOfgqHD.mjs +8 -0
  29. package/dist/openai-codex-responses-DstMs9PK.mjs +8 -0
  30. package/dist/openai-completions-D81vzTqd.mjs +6 -0
  31. package/dist/openai-completions-mzPR2_al.mjs +6 -0
  32. package/dist/openai-responses-BpQ7bzV4.mjs +2 -0
  33. package/dist/openai-responses-BsyyuOSg.mjs +2 -0
  34. package/dist/openai-responses-shared-DujHRX-u.mjs +11 -0
  35. package/dist/openai-responses-shared-Nr5Yi_N5.mjs +11 -0
  36. package/dist/{openrouter-images-NEnwWNeg.mjs → openrouter-images-DEF66Jtk.mjs} +1 -1
  37. package/dist/openrouter-images-XPGQk4Yu.mjs +2 -0
  38. package/dist/{otel-BIqiVgiM.mjs → otel-BUSnyV78.mjs} +1 -1
  39. package/dist/{otel-BbTSxAZp.mjs → otel-Bv5u_Lik.mjs} +1 -1
  40. package/dist/out/mcp-server-darwin-arm64 +0 -0
  41. package/dist/out/mcp-server-darwin-x64 +0 -0
  42. package/dist/out/mcp-server-linux-arm64 +0 -0
  43. package/dist/out/mcp-server-linux-x64 +0 -0
  44. package/dist/out/mcp-server-windows-arm64.exe +0 -0
  45. package/dist/out/mcp-server-windows-x64.exe +0 -0
  46. package/dist/pi-messages-BMuD5Lsm.mjs +8 -0
  47. package/dist/pi-messages-Gq9Ttvbd.mjs +8 -0
  48. package/dist/session-resources-SNa1tEPO.mjs +2 -0
  49. package/dist/{src-Bk9f60_P.mjs → src-BxDQmPZ6.mjs} +1 -1
  50. package/dist/{src-CbkJodKR.mjs → src-C1Ztzxmo.mjs} +1 -1
  51. package/dist/transform-messages-C0FNxyyM.mjs +2 -0
  52. package/dist/transform-messages-s3jcHssz.mjs +2 -0
  53. package/dist/webworkerAll-B7UInSs7.mjs +2 -0
  54. package/package.json +3 -3
  55. package/dist/all-Bd-ariyL.mjs +0 -2
  56. package/dist/anthropic-messages-D9L1s6pn.mjs +0 -40
  57. package/dist/anthropic-messages-OUY8OJj7.mjs +0 -40
  58. package/dist/azure-openai-responses-DJKVhgL-.mjs +0 -2
  59. package/dist/azure-openai-responses-DSoXDHyP.mjs +0 -2
  60. package/dist/browserAll-CGZu5S9C.mjs +0 -2
  61. package/dist/diagnostics-hlO-DFfk.mjs +0 -2
  62. package/dist/google-generative-ai-BqfOLKon.mjs +0 -2
  63. package/dist/google-generative-ai-CZCmY9Gg.mjs +0 -2
  64. package/dist/google-vertex-COsje8-Z.mjs +0 -2
  65. package/dist/google-vertex-Cz5Ddo09.mjs +0 -2
  66. package/dist/models-CtsqYGxn.mjs +0 -2
  67. package/dist/models-DVeZ-5Ql.mjs +0 -2
  68. package/dist/openai-codex-responses-Cq8yFwfN.mjs +0 -8
  69. package/dist/openai-codex-responses-CzFfnGCe.mjs +0 -8
  70. package/dist/openai-completions-DT4sdoVc.mjs +0 -6
  71. package/dist/openai-completions-iO6yRDuR.mjs +0 -6
  72. package/dist/openai-responses-Cr3SvtkS.mjs +0 -2
  73. package/dist/openai-responses-Dtr2Vk2j.mjs +0 -2
  74. package/dist/openai-responses-shared-BLDoTd9K.mjs +0 -13
  75. package/dist/openai-responses-shared-C4PQs_0V.mjs +0 -11
  76. package/dist/openrouter-images-Dk-x2ke6.mjs +0 -2
  77. package/dist/transform-messages-DSEUXL48.mjs +0 -2
  78. package/dist/transform-messages-j96k5V_T.mjs +0 -2
  79. package/dist/webworkerAll-Dy6-Qx-T.mjs +0 -2
  80. /package/dist/{completionchunk-c1fsGiUK.mjs → completionchunk-CL_VFmtq.mjs} +0 -0
  81. /package/dist/{completionchunk-BaC49qbM.mjs → completionchunk-Dyma-JoP.mjs} +0 -0
  82. /package/dist/{dist-BupqiQep.mjs → dist-BgzWr9oi.mjs} +0 -0
  83. /package/dist/{dist-CCiXmKIu.mjs → dist-BtZHKnO9.mjs} +0 -0
  84. /package/dist/{dist-Dq7S86ex.mjs → dist-C3aEr0_q.mjs} +0 -0
  85. /package/dist/{emscripten-module.browser-F76W5DM6-3XbeCXXF.mjs → emscripten-module.browser-F76W5DM6-B_MffdHf.mjs} +0 -0
  86. /package/dist/{emscripten-module.browser-XIKQQPVU-JPkxo8p_.mjs → emscripten-module.browser-XIKQQPVU-ChFl3_k2.mjs} +0 -0
  87. /package/dist/{error-body-D-jnPxbB.mjs → error-body-3m883nGr.mjs} +0 -0
  88. /package/dist/{ffi-D6Fxg1d3.mjs → ffi-DEs9OsLe.mjs} +0 -0
  89. /package/dist/{ffi-u92ceo2s.mjs → ffi-jngwuqKl.mjs} +0 -0
  90. /package/dist/{from-BRY6g9CG.mjs → from-CeVGfYjJ.mjs} +0 -0
  91. /package/dist/{from-Bra_AO5N.mjs → from-DizeILWM.mjs} +0 -0
  92. /package/dist/{github-copilot-headers-ByQsj8SR.mjs → github-copilot-headers-Co77A9iu.mjs} +0 -0
  93. /package/dist/{github-copilot-headers-C4gA1Pjv.mjs → github-copilot-headers-Di-B2QFr.mjs} +0 -0
  94. /package/dist/{hash-BFdQp5Bn.mjs → hash-BJLGFTk8.mjs} +0 -0
  95. /package/dist/{hash-DFXd8wf4.mjs → hash-Dx9oN2Lv.mjs} +0 -0
  96. /package/dist/{headers-BkXFKypW.mjs → headers-8nMK0zm-.mjs} +0 -0
  97. /package/dist/{headers-DtjIrAKV.mjs → headers-Gh3dvZSc.mjs} +0 -0
  98. /package/dist/{html-DwPxy9Y2.mjs → html-De9v6PsV.mjs} +0 -0
  99. /package/dist/{init-BaeOBiNV.mjs → init-BwjB5mke.mjs} +0 -0
  100. /package/dist/{json-parse-BEWPMC87.mjs → json-parse-BjxNFuy6.mjs} +0 -0
  101. /package/dist/{json-parse-qcO5FIDw.mjs → json-parse-CoJ2PRW2.mjs} +0 -0
  102. /package/dist/{module-ES6BEMUI-DGywGVC7.mjs → module-ES6BEMUI-CiRafcvD.mjs} +0 -0
  103. /package/dist/{module-asyncify-2EFITU5U-BU2CORSO.mjs → module-asyncify-2EFITU5U-Bvf6Er23.mjs} +0 -0
  104. /package/dist/{openai-CJ1JzbCY.mjs → openai-Clqf3tig.mjs} +0 -0
  105. /package/dist/{openai-Cv91uXJB.mjs → openai-DtotRKm7.mjs} +0 -0
  106. /package/dist/{openai-prompt-cache-CjAED4AP.mjs → openai-prompt-cache-BbVvSxhO.mjs} +0 -0
  107. /package/dist/{openai-prompt-cache-tVxLccHG.mjs → openai-prompt-cache-ChV-9Dro.mjs} +0 -0
  108. /package/dist/{photon_rs-D_fXqzJa.mjs → photon_rs-DziCqNI5.mjs} +0 -0
  109. /package/dist/{provider-env-D0o9FEJi.mjs → provider-env-CgV7Mc0a.mjs} +0 -0
  110. /package/dist/{provider-env-DTh1Xe-B.mjs → provider-env-p-MKZrBX.mjs} +0 -0
  111. /package/dist/{sanitize-unicode-B5GgPEiu.mjs → sanitize-unicode-BU6jSNzJ.mjs} +0 -0
  112. /package/dist/{sanitize-unicode-DVHYNBlY.mjs → sanitize-unicode-C8aKmv6o.mjs} +0 -0
  113. /package/dist/{standalone-BGhJUGyg.mjs → standalone-NMu-shOx.mjs} +0 -0
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ import{t as e}from"./event-stream-BrGAtXMV.mjs";import{n as t,t as n}from"./headers-Gh3dvZSc.mjs";import{n as r}from"./json-parse-BjxNFuy6.mjs";import{t as i}from"./provider-env-CgV7Mc0a.mjs";import{n as a,t as o}from"./diagnostics-DZacjHpY.mjs";var s=class extends Error{code;diagnosticDetails;constructor(e,t,n){super(e),this.name=`PiMessagesResponseError`,this.code=t,this.diagnosticDetails=n}};function c(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function l(e){try{let t=JSON.parse(e);return c(t)&&c(t.error)?t:void 0}catch{return}}function u(e){let t=8192;return e.length>t?`${e.slice(0,t)}…`:e}function d(e,t,n){let r=typeof n?.error?.message==`string`?n.error.message:void 0,i=typeof n?.error?.code==`string`?n.error.code:void 0,a=r??t,o=i?` (${i})`:``;return`${e.status} ${e.statusText}: ${a}${o}`}function f(e,t,n,r){let i=l(r),a=typeof i?.error?.code==`string`?i.error.code:void 0;return new s(d(n,r,i),a,{version:1,provider:e.provider,model:e.id,url:t.toString(),status:n.status,statusText:n.statusText,error:i?.error,body:i?void 0:u(r),timestampMs:Date.now()})}function p(){return{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}}}function m(e,t){t&&o(e,{type:`pi_messages_rewrite`,timestamp:Date.now(),details:{...t}})}function h(e){let t={role:`assistant`,content:[],api:e.api,provider:e.provider,model:e.id,usage:p(),stopReason:`stop`,timestamp:Date.now()},n=new Map;return e=>{switch(e.type){case`done`:return Object.assign(t,{stopReason:e.reason,usage:e.usage,responseId:e.responseId}),m(t,e.rewrite),{type:`done`,reason:e.reason,message:t};case`error`:return Object.assign(t,{stopReason:e.reason,usage:e.usage,errorMessage:e.errorMessage,responseId:e.responseId}),m(t,e.rewrite),{type:`error`,reason:e.reason,error:t};case`start`:break;case`text_start`:t.content[e.contentIndex]={type:`text`,text:``};break;case`text_delta`:t.content[e.contentIndex].text+=e.delta;break;case`text_end`:Object.assign(t.content[e.contentIndex],{text:e.content,textSignature:e.contentSignature});break;case`thinking_start`:t.content[e.contentIndex]={type:`thinking`,thinking:``};break;case`thinking_delta`:t.content[e.contentIndex].thinking+=e.delta;break;case`thinking_end`:Object.assign(t.content[e.contentIndex],{thinking:e.content,thinkingSignature:e.contentSignature,redacted:e.redacted});break;case`toolcall_start`:t.content[e.contentIndex]={type:`toolCall`,id:e.id,name:e.toolName,arguments:{}},n.set(e.contentIndex,``);break;case`toolcall_delta`:{let i=`${n.get(e.contentIndex)??``}${e.delta}`;n.set(e.contentIndex,i),t.content[e.contentIndex].arguments=r(i);break}case`toolcall_end`:return Object.assign(t.content[e.contentIndex],e.toolCall),n.delete(e.contentIndex),{type:`toolcall_end`,contentIndex:e.contentIndex,toolCall:t.content[e.contentIndex],partial:t}}return{...e,partial:t}}}async function*g(e){let t=new TextDecoder,n=e.getReader(),r=``;try{for(;;){let{done:e,value:i}=await n.read();r+=e?t.decode():t.decode(i,{stream:!0}),r=r.replace(/\r\n/g,`
3
+ `);let a=r.indexOf(`
4
+
5
+ `);for(;a!==-1;){let e=_(r.slice(0,a));e&&(yield e),r=r.slice(a+2),a=r.indexOf(`
6
+
7
+ `)}if(e)break}if(r.trim()){let e=_(r);e&&(yield e)}}finally{n.releaseLock()}}function _(e){let t=e.split(`
8
+ `).find(e=>e.startsWith(`data:`))?.slice(5).trim();return t&&t!==`[DONE]`?JSON.parse(t):void 0}function v(e,t,n){let r=n?`aborted`:`error`,i={role:`assistant`,content:[],api:e.api,provider:e.provider,model:e.id,usage:p(),stopReason:r,errorMessage:t instanceof Error?t.message:String(t),timestamp:Date.now()};return!n&&t instanceof s&&o(i,a(`pi_messages_response_failure`,t,t.diagnosticDetails)),{type:`error`,reason:r,error:i}}function y(e,t){return e||(i(`PI_CACHE_RETENTION`,t)===`long`?`long`:void 0)}const b=(r,i,a)=>{let o=new e,s=h(r);return(async()=>{try{let e=a?.apiKey;if(!e)throw Error(`No API key provided for provider "${r.provider}"`);let c=new URL(`${r.baseUrl.replace(/\/+$/u,``)}/messages`);a?.debug&&c.searchParams.set(`debug`,`1`);let l={model:r.id,context:i,options:{temperature:a?.temperature,maxTokens:a?.maxTokens,reasoning:a?.reasoning,cacheRetention:y(a?.cacheRetention,a?.env),sessionId:a?.sessionId,toolChoice:a?.toolChoice}},u=await a?.onPayload?.(l,r);u!==void 0&&(l=u);let d=await fetch(c,{method:`POST`,headers:{authorization:`Bearer ${e}`,accept:`text/event-stream`,"content-type":`application/json`,...t(a?.headers)},body:JSON.stringify(l),signal:a?.signal});if(await a?.onResponse?.({status:d.status,headers:n(d.headers)},r),!d.ok)throw f(r,c,d,await d.text());if(!d.body)throw Error(`${r.provider} response has no body`);for await(let e of g(d.body)){let t=s(e);if(o.push(t),t.type===`done`||t.type===`error`)return}throw Error(`${r.provider} stream ended without a terminal event`)}catch(e){o.push(v(r,e,a?.signal?.aborted??!1))}})(),o},x=(e,t,n)=>{let r=n;return b(e,t,{...n,reasoning:n?.reasoning,toolChoice:r?.toolChoice,debug:r?.debug})};export{s as PiMessagesResponseError,b as stream,x as streamSimple};
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ import{t as e}from"./event-stream-CXocIcc6.mjs";import{t}from"./provider-env-p-MKZrBX.mjs";import{n,t as r}from"./diagnostics-D0oRYjyK.mjs";import{n as i}from"./json-parse-CoJ2PRW2.mjs";import{n as a,t as o}from"./headers-8nMK0zm-.mjs";var s=class extends Error{code;diagnosticDetails;constructor(e,t,n){super(e),this.name=`PiMessagesResponseError`,this.code=t,this.diagnosticDetails=n}};function c(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function l(e){try{let t=JSON.parse(e);return c(t)&&c(t.error)?t:void 0}catch{return}}function u(e){let t=8192;return e.length>t?`${e.slice(0,t)}…`:e}function d(e,t,n){let r=typeof n?.error?.message==`string`?n.error.message:void 0,i=typeof n?.error?.code==`string`?n.error.code:void 0,a=r??t,o=i?` (${i})`:``;return`${e.status} ${e.statusText}: ${a}${o}`}function f(e,t,n,r){let i=l(r),a=typeof i?.error?.code==`string`?i.error.code:void 0;return new s(d(n,r,i),a,{version:1,provider:e.provider,model:e.id,url:t.toString(),status:n.status,statusText:n.statusText,error:i?.error,body:i?void 0:u(r),timestampMs:Date.now()})}function p(){return{input:0,output:0,cacheRead:0,cacheWrite:0,totalTokens:0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0,total:0}}}function m(e,t){t&&r(e,{type:`pi_messages_rewrite`,timestamp:Date.now(),details:{...t}})}function h(e){let t={role:`assistant`,content:[],api:e.api,provider:e.provider,model:e.id,usage:p(),stopReason:`stop`,timestamp:Date.now()},n=new Map;return e=>{switch(e.type){case`done`:return Object.assign(t,{stopReason:e.reason,usage:e.usage,responseId:e.responseId}),m(t,e.rewrite),{type:`done`,reason:e.reason,message:t};case`error`:return Object.assign(t,{stopReason:e.reason,usage:e.usage,errorMessage:e.errorMessage,responseId:e.responseId}),m(t,e.rewrite),{type:`error`,reason:e.reason,error:t};case`start`:break;case`text_start`:t.content[e.contentIndex]={type:`text`,text:``};break;case`text_delta`:t.content[e.contentIndex].text+=e.delta;break;case`text_end`:Object.assign(t.content[e.contentIndex],{text:e.content,textSignature:e.contentSignature});break;case`thinking_start`:t.content[e.contentIndex]={type:`thinking`,thinking:``};break;case`thinking_delta`:t.content[e.contentIndex].thinking+=e.delta;break;case`thinking_end`:Object.assign(t.content[e.contentIndex],{thinking:e.content,thinkingSignature:e.contentSignature,redacted:e.redacted});break;case`toolcall_start`:t.content[e.contentIndex]={type:`toolCall`,id:e.id,name:e.toolName,arguments:{}},n.set(e.contentIndex,``);break;case`toolcall_delta`:{let r=`${n.get(e.contentIndex)??``}${e.delta}`;n.set(e.contentIndex,r),t.content[e.contentIndex].arguments=i(r);break}case`toolcall_end`:return Object.assign(t.content[e.contentIndex],e.toolCall),n.delete(e.contentIndex),{type:`toolcall_end`,contentIndex:e.contentIndex,toolCall:t.content[e.contentIndex],partial:t}}return{...e,partial:t}}}async function*g(e){let t=new TextDecoder,n=e.getReader(),r=``;try{for(;;){let{done:e,value:i}=await n.read();r+=e?t.decode():t.decode(i,{stream:!0}),r=r.replace(/\r\n/g,`
3
+ `);let a=r.indexOf(`
4
+
5
+ `);for(;a!==-1;){let e=_(r.slice(0,a));e&&(yield e),r=r.slice(a+2),a=r.indexOf(`
6
+
7
+ `)}if(e)break}if(r.trim()){let e=_(r);e&&(yield e)}}finally{n.releaseLock()}}function _(e){let t=e.split(`
8
+ `).find(e=>e.startsWith(`data:`))?.slice(5).trim();return t&&t!==`[DONE]`?JSON.parse(t):void 0}function v(e,t,i){let a=i?`aborted`:`error`,o={role:`assistant`,content:[],api:e.api,provider:e.provider,model:e.id,usage:p(),stopReason:a,errorMessage:t instanceof Error?t.message:String(t),timestamp:Date.now()};return!i&&t instanceof s&&r(o,n(`pi_messages_response_failure`,t,t.diagnosticDetails)),{type:`error`,reason:a,error:o}}function y(e,n){return e||(t(`PI_CACHE_RETENTION`,n)===`long`?`long`:void 0)}const b=(t,n,r)=>{let i=new e,s=h(t);return(async()=>{try{let e=r?.apiKey;if(!e)throw Error(`No API key provided for provider "${t.provider}"`);let c=new URL(`${t.baseUrl.replace(/\/+$/u,``)}/messages`);r?.debug&&c.searchParams.set(`debug`,`1`);let l={model:t.id,context:n,options:{temperature:r?.temperature,maxTokens:r?.maxTokens,reasoning:r?.reasoning,cacheRetention:y(r?.cacheRetention,r?.env),sessionId:r?.sessionId,toolChoice:r?.toolChoice}},u=await r?.onPayload?.(l,t);u!==void 0&&(l=u);let d=await fetch(c,{method:`POST`,headers:{authorization:`Bearer ${e}`,accept:`text/event-stream`,"content-type":`application/json`,...a(r?.headers)},body:JSON.stringify(l),signal:r?.signal});if(await r?.onResponse?.({status:d.status,headers:o(d.headers)},t),!d.ok)throw f(t,c,d,await d.text());if(!d.body)throw Error(`${t.provider} response has no body`);for await(let e of g(d.body)){let t=s(e);if(i.push(t),t.type===`done`||t.type===`error`)return}throw Error(`${t.provider} stream ended without a terminal event`)}catch(e){i.push(v(t,e,r?.signal?.aborted??!1))}})(),i},x=(e,t,n)=>{let r=n;return b(e,t,{...n,reasoning:n?.reasoning,toolChoice:r?.toolChoice,debug:r?.debug})};export{s as PiMessagesResponseError,b as stream,x as streamSimple};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ const e=new Set;function t(t){return e.add(t),()=>{e.delete(t)}}function n(t){let n=[];for(let r of e)try{r(t)}catch(e){n.push(e)}if(n.length>0)throw AggregateError(n,`Failed to cleanup session resources`)}export{t as n,n as t};
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import{Nt as e}from"./index.mjs";import{a as t,i as n,n as r,o as i,r as a,s as o,t as s}from"./from-BRY6g9CG.mjs";import{format as c}from"node:url";import{Buffer as l}from"node:buffer";import u,{PassThrough as d,pipeline as f}from"node:stream";import{deprecate as p,promisify as m,types as h}from"node:util";import g from"node:zlib";import{isIP as _}from"node:net";import v from"node:http";import ee from"node:https";function te(e){if(!/^data:/i.test(e))throw TypeError('`uri` does not appear to be a Data URI (must begin with "data:")');e=e.replace(/\r?\n/g,``);let t=e.indexOf(`,`);if(t===-1||t<=4)throw TypeError(`malformed data: URI`);let n=e.substring(5,t).split(`;`),r=``,i=!1,a=n[0]||`text/plain`,o=a;for(let e=1;e<n.length;e++)n[e]===`base64`?i=!0:n[e]&&(o+=`;${n[e]}`,n[e].indexOf(`charset=`)===0&&(r=n[e].substring(8)));!n[0]&&!r.length&&(o+=`;charset=US-ASCII`,r=`US-ASCII`);let s=i?`base64`:`ascii`,c=unescape(e.substring(t+1)),l=Buffer.from(c,s);return l.type=a,l.typeFull=o,l.charset=r,l}var ne=e((()=>{})),y,b=e((()=>{y=class extends Error{constructor(e,t){super(e),Error.captureStackTrace(this,this.constructor),this.type=t}get name(){return this.constructor.name}get[Symbol.toStringTag](){return this.constructor.name}}})),x,re=e((()=>{b(),x=class extends y{constructor(e,t,n){super(e,t),n&&(this.code=this.errno=n.code,this.erroredSysCall=n.syscall)}}})),S,C,w,T,E,ie,D=e((()=>{S=Symbol.toStringTag,C=e=>typeof e==`object`&&typeof e.append==`function`&&typeof e.delete==`function`&&typeof e.get==`function`&&typeof e.getAll==`function`&&typeof e.has==`function`&&typeof e.set==`function`&&typeof e.sort==`function`&&e[S]===`URLSearchParams`,w=e=>e&&typeof e==`object`&&typeof e.arrayBuffer==`function`&&typeof e.type==`string`&&typeof e.stream==`function`&&typeof e.constructor==`function`&&/^(Blob|File)$/.test(e[S]),T=e=>typeof e==`object`&&(e[S]===`AbortSignal`||e[S]===`EventTarget`),E=(e,t)=>{let n=new URL(t).hostname,r=new URL(e).hostname;return n===r||n.endsWith(`.${r}`)},ie=(e,t)=>new URL(t).protocol===new URL(e).protocol}));async function O(e){if(e[A].disturbed)throw TypeError(`body used already for: ${e.url}`);if(e[A].disturbed=!0,e[A].error)throw e[A].error;let{body:t}=e;if(t===null||!(t instanceof u))return l.alloc(0);let n=[],r=0;try{for await(let i of t){if(e.size>0&&r+i.length>e.size){let n=new x(`content size at ${e.url} over limit: ${e.size}`,`max-size`);throw t.destroy(n),n}r+=i.length,n.push(i)}}catch(t){throw t instanceof y?t:new x(`Invalid response body while trying to fetch ${e.url}: ${t.message}`,`system`,t)}if(t.readableEnded===!0||t._readableState.ended===!0)try{return n.every(e=>typeof e==`string`)?l.from(n.join(``)):l.concat(n,r)}catch(t){throw new x(`Could not create Buffer from response body for ${e.url}: ${t.message}`,`system`,t)}else throw new x(`Premature close of server response while trying to fetch ${e.url}`)}var k,A,j,M,N,P,F,ae,I=e((()=>{o(),n(),re(),b(),D(),k=m(u.pipeline),A=Symbol(`Body internals`),j=class{constructor(e,{size:t=0}={}){let n=null;e===null?e=null:C(e)?e=l.from(e.toString()):w(e)||l.isBuffer(e)||(h.isAnyArrayBuffer(e)?e=l.from(e):ArrayBuffer.isView(e)?e=l.from(e.buffer,e.byteOffset,e.byteLength):e instanceof u||(e instanceof r?(e=a(e),n=e.type.split(`=`)[1]):e=l.from(String(e))));let i=e;l.isBuffer(e)?i=u.Readable.from(e):w(e)&&(i=u.Readable.from(e.stream())),this[A]={body:e,stream:i,boundary:n,disturbed:!1,error:null},this.size=t,e instanceof u&&e.on(`error`,e=>{let t=e instanceof y?e:new x(`Invalid response body while trying to fetch ${this.url}: ${e.message}`,`system`,e);this[A].error=t})}get body(){return this[A].stream}get bodyUsed(){return this[A].disturbed}async arrayBuffer(){let{buffer:e,byteOffset:t,byteLength:n}=await O(this);return e.slice(t,t+n)}async formData(){let e=this.headers.get(`content-type`);if(e.startsWith(`application/x-www-form-urlencoded`)){let e=new r,t=new URLSearchParams(await this.text());for(let[n,r]of t)e.append(n,r);return e}let{toFormData:t}=await import(`./multipart-parser-CYJPmLQW.mjs`);return t(this.body,e)}async blob(){let e=this.headers&&this.headers.get(`content-type`)||this[A].body&&this[A].body.type||``;return new i([await this.arrayBuffer()],{type:e})}async json(){let e=await this.text();return JSON.parse(e)}async text(){let e=await O(this);return new TextDecoder().decode(e)}buffer(){return O(this)}},j.prototype.buffer=p(j.prototype.buffer,`Please use 'response.arrayBuffer()' instead of 'response.buffer()'`,`node-fetch#buffer`),Object.defineProperties(j.prototype,{body:{enumerable:!0},bodyUsed:{enumerable:!0},arrayBuffer:{enumerable:!0},blob:{enumerable:!0},json:{enumerable:!0},text:{enumerable:!0},data:{get:p(()=>{},`data doesn't exist, use json(), text(), arrayBuffer(), or body instead`,`https://github.com/node-fetch/node-fetch/issues/1000 (response)`)}}),M=(e,t)=>{let n,r,{body:i}=e[A];if(e.bodyUsed)throw Error(`cannot clone body after it is used`);return i instanceof u&&typeof i.getBoundary!=`function`&&(n=new d({highWaterMark:t}),r=new d({highWaterMark:t}),i.pipe(n),i.pipe(r),e[A].stream=n,i=r),i},N=p(e=>e.getBoundary(),`form-data doesn't follow the spec and requires special treatment. Use alternative package`,`https://github.com/node-fetch/node-fetch/issues/1167`),P=(e,t)=>e===null?null:typeof e==`string`?`text/plain;charset=UTF-8`:C(e)?`application/x-www-form-urlencoded;charset=UTF-8`:w(e)?e.type||null:l.isBuffer(e)||h.isAnyArrayBuffer(e)||ArrayBuffer.isView(e)?null:e instanceof r?`multipart/form-data; boundary=${t[A].boundary}`:e&&typeof e.getBoundary==`function`?`multipart/form-data;boundary=${N(e)}`:e instanceof u?null:`text/plain;charset=UTF-8`,F=e=>{let{body:t}=e[A];return t===null?0:w(t)?t.size:l.isBuffer(t)?t.length:t&&typeof t.getLengthSync==`function`&&t.hasKnownLength&&t.hasKnownLength()?t.getLengthSync():null},ae=async(e,{body:t})=>{t===null?e.end():await k(t,e)}}));function oe(e=[]){return new z(e.reduce((e,t,n,r)=>(n%2==0&&e.push(r.slice(n,n+2)),e),[]).filter(([e,t])=>{try{return L(e),R(e,String(t)),!0}catch{return!1}}))}var L,R,z,B=e((()=>{L=typeof v.validateHeaderName==`function`?v.validateHeaderName:e=>{if(!/^[\^`\-\w!#$%&'*+.|~]+$/.test(e)){let t=TypeError(`Header name must be a valid HTTP token [${e}]`);throw Object.defineProperty(t,`code`,{value:`ERR_INVALID_HTTP_TOKEN`}),t}},R=typeof v.validateHeaderValue==`function`?v.validateHeaderValue:(e,t)=>{if(/[^\t\u0020-\u007E\u0080-\u00FF]/.test(t)){let t=TypeError(`Invalid character in header content ["${e}"]`);throw Object.defineProperty(t,`code`,{value:`ERR_INVALID_CHAR`}),t}},z=class e extends URLSearchParams{constructor(t){let n=[];if(t instanceof e){let e=t.raw();for(let[t,r]of Object.entries(e))n.push(...r.map(e=>[t,e]))}else if(t!=null)if(typeof t==`object`&&!h.isBoxedPrimitive(t)){let e=t[Symbol.iterator];if(e==null)n.push(...Object.entries(t));else{if(typeof e!=`function`)throw TypeError(`Header pairs must be iterable`);n=[...t].map(e=>{if(typeof e!=`object`||h.isBoxedPrimitive(e))throw TypeError(`Each header pair must be an iterable object`);return[...e]}).map(e=>{if(e.length!==2)throw TypeError(`Each header pair must be a name/value tuple`);return[...e]})}}else throw TypeError(`Failed to construct 'Headers': The provided value is not of type '(sequence<sequence<ByteString>> or record<ByteString, ByteString>)`);return n=n.length>0?n.map(([e,t])=>(L(e),R(e,String(t)),[String(e).toLowerCase(),String(t)])):void 0,super(n),new Proxy(this,{get(e,t,n){switch(t){case`append`:case`set`:return(n,r)=>(L(n),R(n,String(r)),URLSearchParams.prototype[t].call(e,String(n).toLowerCase(),String(r)));case`delete`:case`has`:case`getAll`:return n=>(L(n),URLSearchParams.prototype[t].call(e,String(n).toLowerCase()));case`keys`:return()=>(e.sort(),new Set(URLSearchParams.prototype.keys.call(e)).keys());default:return Reflect.get(e,t,n)}}})}get[Symbol.toStringTag](){return this.constructor.name}toString(){return Object.prototype.toString.call(this)}get(e){let t=this.getAll(e);if(t.length===0)return null;let n=t.join(`, `);return/^content-encoding$/i.test(e)&&(n=n.toLowerCase()),n}forEach(e,t=void 0){for(let n of this.keys())Reflect.apply(e,t,[this.get(n),n,this])}*values(){for(let e of this.keys())yield this.get(e)}*entries(){for(let e of this.keys())yield[e,this.get(e)]}[Symbol.iterator](){return this.entries()}raw(){return[...this.keys()].reduce((e,t)=>(e[t]=this.getAll(t),e),{})}[Symbol.for(`nodejs.util.inspect.custom`)](){return[...this.keys()].reduce((e,t)=>{let n=this.getAll(t);return t===`host`?e[t]=n[0]:e[t]=n.length>1?n:n[0],e},{})}},Object.defineProperties(z.prototype,[`get`,`entries`,`forEach`,`values`].reduce((e,t)=>(e[t]={enumerable:!0},e),{}))})),V,H,U=e((()=>{V=new Set([301,302,303,307,308]),H=e=>V.has(e)})),W,G,se=e((()=>{B(),I(),U(),W=Symbol(`Response internals`),G=class e extends j{constructor(e=null,t={}){super(e,t);let n=t.status==null?200:t.status,r=new z(t.headers);if(e!==null&&!r.has(`Content-Type`)){let t=P(e,this);t&&r.append(`Content-Type`,t)}this[W]={type:`default`,url:t.url,status:n,statusText:t.statusText||``,headers:r,counter:t.counter,highWaterMark:t.highWaterMark}}get type(){return this[W].type}get url(){return this[W].url||``}get status(){return this[W].status}get ok(){return this[W].status>=200&&this[W].status<300}get redirected(){return this[W].counter>0}get statusText(){return this[W].statusText}get headers(){return this[W].headers}get highWaterMark(){return this[W].highWaterMark}clone(){return new e(M(this,this.highWaterMark),{type:this.type,url:this.url,status:this.status,statusText:this.statusText,headers:this.headers,ok:this.ok,redirected:this.redirected,size:this.size,highWaterMark:this.highWaterMark})}static redirect(t,n=302){if(!H(n))throw RangeError(`Failed to execute "redirect" on "response": Invalid status code`);return new e(null,{headers:{location:new URL(t).toString()},status:n})}static error(){let t=new e(null,{status:0,statusText:``});return t[W].type=`error`,t}static json(t=void 0,n={}){let r=JSON.stringify(t);if(r===void 0)throw TypeError(`data is not JSON serializable`);let i=new z(n&&n.headers);return i.has(`content-type`)||i.set(`content-type`,`application/json`),new e(r,{...n,headers:i})}get[Symbol.toStringTag](){return`Response`}},Object.defineProperties(G.prototype,{type:{enumerable:!0},url:{enumerable:!0},status:{enumerable:!0},ok:{enumerable:!0},redirected:{enumerable:!0},statusText:{enumerable:!0},headers:{enumerable:!0},clone:{enumerable:!0}})})),K,ce=e((()=>{K=e=>{if(e.search)return e.search;let t=e.href.length-1,n=e.hash||(e.href[t]===`#`?`#`:``);return e.href[t-n.length]===`?`?`?`:``}}));function q(e,t=!1){return e==null||(e=new URL(e),/^(about|blob|data):$/.test(e.protocol))?`no-referrer`:(e.username=``,e.password=``,e.hash=``,t&&(e.pathname=``,e.search=``),e)}function le(e){if(!Y.has(e))throw TypeError(`Invalid referrerPolicy: ${e}`);return e}function ue(e){if(/^(http|ws)s:$/.test(e.protocol))return!0;let t=e.host.replace(/(^\[)|(]$)/g,``),n=_(t);return n===4&&/^127\./.test(t)||n===6&&/^(((0+:){7})|(::(0+:){0,6}))0*1$/.test(t)?!0:e.host===`localhost`||e.host.endsWith(`.localhost`)?!1:e.protocol===`file:`}function J(e){return/^about:(blank|srcdoc)$/.test(e)||e.protocol===`data:`||/^(blob|filesystem):$/.test(e.protocol)?!0:ue(e)}function de(e,{referrerURLCallback:t,referrerOriginCallback:n}={}){if(e.referrer===`no-referrer`||e.referrerPolicy===``)return null;let r=e.referrerPolicy;if(e.referrer===`about:client`)return`no-referrer`;let i=e.referrer,a=q(i),o=q(i,!0);a.toString().length>4096&&(a=o),t&&(a=t(a)),n&&(o=n(o));let s=new URL(e.url);switch(r){case`no-referrer`:return`no-referrer`;case`origin`:return o;case`unsafe-url`:return a;case`strict-origin`:return J(a)&&!J(s)?`no-referrer`:o.toString();case`strict-origin-when-cross-origin`:return a.origin===s.origin?a:J(a)&&!J(s)?`no-referrer`:o;case`same-origin`:return a.origin===s.origin?a:`no-referrer`;case`origin-when-cross-origin`:return a.origin===s.origin?a:o;case`no-referrer-when-downgrade`:return J(a)&&!J(s)?`no-referrer`:a;default:throw TypeError(`Invalid referrerPolicy: ${r}`)}}function fe(e){let t=(e.get(`referrer-policy`)||``).split(/[,\s]+/),n=``;for(let e of t)e&&Y.has(e)&&(n=e);return n}var Y,X,pe=e((()=>{Y=new Set([``,`no-referrer`,`no-referrer-when-downgrade`,`same-origin`,`origin`,`strict-origin`,`origin-when-cross-origin`,`strict-origin-when-cross-origin`,`unsafe-url`]),X=`strict-origin-when-cross-origin`})),Z,Q,me,$,he,ge=e((()=>{B(),I(),D(),ce(),pe(),Z=Symbol(`Request internals`),Q=e=>typeof e==`object`&&typeof e[Z]==`object`,me=p(()=>{},`.data is not a valid RequestInit property, use .body instead`,`https://github.com/node-fetch/node-fetch/issues/1000 (request)`),$=class e extends j{constructor(e,t={}){let n;if(Q(e)?n=new URL(e.url):(n=new URL(e),e={}),n.username!==``||n.password!==``)throw TypeError(`${n} is an url with embedded credentials.`);let r=t.method||e.method||`GET`;if(/^(delete|get|head|options|post|put)$/i.test(r)&&(r=r.toUpperCase()),!Q(t)&&`data`in t&&me(),(t.body!=null||Q(e)&&e.body!==null)&&(r===`GET`||r===`HEAD`))throw TypeError(`Request with GET/HEAD method cannot have body`);let i=t.body?t.body:Q(e)&&e.body!==null?M(e):null;super(i,{size:t.size||e.size||0});let a=new z(t.headers||e.headers||{});if(i!==null&&!a.has(`Content-Type`)){let e=P(i,this);e&&a.set(`Content-Type`,e)}let o=Q(e)?e.signal:null;if(`signal`in t&&(o=t.signal),o!=null&&!T(o))throw TypeError(`Expected signal to be an instanceof AbortSignal or EventTarget`);let s=t.referrer==null?e.referrer:t.referrer;if(s===``)s=`no-referrer`;else if(s){let e=new URL(s);s=/^about:(\/\/)?client$/.test(e)?`client`:e}else s=void 0;this[Z]={method:r,redirect:t.redirect||e.redirect||`follow`,headers:a,parsedURL:n,signal:o,referrer:s},this.follow=t.follow===void 0?e.follow===void 0?20:e.follow:t.follow,this.compress=t.compress===void 0?e.compress===void 0?!0:e.compress:t.compress,this.counter=t.counter||e.counter||0,this.agent=t.agent||e.agent,this.highWaterMark=t.highWaterMark||e.highWaterMark||16384,this.insecureHTTPParser=t.insecureHTTPParser||e.insecureHTTPParser||!1,this.referrerPolicy=t.referrerPolicy||e.referrerPolicy||``}get method(){return this[Z].method}get url(){return c(this[Z].parsedURL)}get headers(){return this[Z].headers}get redirect(){return this[Z].redirect}get signal(){return this[Z].signal}get referrer(){if(this[Z].referrer===`no-referrer`)return``;if(this[Z].referrer===`client`)return`about:client`;if(this[Z].referrer)return this[Z].referrer.toString()}get referrerPolicy(){return this[Z].referrerPolicy}set referrerPolicy(e){this[Z].referrerPolicy=le(e)}clone(){return new e(this)}get[Symbol.toStringTag](){return`Request`}},Object.defineProperties($.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0},referrer:{enumerable:!0},referrerPolicy:{enumerable:!0}}),he=e=>{let{parsedURL:t}=e[Z],n=new z(e[Z].headers);n.has(`Accept`)||n.set(`Accept`,`*/*`);let r=null;if(e.body===null&&/^(post|put)$/i.test(e.method)&&(r=`0`),e.body!==null){let t=F(e);typeof t==`number`&&!Number.isNaN(t)&&(r=String(t))}r&&n.set(`Content-Length`,r),e.referrerPolicy===``&&(e.referrerPolicy=X),e.referrer&&e.referrer!==`no-referrer`?e[Z].referrer=de(e):e[Z].referrer=`no-referrer`,e[Z].referrer instanceof URL&&n.set(`Referer`,e.referrer),n.has(`User-Agent`)||n.set(`User-Agent`,`node-fetch`),e.compress&&!n.has(`Accept-Encoding`)&&n.set(`Accept-Encoding`,`gzip, deflate, br`);let{agent:i}=e;typeof i==`function`&&(i=i(t));let a=K(t);return{parsedURL:t,options:{path:t.pathname+a,method:e.method,headers:n[Symbol.for(`nodejs.util.inspect.custom`)](),insecureHTTPParser:e.insecureHTTPParser,agent:i}}}})),_e,ve=e((()=>{b(),_e=class extends y{constructor(e,t=`aborted`){super(e,t)}}}));async function ye(e,t){return new Promise((n,r)=>{let i=new $(e,t),{parsedURL:a,options:o}=he(i);if(!xe.has(a.protocol))throw TypeError(`node-fetch cannot load ${e}. URL scheme "${a.protocol.replace(/:$/,``)}" is not supported.`);if(a.protocol===`data:`){let e=te(i.url);n(new G(e,{headers:{"Content-Type":e.typeFull}}));return}let s=(a.protocol===`https:`?ee:v).request,{signal:c}=i,l=null,p=()=>{let e=new _e(`The operation was aborted.`);r(e),i.body&&i.body instanceof u.Readable&&i.body.destroy(e),!(!l||!l.body)&&l.body.emit(`error`,e)};if(c&&c.aborted){p();return}let m=()=>{p(),_()},h=s(a.toString(),o);c&&c.addEventListener(`abort`,m);let _=()=>{h.abort(),c&&c.removeEventListener(`abort`,m)};h.on(`error`,e=>{r(new x(`request to ${i.url} failed, reason: ${e.message}`,`system`,e)),_()}),be(h,e=>{l&&l.body&&l.body.destroy(e)}),process.version<`v14`&&h.on(`socket`,e=>{let t;e.prependListener(`end`,()=>{t=e._eventsCount}),e.prependListener(`close`,n=>{if(l&&t<e._eventsCount&&!n){let e=Error(`Premature close`);e.code=`ERR_STREAM_PREMATURE_CLOSE`,l.body.emit(`error`,e)}})}),h.on(`response`,e=>{h.setTimeout(0);let a=oe(e.rawHeaders);if(H(e.statusCode)){let o=a.get(`Location`),s=null;try{s=o===null?null:new URL(o,i.url)}catch{if(i.redirect!==`manual`){r(new x(`uri requested responds with an invalid redirect URL: ${o}`,`invalid-redirect`)),_();return}}switch(i.redirect){case`error`:r(new x(`uri requested responds with a redirect, redirect mode is set to error: ${i.url}`,`no-redirect`)),_();return;case`manual`:break;case`follow`:{if(s===null)break;if(i.counter>=i.follow){r(new x(`maximum redirect reached at: ${i.url}`,`max-redirect`)),_();return}let o={headers:new z(i.headers),follow:i.follow,counter:i.counter+1,agent:i.agent,compress:i.compress,method:i.method,body:M(i),signal:i.signal,size:i.size,referrer:i.referrer,referrerPolicy:i.referrerPolicy};if(!E(i.url,s)||!ie(i.url,s))for(let e of[`authorization`,`www-authenticate`,`cookie`,`cookie2`])o.headers.delete(e);if(e.statusCode!==303&&i.body&&t.body instanceof u.Readable){r(new x(`Cannot follow redirect with body being a readable stream`,`unsupported-redirect`)),_();return}(e.statusCode===303||(e.statusCode===301||e.statusCode===302)&&i.method===`POST`)&&(o.method=`GET`,o.body=void 0,o.headers.delete(`content-length`));let c=fe(a);c&&(o.referrerPolicy=c),n(ye(new $(s,o))),_();return}default:return r(TypeError(`Redirect option '${i.redirect}' is not a valid value of RequestRedirect`))}}c&&e.once(`end`,()=>{c.removeEventListener(`abort`,m)});let o=f(e,new d,e=>{e&&r(e)});process.version<`v12.10`&&e.on(`aborted`,m);let s={url:i.url,status:e.statusCode,statusText:e.statusMessage,headers:a,size:i.size,counter:i.counter,highWaterMark:i.highWaterMark},p=a.get(`Content-Encoding`);if(!i.compress||i.method===`HEAD`||p===null||e.statusCode===204||e.statusCode===304){l=new G(o,s),n(l);return}let v={flush:g.Z_SYNC_FLUSH,finishFlush:g.Z_SYNC_FLUSH};if(p===`gzip`||p===`x-gzip`){o=f(o,g.createGunzip(v),e=>{e&&r(e)}),l=new G(o,s),n(l);return}if(p===`deflate`||p===`x-deflate`){let t=f(e,new d,e=>{e&&r(e)});t.once(`data`,e=>{o=(e[0]&15)==8?f(o,g.createInflate(),e=>{e&&r(e)}):f(o,g.createInflateRaw(),e=>{e&&r(e)}),l=new G(o,s),n(l)}),t.once(`end`,()=>{l||(l=new G(o,s),n(l))});return}if(p===`br`){o=f(o,g.createBrotliDecompress(),e=>{e&&r(e)}),l=new G(o,s),n(l);return}l=new G(o,s),n(l)}),ae(h,i).catch(r)})}function be(e,t){let n=l.from(`0\r
2
+ import{Nt as e}from"./index.mjs";import{a as t,i as n,n as r,o as i,r as a,s as o,t as s}from"./from-CeVGfYjJ.mjs";import{format as c}from"node:url";import{Buffer as l}from"node:buffer";import u,{PassThrough as d,pipeline as f}from"node:stream";import{deprecate as p,promisify as m,types as h}from"node:util";import g from"node:zlib";import{isIP as _}from"node:net";import v from"node:http";import ee from"node:https";function te(e){if(!/^data:/i.test(e))throw TypeError('`uri` does not appear to be a Data URI (must begin with "data:")');e=e.replace(/\r?\n/g,``);let t=e.indexOf(`,`);if(t===-1||t<=4)throw TypeError(`malformed data: URI`);let n=e.substring(5,t).split(`;`),r=``,i=!1,a=n[0]||`text/plain`,o=a;for(let e=1;e<n.length;e++)n[e]===`base64`?i=!0:n[e]&&(o+=`;${n[e]}`,n[e].indexOf(`charset=`)===0&&(r=n[e].substring(8)));!n[0]&&!r.length&&(o+=`;charset=US-ASCII`,r=`US-ASCII`);let s=i?`base64`:`ascii`,c=unescape(e.substring(t+1)),l=Buffer.from(c,s);return l.type=a,l.typeFull=o,l.charset=r,l}var ne=e((()=>{})),y,b=e((()=>{y=class extends Error{constructor(e,t){super(e),Error.captureStackTrace(this,this.constructor),this.type=t}get name(){return this.constructor.name}get[Symbol.toStringTag](){return this.constructor.name}}})),x,re=e((()=>{b(),x=class extends y{constructor(e,t,n){super(e,t),n&&(this.code=this.errno=n.code,this.erroredSysCall=n.syscall)}}})),S,C,w,T,E,ie,D=e((()=>{S=Symbol.toStringTag,C=e=>typeof e==`object`&&typeof e.append==`function`&&typeof e.delete==`function`&&typeof e.get==`function`&&typeof e.getAll==`function`&&typeof e.has==`function`&&typeof e.set==`function`&&typeof e.sort==`function`&&e[S]===`URLSearchParams`,w=e=>e&&typeof e==`object`&&typeof e.arrayBuffer==`function`&&typeof e.type==`string`&&typeof e.stream==`function`&&typeof e.constructor==`function`&&/^(Blob|File)$/.test(e[S]),T=e=>typeof e==`object`&&(e[S]===`AbortSignal`||e[S]===`EventTarget`),E=(e,t)=>{let n=new URL(t).hostname,r=new URL(e).hostname;return n===r||n.endsWith(`.${r}`)},ie=(e,t)=>new URL(t).protocol===new URL(e).protocol}));async function O(e){if(e[A].disturbed)throw TypeError(`body used already for: ${e.url}`);if(e[A].disturbed=!0,e[A].error)throw e[A].error;let{body:t}=e;if(t===null||!(t instanceof u))return l.alloc(0);let n=[],r=0;try{for await(let i of t){if(e.size>0&&r+i.length>e.size){let n=new x(`content size at ${e.url} over limit: ${e.size}`,`max-size`);throw t.destroy(n),n}r+=i.length,n.push(i)}}catch(t){throw t instanceof y?t:new x(`Invalid response body while trying to fetch ${e.url}: ${t.message}`,`system`,t)}if(t.readableEnded===!0||t._readableState.ended===!0)try{return n.every(e=>typeof e==`string`)?l.from(n.join(``)):l.concat(n,r)}catch(t){throw new x(`Could not create Buffer from response body for ${e.url}: ${t.message}`,`system`,t)}else throw new x(`Premature close of server response while trying to fetch ${e.url}`)}var k,A,j,M,N,P,F,ae,I=e((()=>{o(),n(),re(),b(),D(),k=m(u.pipeline),A=Symbol(`Body internals`),j=class{constructor(e,{size:t=0}={}){let n=null;e===null?e=null:C(e)?e=l.from(e.toString()):w(e)||l.isBuffer(e)||(h.isAnyArrayBuffer(e)?e=l.from(e):ArrayBuffer.isView(e)?e=l.from(e.buffer,e.byteOffset,e.byteLength):e instanceof u||(e instanceof r?(e=a(e),n=e.type.split(`=`)[1]):e=l.from(String(e))));let i=e;l.isBuffer(e)?i=u.Readable.from(e):w(e)&&(i=u.Readable.from(e.stream())),this[A]={body:e,stream:i,boundary:n,disturbed:!1,error:null},this.size=t,e instanceof u&&e.on(`error`,e=>{let t=e instanceof y?e:new x(`Invalid response body while trying to fetch ${this.url}: ${e.message}`,`system`,e);this[A].error=t})}get body(){return this[A].stream}get bodyUsed(){return this[A].disturbed}async arrayBuffer(){let{buffer:e,byteOffset:t,byteLength:n}=await O(this);return e.slice(t,t+n)}async formData(){let e=this.headers.get(`content-type`);if(e.startsWith(`application/x-www-form-urlencoded`)){let e=new r,t=new URLSearchParams(await this.text());for(let[n,r]of t)e.append(n,r);return e}let{toFormData:t}=await import(`./multipart-parser-Ce015IGH.mjs`);return t(this.body,e)}async blob(){let e=this.headers&&this.headers.get(`content-type`)||this[A].body&&this[A].body.type||``;return new i([await this.arrayBuffer()],{type:e})}async json(){let e=await this.text();return JSON.parse(e)}async text(){let e=await O(this);return new TextDecoder().decode(e)}buffer(){return O(this)}},j.prototype.buffer=p(j.prototype.buffer,`Please use 'response.arrayBuffer()' instead of 'response.buffer()'`,`node-fetch#buffer`),Object.defineProperties(j.prototype,{body:{enumerable:!0},bodyUsed:{enumerable:!0},arrayBuffer:{enumerable:!0},blob:{enumerable:!0},json:{enumerable:!0},text:{enumerable:!0},data:{get:p(()=>{},`data doesn't exist, use json(), text(), arrayBuffer(), or body instead`,`https://github.com/node-fetch/node-fetch/issues/1000 (response)`)}}),M=(e,t)=>{let n,r,{body:i}=e[A];if(e.bodyUsed)throw Error(`cannot clone body after it is used`);return i instanceof u&&typeof i.getBoundary!=`function`&&(n=new d({highWaterMark:t}),r=new d({highWaterMark:t}),i.pipe(n),i.pipe(r),e[A].stream=n,i=r),i},N=p(e=>e.getBoundary(),`form-data doesn't follow the spec and requires special treatment. Use alternative package`,`https://github.com/node-fetch/node-fetch/issues/1167`),P=(e,t)=>e===null?null:typeof e==`string`?`text/plain;charset=UTF-8`:C(e)?`application/x-www-form-urlencoded;charset=UTF-8`:w(e)?e.type||null:l.isBuffer(e)||h.isAnyArrayBuffer(e)||ArrayBuffer.isView(e)?null:e instanceof r?`multipart/form-data; boundary=${t[A].boundary}`:e&&typeof e.getBoundary==`function`?`multipart/form-data;boundary=${N(e)}`:e instanceof u?null:`text/plain;charset=UTF-8`,F=e=>{let{body:t}=e[A];return t===null?0:w(t)?t.size:l.isBuffer(t)?t.length:t&&typeof t.getLengthSync==`function`&&t.hasKnownLength&&t.hasKnownLength()?t.getLengthSync():null},ae=async(e,{body:t})=>{t===null?e.end():await k(t,e)}}));function oe(e=[]){return new z(e.reduce((e,t,n,r)=>(n%2==0&&e.push(r.slice(n,n+2)),e),[]).filter(([e,t])=>{try{return L(e),R(e,String(t)),!0}catch{return!1}}))}var L,R,z,B=e((()=>{L=typeof v.validateHeaderName==`function`?v.validateHeaderName:e=>{if(!/^[\^`\-\w!#$%&'*+.|~]+$/.test(e)){let t=TypeError(`Header name must be a valid HTTP token [${e}]`);throw Object.defineProperty(t,`code`,{value:`ERR_INVALID_HTTP_TOKEN`}),t}},R=typeof v.validateHeaderValue==`function`?v.validateHeaderValue:(e,t)=>{if(/[^\t\u0020-\u007E\u0080-\u00FF]/.test(t)){let t=TypeError(`Invalid character in header content ["${e}"]`);throw Object.defineProperty(t,`code`,{value:`ERR_INVALID_CHAR`}),t}},z=class e extends URLSearchParams{constructor(t){let n=[];if(t instanceof e){let e=t.raw();for(let[t,r]of Object.entries(e))n.push(...r.map(e=>[t,e]))}else if(t!=null)if(typeof t==`object`&&!h.isBoxedPrimitive(t)){let e=t[Symbol.iterator];if(e==null)n.push(...Object.entries(t));else{if(typeof e!=`function`)throw TypeError(`Header pairs must be iterable`);n=[...t].map(e=>{if(typeof e!=`object`||h.isBoxedPrimitive(e))throw TypeError(`Each header pair must be an iterable object`);return[...e]}).map(e=>{if(e.length!==2)throw TypeError(`Each header pair must be a name/value tuple`);return[...e]})}}else throw TypeError(`Failed to construct 'Headers': The provided value is not of type '(sequence<sequence<ByteString>> or record<ByteString, ByteString>)`);return n=n.length>0?n.map(([e,t])=>(L(e),R(e,String(t)),[String(e).toLowerCase(),String(t)])):void 0,super(n),new Proxy(this,{get(e,t,n){switch(t){case`append`:case`set`:return(n,r)=>(L(n),R(n,String(r)),URLSearchParams.prototype[t].call(e,String(n).toLowerCase(),String(r)));case`delete`:case`has`:case`getAll`:return n=>(L(n),URLSearchParams.prototype[t].call(e,String(n).toLowerCase()));case`keys`:return()=>(e.sort(),new Set(URLSearchParams.prototype.keys.call(e)).keys());default:return Reflect.get(e,t,n)}}})}get[Symbol.toStringTag](){return this.constructor.name}toString(){return Object.prototype.toString.call(this)}get(e){let t=this.getAll(e);if(t.length===0)return null;let n=t.join(`, `);return/^content-encoding$/i.test(e)&&(n=n.toLowerCase()),n}forEach(e,t=void 0){for(let n of this.keys())Reflect.apply(e,t,[this.get(n),n,this])}*values(){for(let e of this.keys())yield this.get(e)}*entries(){for(let e of this.keys())yield[e,this.get(e)]}[Symbol.iterator](){return this.entries()}raw(){return[...this.keys()].reduce((e,t)=>(e[t]=this.getAll(t),e),{})}[Symbol.for(`nodejs.util.inspect.custom`)](){return[...this.keys()].reduce((e,t)=>{let n=this.getAll(t);return t===`host`?e[t]=n[0]:e[t]=n.length>1?n:n[0],e},{})}},Object.defineProperties(z.prototype,[`get`,`entries`,`forEach`,`values`].reduce((e,t)=>(e[t]={enumerable:!0},e),{}))})),V,H,U=e((()=>{V=new Set([301,302,303,307,308]),H=e=>V.has(e)})),W,G,se=e((()=>{B(),I(),U(),W=Symbol(`Response internals`),G=class e extends j{constructor(e=null,t={}){super(e,t);let n=t.status==null?200:t.status,r=new z(t.headers);if(e!==null&&!r.has(`Content-Type`)){let t=P(e,this);t&&r.append(`Content-Type`,t)}this[W]={type:`default`,url:t.url,status:n,statusText:t.statusText||``,headers:r,counter:t.counter,highWaterMark:t.highWaterMark}}get type(){return this[W].type}get url(){return this[W].url||``}get status(){return this[W].status}get ok(){return this[W].status>=200&&this[W].status<300}get redirected(){return this[W].counter>0}get statusText(){return this[W].statusText}get headers(){return this[W].headers}get highWaterMark(){return this[W].highWaterMark}clone(){return new e(M(this,this.highWaterMark),{type:this.type,url:this.url,status:this.status,statusText:this.statusText,headers:this.headers,ok:this.ok,redirected:this.redirected,size:this.size,highWaterMark:this.highWaterMark})}static redirect(t,n=302){if(!H(n))throw RangeError(`Failed to execute "redirect" on "response": Invalid status code`);return new e(null,{headers:{location:new URL(t).toString()},status:n})}static error(){let t=new e(null,{status:0,statusText:``});return t[W].type=`error`,t}static json(t=void 0,n={}){let r=JSON.stringify(t);if(r===void 0)throw TypeError(`data is not JSON serializable`);let i=new z(n&&n.headers);return i.has(`content-type`)||i.set(`content-type`,`application/json`),new e(r,{...n,headers:i})}get[Symbol.toStringTag](){return`Response`}},Object.defineProperties(G.prototype,{type:{enumerable:!0},url:{enumerable:!0},status:{enumerable:!0},ok:{enumerable:!0},redirected:{enumerable:!0},statusText:{enumerable:!0},headers:{enumerable:!0},clone:{enumerable:!0}})})),K,ce=e((()=>{K=e=>{if(e.search)return e.search;let t=e.href.length-1,n=e.hash||(e.href[t]===`#`?`#`:``);return e.href[t-n.length]===`?`?`?`:``}}));function q(e,t=!1){return e==null||(e=new URL(e),/^(about|blob|data):$/.test(e.protocol))?`no-referrer`:(e.username=``,e.password=``,e.hash=``,t&&(e.pathname=``,e.search=``),e)}function le(e){if(!Y.has(e))throw TypeError(`Invalid referrerPolicy: ${e}`);return e}function ue(e){if(/^(http|ws)s:$/.test(e.protocol))return!0;let t=e.host.replace(/(^\[)|(]$)/g,``),n=_(t);return n===4&&/^127\./.test(t)||n===6&&/^(((0+:){7})|(::(0+:){0,6}))0*1$/.test(t)?!0:e.host===`localhost`||e.host.endsWith(`.localhost`)?!1:e.protocol===`file:`}function J(e){return/^about:(blank|srcdoc)$/.test(e)||e.protocol===`data:`||/^(blob|filesystem):$/.test(e.protocol)?!0:ue(e)}function de(e,{referrerURLCallback:t,referrerOriginCallback:n}={}){if(e.referrer===`no-referrer`||e.referrerPolicy===``)return null;let r=e.referrerPolicy;if(e.referrer===`about:client`)return`no-referrer`;let i=e.referrer,a=q(i),o=q(i,!0);a.toString().length>4096&&(a=o),t&&(a=t(a)),n&&(o=n(o));let s=new URL(e.url);switch(r){case`no-referrer`:return`no-referrer`;case`origin`:return o;case`unsafe-url`:return a;case`strict-origin`:return J(a)&&!J(s)?`no-referrer`:o.toString();case`strict-origin-when-cross-origin`:return a.origin===s.origin?a:J(a)&&!J(s)?`no-referrer`:o;case`same-origin`:return a.origin===s.origin?a:`no-referrer`;case`origin-when-cross-origin`:return a.origin===s.origin?a:o;case`no-referrer-when-downgrade`:return J(a)&&!J(s)?`no-referrer`:a;default:throw TypeError(`Invalid referrerPolicy: ${r}`)}}function fe(e){let t=(e.get(`referrer-policy`)||``).split(/[,\s]+/),n=``;for(let e of t)e&&Y.has(e)&&(n=e);return n}var Y,X,pe=e((()=>{Y=new Set([``,`no-referrer`,`no-referrer-when-downgrade`,`same-origin`,`origin`,`strict-origin`,`origin-when-cross-origin`,`strict-origin-when-cross-origin`,`unsafe-url`]),X=`strict-origin-when-cross-origin`})),Z,Q,me,$,he,ge=e((()=>{B(),I(),D(),ce(),pe(),Z=Symbol(`Request internals`),Q=e=>typeof e==`object`&&typeof e[Z]==`object`,me=p(()=>{},`.data is not a valid RequestInit property, use .body instead`,`https://github.com/node-fetch/node-fetch/issues/1000 (request)`),$=class e extends j{constructor(e,t={}){let n;if(Q(e)?n=new URL(e.url):(n=new URL(e),e={}),n.username!==``||n.password!==``)throw TypeError(`${n} is an url with embedded credentials.`);let r=t.method||e.method||`GET`;if(/^(delete|get|head|options|post|put)$/i.test(r)&&(r=r.toUpperCase()),!Q(t)&&`data`in t&&me(),(t.body!=null||Q(e)&&e.body!==null)&&(r===`GET`||r===`HEAD`))throw TypeError(`Request with GET/HEAD method cannot have body`);let i=t.body?t.body:Q(e)&&e.body!==null?M(e):null;super(i,{size:t.size||e.size||0});let a=new z(t.headers||e.headers||{});if(i!==null&&!a.has(`Content-Type`)){let e=P(i,this);e&&a.set(`Content-Type`,e)}let o=Q(e)?e.signal:null;if(`signal`in t&&(o=t.signal),o!=null&&!T(o))throw TypeError(`Expected signal to be an instanceof AbortSignal or EventTarget`);let s=t.referrer==null?e.referrer:t.referrer;if(s===``)s=`no-referrer`;else if(s){let e=new URL(s);s=/^about:(\/\/)?client$/.test(e)?`client`:e}else s=void 0;this[Z]={method:r,redirect:t.redirect||e.redirect||`follow`,headers:a,parsedURL:n,signal:o,referrer:s},this.follow=t.follow===void 0?e.follow===void 0?20:e.follow:t.follow,this.compress=t.compress===void 0?e.compress===void 0?!0:e.compress:t.compress,this.counter=t.counter||e.counter||0,this.agent=t.agent||e.agent,this.highWaterMark=t.highWaterMark||e.highWaterMark||16384,this.insecureHTTPParser=t.insecureHTTPParser||e.insecureHTTPParser||!1,this.referrerPolicy=t.referrerPolicy||e.referrerPolicy||``}get method(){return this[Z].method}get url(){return c(this[Z].parsedURL)}get headers(){return this[Z].headers}get redirect(){return this[Z].redirect}get signal(){return this[Z].signal}get referrer(){if(this[Z].referrer===`no-referrer`)return``;if(this[Z].referrer===`client`)return`about:client`;if(this[Z].referrer)return this[Z].referrer.toString()}get referrerPolicy(){return this[Z].referrerPolicy}set referrerPolicy(e){this[Z].referrerPolicy=le(e)}clone(){return new e(this)}get[Symbol.toStringTag](){return`Request`}},Object.defineProperties($.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0},referrer:{enumerable:!0},referrerPolicy:{enumerable:!0}}),he=e=>{let{parsedURL:t}=e[Z],n=new z(e[Z].headers);n.has(`Accept`)||n.set(`Accept`,`*/*`);let r=null;if(e.body===null&&/^(post|put)$/i.test(e.method)&&(r=`0`),e.body!==null){let t=F(e);typeof t==`number`&&!Number.isNaN(t)&&(r=String(t))}r&&n.set(`Content-Length`,r),e.referrerPolicy===``&&(e.referrerPolicy=X),e.referrer&&e.referrer!==`no-referrer`?e[Z].referrer=de(e):e[Z].referrer=`no-referrer`,e[Z].referrer instanceof URL&&n.set(`Referer`,e.referrer),n.has(`User-Agent`)||n.set(`User-Agent`,`node-fetch`),e.compress&&!n.has(`Accept-Encoding`)&&n.set(`Accept-Encoding`,`gzip, deflate, br`);let{agent:i}=e;typeof i==`function`&&(i=i(t));let a=K(t);return{parsedURL:t,options:{path:t.pathname+a,method:e.method,headers:n[Symbol.for(`nodejs.util.inspect.custom`)](),insecureHTTPParser:e.insecureHTTPParser,agent:i}}}})),_e,ve=e((()=>{b(),_e=class extends y{constructor(e,t=`aborted`){super(e,t)}}}));async function ye(e,t){return new Promise((n,r)=>{let i=new $(e,t),{parsedURL:a,options:o}=he(i);if(!xe.has(a.protocol))throw TypeError(`node-fetch cannot load ${e}. URL scheme "${a.protocol.replace(/:$/,``)}" is not supported.`);if(a.protocol===`data:`){let e=te(i.url);n(new G(e,{headers:{"Content-Type":e.typeFull}}));return}let s=(a.protocol===`https:`?ee:v).request,{signal:c}=i,l=null,p=()=>{let e=new _e(`The operation was aborted.`);r(e),i.body&&i.body instanceof u.Readable&&i.body.destroy(e),!(!l||!l.body)&&l.body.emit(`error`,e)};if(c&&c.aborted){p();return}let m=()=>{p(),_()},h=s(a.toString(),o);c&&c.addEventListener(`abort`,m);let _=()=>{h.abort(),c&&c.removeEventListener(`abort`,m)};h.on(`error`,e=>{r(new x(`request to ${i.url} failed, reason: ${e.message}`,`system`,e)),_()}),be(h,e=>{l&&l.body&&l.body.destroy(e)}),process.version<`v14`&&h.on(`socket`,e=>{let t;e.prependListener(`end`,()=>{t=e._eventsCount}),e.prependListener(`close`,n=>{if(l&&t<e._eventsCount&&!n){let e=Error(`Premature close`);e.code=`ERR_STREAM_PREMATURE_CLOSE`,l.body.emit(`error`,e)}})}),h.on(`response`,e=>{h.setTimeout(0);let a=oe(e.rawHeaders);if(H(e.statusCode)){let o=a.get(`Location`),s=null;try{s=o===null?null:new URL(o,i.url)}catch{if(i.redirect!==`manual`){r(new x(`uri requested responds with an invalid redirect URL: ${o}`,`invalid-redirect`)),_();return}}switch(i.redirect){case`error`:r(new x(`uri requested responds with a redirect, redirect mode is set to error: ${i.url}`,`no-redirect`)),_();return;case`manual`:break;case`follow`:{if(s===null)break;if(i.counter>=i.follow){r(new x(`maximum redirect reached at: ${i.url}`,`max-redirect`)),_();return}let o={headers:new z(i.headers),follow:i.follow,counter:i.counter+1,agent:i.agent,compress:i.compress,method:i.method,body:M(i),signal:i.signal,size:i.size,referrer:i.referrer,referrerPolicy:i.referrerPolicy};if(!E(i.url,s)||!ie(i.url,s))for(let e of[`authorization`,`www-authenticate`,`cookie`,`cookie2`])o.headers.delete(e);if(e.statusCode!==303&&i.body&&t.body instanceof u.Readable){r(new x(`Cannot follow redirect with body being a readable stream`,`unsupported-redirect`)),_();return}(e.statusCode===303||(e.statusCode===301||e.statusCode===302)&&i.method===`POST`)&&(o.method=`GET`,o.body=void 0,o.headers.delete(`content-length`));let c=fe(a);c&&(o.referrerPolicy=c),n(ye(new $(s,o))),_();return}default:return r(TypeError(`Redirect option '${i.redirect}' is not a valid value of RequestRedirect`))}}c&&e.once(`end`,()=>{c.removeEventListener(`abort`,m)});let o=f(e,new d,e=>{e&&r(e)});process.version<`v12.10`&&e.on(`aborted`,m);let s={url:i.url,status:e.statusCode,statusText:e.statusMessage,headers:a,size:i.size,counter:i.counter,highWaterMark:i.highWaterMark},p=a.get(`Content-Encoding`);if(!i.compress||i.method===`HEAD`||p===null||e.statusCode===204||e.statusCode===304){l=new G(o,s),n(l);return}let v={flush:g.Z_SYNC_FLUSH,finishFlush:g.Z_SYNC_FLUSH};if(p===`gzip`||p===`x-gzip`){o=f(o,g.createGunzip(v),e=>{e&&r(e)}),l=new G(o,s),n(l);return}if(p===`deflate`||p===`x-deflate`){let t=f(e,new d,e=>{e&&r(e)});t.once(`data`,e=>{o=(e[0]&15)==8?f(o,g.createInflate(),e=>{e&&r(e)}):f(o,g.createInflateRaw(),e=>{e&&r(e)}),l=new G(o,s),n(l)}),t.once(`end`,()=>{l||(l=new G(o,s),n(l))});return}if(p===`br`){o=f(o,g.createBrotliDecompress(),e=>{e&&r(e)}),l=new G(o,s),n(l);return}l=new G(o,s),n(l)}),ae(h,i).catch(r)})}function be(e,t){let n=l.from(`0\r
3
3
  \r
4
4
  `),r=!1,i=!1,a;e.on(`response`,e=>{let{headers:t}=e;r=t[`transfer-encoding`]===`chunked`&&!t[`content-length`]}),e.on(`socket`,o=>{let s=()=>{if(r&&!i){let e=Error(`Premature close`);e.code=`ERR_STREAM_PREMATURE_CLOSE`,t(e)}},c=e=>{i=l.compare(e.slice(-5),n)===0,!i&&a&&(i=l.compare(a.slice(-3),n.slice(0,3))===0&&l.compare(e.slice(-2),n.slice(3))===0),a=e};o.prependListener(`close`,s),o.on(`data`,c),e.on(`close`,()=>{o.removeListener(`close`,s),o.removeListener(`data`,c)})})}var xe;e((()=>{ne(),I(),se(),B(),ge(),re(),ve(),U(),n(),D(),pe(),s(),xe=new Set([`data:`,`http:`,`https:`])}))();export{ye as default};
@@ -1,4 +1,4 @@
1
1
  #!/usr/bin/env node
2
- import{Nt as e}from"./index.mjs";import{a as t,i as n,n as r,o as i,r as a,s as o,t as s}from"./from-Bra_AO5N.mjs";import{format as c}from"node:url";import{Buffer as l}from"node:buffer";import u,{PassThrough as d,pipeline as f}from"node:stream";import{deprecate as p,promisify as m,types as h}from"node:util";import g from"node:zlib";import{isIP as _}from"node:net";import v from"node:http";import ee from"node:https";function te(e){if(!/^data:/i.test(e))throw TypeError('`uri` does not appear to be a Data URI (must begin with "data:")');e=e.replace(/\r?\n/g,``);let t=e.indexOf(`,`);if(t===-1||t<=4)throw TypeError(`malformed data: URI`);let n=e.substring(5,t).split(`;`),r=``,i=!1,a=n[0]||`text/plain`,o=a;for(let e=1;e<n.length;e++)n[e]===`base64`?i=!0:n[e]&&(o+=`;${n[e]}`,n[e].indexOf(`charset=`)===0&&(r=n[e].substring(8)));!n[0]&&!r.length&&(o+=`;charset=US-ASCII`,r=`US-ASCII`);let s=i?`base64`:`ascii`,c=unescape(e.substring(t+1)),l=Buffer.from(c,s);return l.type=a,l.typeFull=o,l.charset=r,l}var ne=e((()=>{})),y,b=e((()=>{y=class extends Error{constructor(e,t){super(e),Error.captureStackTrace(this,this.constructor),this.type=t}get name(){return this.constructor.name}get[Symbol.toStringTag](){return this.constructor.name}}})),x,re=e((()=>{b(),x=class extends y{constructor(e,t,n){super(e,t),n&&(this.code=this.errno=n.code,this.erroredSysCall=n.syscall)}}})),S,C,w,T,E,ie,D=e((()=>{S=Symbol.toStringTag,C=e=>typeof e==`object`&&typeof e.append==`function`&&typeof e.delete==`function`&&typeof e.get==`function`&&typeof e.getAll==`function`&&typeof e.has==`function`&&typeof e.set==`function`&&typeof e.sort==`function`&&e[S]===`URLSearchParams`,w=e=>e&&typeof e==`object`&&typeof e.arrayBuffer==`function`&&typeof e.type==`string`&&typeof e.stream==`function`&&typeof e.constructor==`function`&&/^(Blob|File)$/.test(e[S]),T=e=>typeof e==`object`&&(e[S]===`AbortSignal`||e[S]===`EventTarget`),E=(e,t)=>{let n=new URL(t).hostname,r=new URL(e).hostname;return n===r||n.endsWith(`.${r}`)},ie=(e,t)=>new URL(t).protocol===new URL(e).protocol}));async function O(e){if(e[A].disturbed)throw TypeError(`body used already for: ${e.url}`);if(e[A].disturbed=!0,e[A].error)throw e[A].error;let{body:t}=e;if(t===null||!(t instanceof u))return l.alloc(0);let n=[],r=0;try{for await(let i of t){if(e.size>0&&r+i.length>e.size){let n=new x(`content size at ${e.url} over limit: ${e.size}`,`max-size`);throw t.destroy(n),n}r+=i.length,n.push(i)}}catch(t){throw t instanceof y?t:new x(`Invalid response body while trying to fetch ${e.url}: ${t.message}`,`system`,t)}if(t.readableEnded===!0||t._readableState.ended===!0)try{return n.every(e=>typeof e==`string`)?l.from(n.join(``)):l.concat(n,r)}catch(t){throw new x(`Could not create Buffer from response body for ${e.url}: ${t.message}`,`system`,t)}else throw new x(`Premature close of server response while trying to fetch ${e.url}`)}var k,A,j,M,N,P,F,ae,I=e((()=>{o(),n(),re(),b(),D(),k=m(u.pipeline),A=Symbol(`Body internals`),j=class{constructor(e,{size:t=0}={}){let n=null;e===null?e=null:C(e)?e=l.from(e.toString()):w(e)||l.isBuffer(e)||(h.isAnyArrayBuffer(e)?e=l.from(e):ArrayBuffer.isView(e)?e=l.from(e.buffer,e.byteOffset,e.byteLength):e instanceof u||(e instanceof r?(e=a(e),n=e.type.split(`=`)[1]):e=l.from(String(e))));let i=e;l.isBuffer(e)?i=u.Readable.from(e):w(e)&&(i=u.Readable.from(e.stream())),this[A]={body:e,stream:i,boundary:n,disturbed:!1,error:null},this.size=t,e instanceof u&&e.on(`error`,e=>{let t=e instanceof y?e:new x(`Invalid response body while trying to fetch ${this.url}: ${e.message}`,`system`,e);this[A].error=t})}get body(){return this[A].stream}get bodyUsed(){return this[A].disturbed}async arrayBuffer(){let{buffer:e,byteOffset:t,byteLength:n}=await O(this);return e.slice(t,t+n)}async formData(){let e=this.headers.get(`content-type`);if(e.startsWith(`application/x-www-form-urlencoded`)){let e=new r,t=new URLSearchParams(await this.text());for(let[n,r]of t)e.append(n,r);return e}let{toFormData:t}=await import(`./multipart-parser-4wzMiNnD.mjs`);return t(this.body,e)}async blob(){let e=this.headers&&this.headers.get(`content-type`)||this[A].body&&this[A].body.type||``;return new i([await this.arrayBuffer()],{type:e})}async json(){let e=await this.text();return JSON.parse(e)}async text(){let e=await O(this);return new TextDecoder().decode(e)}buffer(){return O(this)}},j.prototype.buffer=p(j.prototype.buffer,`Please use 'response.arrayBuffer()' instead of 'response.buffer()'`,`node-fetch#buffer`),Object.defineProperties(j.prototype,{body:{enumerable:!0},bodyUsed:{enumerable:!0},arrayBuffer:{enumerable:!0},blob:{enumerable:!0},json:{enumerable:!0},text:{enumerable:!0},data:{get:p(()=>{},`data doesn't exist, use json(), text(), arrayBuffer(), or body instead`,`https://github.com/node-fetch/node-fetch/issues/1000 (response)`)}}),M=(e,t)=>{let n,r,{body:i}=e[A];if(e.bodyUsed)throw Error(`cannot clone body after it is used`);return i instanceof u&&typeof i.getBoundary!=`function`&&(n=new d({highWaterMark:t}),r=new d({highWaterMark:t}),i.pipe(n),i.pipe(r),e[A].stream=n,i=r),i},N=p(e=>e.getBoundary(),`form-data doesn't follow the spec and requires special treatment. Use alternative package`,`https://github.com/node-fetch/node-fetch/issues/1167`),P=(e,t)=>e===null?null:typeof e==`string`?`text/plain;charset=UTF-8`:C(e)?`application/x-www-form-urlencoded;charset=UTF-8`:w(e)?e.type||null:l.isBuffer(e)||h.isAnyArrayBuffer(e)||ArrayBuffer.isView(e)?null:e instanceof r?`multipart/form-data; boundary=${t[A].boundary}`:e&&typeof e.getBoundary==`function`?`multipart/form-data;boundary=${N(e)}`:e instanceof u?null:`text/plain;charset=UTF-8`,F=e=>{let{body:t}=e[A];return t===null?0:w(t)?t.size:l.isBuffer(t)?t.length:t&&typeof t.getLengthSync==`function`&&t.hasKnownLength&&t.hasKnownLength()?t.getLengthSync():null},ae=async(e,{body:t})=>{t===null?e.end():await k(t,e)}}));function oe(e=[]){return new z(e.reduce((e,t,n,r)=>(n%2==0&&e.push(r.slice(n,n+2)),e),[]).filter(([e,t])=>{try{return L(e),R(e,String(t)),!0}catch{return!1}}))}var L,R,z,B=e((()=>{L=typeof v.validateHeaderName==`function`?v.validateHeaderName:e=>{if(!/^[\^`\-\w!#$%&'*+.|~]+$/.test(e)){let t=TypeError(`Header name must be a valid HTTP token [${e}]`);throw Object.defineProperty(t,`code`,{value:`ERR_INVALID_HTTP_TOKEN`}),t}},R=typeof v.validateHeaderValue==`function`?v.validateHeaderValue:(e,t)=>{if(/[^\t\u0020-\u007E\u0080-\u00FF]/.test(t)){let t=TypeError(`Invalid character in header content ["${e}"]`);throw Object.defineProperty(t,`code`,{value:`ERR_INVALID_CHAR`}),t}},z=class e extends URLSearchParams{constructor(t){let n=[];if(t instanceof e){let e=t.raw();for(let[t,r]of Object.entries(e))n.push(...r.map(e=>[t,e]))}else if(t!=null)if(typeof t==`object`&&!h.isBoxedPrimitive(t)){let e=t[Symbol.iterator];if(e==null)n.push(...Object.entries(t));else{if(typeof e!=`function`)throw TypeError(`Header pairs must be iterable`);n=[...t].map(e=>{if(typeof e!=`object`||h.isBoxedPrimitive(e))throw TypeError(`Each header pair must be an iterable object`);return[...e]}).map(e=>{if(e.length!==2)throw TypeError(`Each header pair must be a name/value tuple`);return[...e]})}}else throw TypeError(`Failed to construct 'Headers': The provided value is not of type '(sequence<sequence<ByteString>> or record<ByteString, ByteString>)`);return n=n.length>0?n.map(([e,t])=>(L(e),R(e,String(t)),[String(e).toLowerCase(),String(t)])):void 0,super(n),new Proxy(this,{get(e,t,n){switch(t){case`append`:case`set`:return(n,r)=>(L(n),R(n,String(r)),URLSearchParams.prototype[t].call(e,String(n).toLowerCase(),String(r)));case`delete`:case`has`:case`getAll`:return n=>(L(n),URLSearchParams.prototype[t].call(e,String(n).toLowerCase()));case`keys`:return()=>(e.sort(),new Set(URLSearchParams.prototype.keys.call(e)).keys());default:return Reflect.get(e,t,n)}}})}get[Symbol.toStringTag](){return this.constructor.name}toString(){return Object.prototype.toString.call(this)}get(e){let t=this.getAll(e);if(t.length===0)return null;let n=t.join(`, `);return/^content-encoding$/i.test(e)&&(n=n.toLowerCase()),n}forEach(e,t=void 0){for(let n of this.keys())Reflect.apply(e,t,[this.get(n),n,this])}*values(){for(let e of this.keys())yield this.get(e)}*entries(){for(let e of this.keys())yield[e,this.get(e)]}[Symbol.iterator](){return this.entries()}raw(){return[...this.keys()].reduce((e,t)=>(e[t]=this.getAll(t),e),{})}[Symbol.for(`nodejs.util.inspect.custom`)](){return[...this.keys()].reduce((e,t)=>{let n=this.getAll(t);return t===`host`?e[t]=n[0]:e[t]=n.length>1?n:n[0],e},{})}},Object.defineProperties(z.prototype,[`get`,`entries`,`forEach`,`values`].reduce((e,t)=>(e[t]={enumerable:!0},e),{}))})),V,H,U=e((()=>{V=new Set([301,302,303,307,308]),H=e=>V.has(e)})),W,G,se=e((()=>{B(),I(),U(),W=Symbol(`Response internals`),G=class e extends j{constructor(e=null,t={}){super(e,t);let n=t.status==null?200:t.status,r=new z(t.headers);if(e!==null&&!r.has(`Content-Type`)){let t=P(e,this);t&&r.append(`Content-Type`,t)}this[W]={type:`default`,url:t.url,status:n,statusText:t.statusText||``,headers:r,counter:t.counter,highWaterMark:t.highWaterMark}}get type(){return this[W].type}get url(){return this[W].url||``}get status(){return this[W].status}get ok(){return this[W].status>=200&&this[W].status<300}get redirected(){return this[W].counter>0}get statusText(){return this[W].statusText}get headers(){return this[W].headers}get highWaterMark(){return this[W].highWaterMark}clone(){return new e(M(this,this.highWaterMark),{type:this.type,url:this.url,status:this.status,statusText:this.statusText,headers:this.headers,ok:this.ok,redirected:this.redirected,size:this.size,highWaterMark:this.highWaterMark})}static redirect(t,n=302){if(!H(n))throw RangeError(`Failed to execute "redirect" on "response": Invalid status code`);return new e(null,{headers:{location:new URL(t).toString()},status:n})}static error(){let t=new e(null,{status:0,statusText:``});return t[W].type=`error`,t}static json(t=void 0,n={}){let r=JSON.stringify(t);if(r===void 0)throw TypeError(`data is not JSON serializable`);let i=new z(n&&n.headers);return i.has(`content-type`)||i.set(`content-type`,`application/json`),new e(r,{...n,headers:i})}get[Symbol.toStringTag](){return`Response`}},Object.defineProperties(G.prototype,{type:{enumerable:!0},url:{enumerable:!0},status:{enumerable:!0},ok:{enumerable:!0},redirected:{enumerable:!0},statusText:{enumerable:!0},headers:{enumerable:!0},clone:{enumerable:!0}})})),K,ce=e((()=>{K=e=>{if(e.search)return e.search;let t=e.href.length-1,n=e.hash||(e.href[t]===`#`?`#`:``);return e.href[t-n.length]===`?`?`?`:``}}));function q(e,t=!1){return e==null||(e=new URL(e),/^(about|blob|data):$/.test(e.protocol))?`no-referrer`:(e.username=``,e.password=``,e.hash=``,t&&(e.pathname=``,e.search=``),e)}function le(e){if(!Y.has(e))throw TypeError(`Invalid referrerPolicy: ${e}`);return e}function ue(e){if(/^(http|ws)s:$/.test(e.protocol))return!0;let t=e.host.replace(/(^\[)|(]$)/g,``),n=_(t);return n===4&&/^127\./.test(t)||n===6&&/^(((0+:){7})|(::(0+:){0,6}))0*1$/.test(t)?!0:e.host===`localhost`||e.host.endsWith(`.localhost`)?!1:e.protocol===`file:`}function J(e){return/^about:(blank|srcdoc)$/.test(e)||e.protocol===`data:`||/^(blob|filesystem):$/.test(e.protocol)?!0:ue(e)}function de(e,{referrerURLCallback:t,referrerOriginCallback:n}={}){if(e.referrer===`no-referrer`||e.referrerPolicy===``)return null;let r=e.referrerPolicy;if(e.referrer===`about:client`)return`no-referrer`;let i=e.referrer,a=q(i),o=q(i,!0);a.toString().length>4096&&(a=o),t&&(a=t(a)),n&&(o=n(o));let s=new URL(e.url);switch(r){case`no-referrer`:return`no-referrer`;case`origin`:return o;case`unsafe-url`:return a;case`strict-origin`:return J(a)&&!J(s)?`no-referrer`:o.toString();case`strict-origin-when-cross-origin`:return a.origin===s.origin?a:J(a)&&!J(s)?`no-referrer`:o;case`same-origin`:return a.origin===s.origin?a:`no-referrer`;case`origin-when-cross-origin`:return a.origin===s.origin?a:o;case`no-referrer-when-downgrade`:return J(a)&&!J(s)?`no-referrer`:a;default:throw TypeError(`Invalid referrerPolicy: ${r}`)}}function fe(e){let t=(e.get(`referrer-policy`)||``).split(/[,\s]+/),n=``;for(let e of t)e&&Y.has(e)&&(n=e);return n}var Y,X,pe=e((()=>{Y=new Set([``,`no-referrer`,`no-referrer-when-downgrade`,`same-origin`,`origin`,`strict-origin`,`origin-when-cross-origin`,`strict-origin-when-cross-origin`,`unsafe-url`]),X=`strict-origin-when-cross-origin`})),Z,Q,me,$,he,ge=e((()=>{B(),I(),D(),ce(),pe(),Z=Symbol(`Request internals`),Q=e=>typeof e==`object`&&typeof e[Z]==`object`,me=p(()=>{},`.data is not a valid RequestInit property, use .body instead`,`https://github.com/node-fetch/node-fetch/issues/1000 (request)`),$=class e extends j{constructor(e,t={}){let n;if(Q(e)?n=new URL(e.url):(n=new URL(e),e={}),n.username!==``||n.password!==``)throw TypeError(`${n} is an url with embedded credentials.`);let r=t.method||e.method||`GET`;if(/^(delete|get|head|options|post|put)$/i.test(r)&&(r=r.toUpperCase()),!Q(t)&&`data`in t&&me(),(t.body!=null||Q(e)&&e.body!==null)&&(r===`GET`||r===`HEAD`))throw TypeError(`Request with GET/HEAD method cannot have body`);let i=t.body?t.body:Q(e)&&e.body!==null?M(e):null;super(i,{size:t.size||e.size||0});let a=new z(t.headers||e.headers||{});if(i!==null&&!a.has(`Content-Type`)){let e=P(i,this);e&&a.set(`Content-Type`,e)}let o=Q(e)?e.signal:null;if(`signal`in t&&(o=t.signal),o!=null&&!T(o))throw TypeError(`Expected signal to be an instanceof AbortSignal or EventTarget`);let s=t.referrer==null?e.referrer:t.referrer;if(s===``)s=`no-referrer`;else if(s){let e=new URL(s);s=/^about:(\/\/)?client$/.test(e)?`client`:e}else s=void 0;this[Z]={method:r,redirect:t.redirect||e.redirect||`follow`,headers:a,parsedURL:n,signal:o,referrer:s},this.follow=t.follow===void 0?e.follow===void 0?20:e.follow:t.follow,this.compress=t.compress===void 0?e.compress===void 0?!0:e.compress:t.compress,this.counter=t.counter||e.counter||0,this.agent=t.agent||e.agent,this.highWaterMark=t.highWaterMark||e.highWaterMark||16384,this.insecureHTTPParser=t.insecureHTTPParser||e.insecureHTTPParser||!1,this.referrerPolicy=t.referrerPolicy||e.referrerPolicy||``}get method(){return this[Z].method}get url(){return c(this[Z].parsedURL)}get headers(){return this[Z].headers}get redirect(){return this[Z].redirect}get signal(){return this[Z].signal}get referrer(){if(this[Z].referrer===`no-referrer`)return``;if(this[Z].referrer===`client`)return`about:client`;if(this[Z].referrer)return this[Z].referrer.toString()}get referrerPolicy(){return this[Z].referrerPolicy}set referrerPolicy(e){this[Z].referrerPolicy=le(e)}clone(){return new e(this)}get[Symbol.toStringTag](){return`Request`}},Object.defineProperties($.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0},referrer:{enumerable:!0},referrerPolicy:{enumerable:!0}}),he=e=>{let{parsedURL:t}=e[Z],n=new z(e[Z].headers);n.has(`Accept`)||n.set(`Accept`,`*/*`);let r=null;if(e.body===null&&/^(post|put)$/i.test(e.method)&&(r=`0`),e.body!==null){let t=F(e);typeof t==`number`&&!Number.isNaN(t)&&(r=String(t))}r&&n.set(`Content-Length`,r),e.referrerPolicy===``&&(e.referrerPolicy=X),e.referrer&&e.referrer!==`no-referrer`?e[Z].referrer=de(e):e[Z].referrer=`no-referrer`,e[Z].referrer instanceof URL&&n.set(`Referer`,e.referrer),n.has(`User-Agent`)||n.set(`User-Agent`,`node-fetch`),e.compress&&!n.has(`Accept-Encoding`)&&n.set(`Accept-Encoding`,`gzip, deflate, br`);let{agent:i}=e;typeof i==`function`&&(i=i(t));let a=K(t);return{parsedURL:t,options:{path:t.pathname+a,method:e.method,headers:n[Symbol.for(`nodejs.util.inspect.custom`)](),insecureHTTPParser:e.insecureHTTPParser,agent:i}}}})),_e,ve=e((()=>{b(),_e=class extends y{constructor(e,t=`aborted`){super(e,t)}}}));async function ye(e,t){return new Promise((n,r)=>{let i=new $(e,t),{parsedURL:a,options:o}=he(i);if(!xe.has(a.protocol))throw TypeError(`node-fetch cannot load ${e}. URL scheme "${a.protocol.replace(/:$/,``)}" is not supported.`);if(a.protocol===`data:`){let e=te(i.url);n(new G(e,{headers:{"Content-Type":e.typeFull}}));return}let s=(a.protocol===`https:`?ee:v).request,{signal:c}=i,l=null,p=()=>{let e=new _e(`The operation was aborted.`);r(e),i.body&&i.body instanceof u.Readable&&i.body.destroy(e),!(!l||!l.body)&&l.body.emit(`error`,e)};if(c&&c.aborted){p();return}let m=()=>{p(),_()},h=s(a.toString(),o);c&&c.addEventListener(`abort`,m);let _=()=>{h.abort(),c&&c.removeEventListener(`abort`,m)};h.on(`error`,e=>{r(new x(`request to ${i.url} failed, reason: ${e.message}`,`system`,e)),_()}),be(h,e=>{l&&l.body&&l.body.destroy(e)}),process.version<`v14`&&h.on(`socket`,e=>{let t;e.prependListener(`end`,()=>{t=e._eventsCount}),e.prependListener(`close`,n=>{if(l&&t<e._eventsCount&&!n){let e=Error(`Premature close`);e.code=`ERR_STREAM_PREMATURE_CLOSE`,l.body.emit(`error`,e)}})}),h.on(`response`,e=>{h.setTimeout(0);let a=oe(e.rawHeaders);if(H(e.statusCode)){let o=a.get(`Location`),s=null;try{s=o===null?null:new URL(o,i.url)}catch{if(i.redirect!==`manual`){r(new x(`uri requested responds with an invalid redirect URL: ${o}`,`invalid-redirect`)),_();return}}switch(i.redirect){case`error`:r(new x(`uri requested responds with a redirect, redirect mode is set to error: ${i.url}`,`no-redirect`)),_();return;case`manual`:break;case`follow`:{if(s===null)break;if(i.counter>=i.follow){r(new x(`maximum redirect reached at: ${i.url}`,`max-redirect`)),_();return}let o={headers:new z(i.headers),follow:i.follow,counter:i.counter+1,agent:i.agent,compress:i.compress,method:i.method,body:M(i),signal:i.signal,size:i.size,referrer:i.referrer,referrerPolicy:i.referrerPolicy};if(!E(i.url,s)||!ie(i.url,s))for(let e of[`authorization`,`www-authenticate`,`cookie`,`cookie2`])o.headers.delete(e);if(e.statusCode!==303&&i.body&&t.body instanceof u.Readable){r(new x(`Cannot follow redirect with body being a readable stream`,`unsupported-redirect`)),_();return}(e.statusCode===303||(e.statusCode===301||e.statusCode===302)&&i.method===`POST`)&&(o.method=`GET`,o.body=void 0,o.headers.delete(`content-length`));let c=fe(a);c&&(o.referrerPolicy=c),n(ye(new $(s,o))),_();return}default:return r(TypeError(`Redirect option '${i.redirect}' is not a valid value of RequestRedirect`))}}c&&e.once(`end`,()=>{c.removeEventListener(`abort`,m)});let o=f(e,new d,e=>{e&&r(e)});process.version<`v12.10`&&e.on(`aborted`,m);let s={url:i.url,status:e.statusCode,statusText:e.statusMessage,headers:a,size:i.size,counter:i.counter,highWaterMark:i.highWaterMark},p=a.get(`Content-Encoding`);if(!i.compress||i.method===`HEAD`||p===null||e.statusCode===204||e.statusCode===304){l=new G(o,s),n(l);return}let v={flush:g.Z_SYNC_FLUSH,finishFlush:g.Z_SYNC_FLUSH};if(p===`gzip`||p===`x-gzip`){o=f(o,g.createGunzip(v),e=>{e&&r(e)}),l=new G(o,s),n(l);return}if(p===`deflate`||p===`x-deflate`){let t=f(e,new d,e=>{e&&r(e)});t.once(`data`,e=>{o=(e[0]&15)==8?f(o,g.createInflate(),e=>{e&&r(e)}):f(o,g.createInflateRaw(),e=>{e&&r(e)}),l=new G(o,s),n(l)}),t.once(`end`,()=>{l||(l=new G(o,s),n(l))});return}if(p===`br`){o=f(o,g.createBrotliDecompress(),e=>{e&&r(e)}),l=new G(o,s),n(l);return}l=new G(o,s),n(l)}),ae(h,i).catch(r)})}function be(e,t){let n=l.from(`0\r
2
+ import{Nt as e}from"./index.mjs";import{a as t,i as n,n as r,o as i,r as a,s as o,t as s}from"./from-DizeILWM.mjs";import{format as c}from"node:url";import{Buffer as l}from"node:buffer";import u,{PassThrough as d,pipeline as f}from"node:stream";import{deprecate as p,promisify as m,types as h}from"node:util";import g from"node:zlib";import{isIP as _}from"node:net";import v from"node:http";import ee from"node:https";function te(e){if(!/^data:/i.test(e))throw TypeError('`uri` does not appear to be a Data URI (must begin with "data:")');e=e.replace(/\r?\n/g,``);let t=e.indexOf(`,`);if(t===-1||t<=4)throw TypeError(`malformed data: URI`);let n=e.substring(5,t).split(`;`),r=``,i=!1,a=n[0]||`text/plain`,o=a;for(let e=1;e<n.length;e++)n[e]===`base64`?i=!0:n[e]&&(o+=`;${n[e]}`,n[e].indexOf(`charset=`)===0&&(r=n[e].substring(8)));!n[0]&&!r.length&&(o+=`;charset=US-ASCII`,r=`US-ASCII`);let s=i?`base64`:`ascii`,c=unescape(e.substring(t+1)),l=Buffer.from(c,s);return l.type=a,l.typeFull=o,l.charset=r,l}var ne=e((()=>{})),y,b=e((()=>{y=class extends Error{constructor(e,t){super(e),Error.captureStackTrace(this,this.constructor),this.type=t}get name(){return this.constructor.name}get[Symbol.toStringTag](){return this.constructor.name}}})),x,re=e((()=>{b(),x=class extends y{constructor(e,t,n){super(e,t),n&&(this.code=this.errno=n.code,this.erroredSysCall=n.syscall)}}})),S,C,w,T,E,ie,D=e((()=>{S=Symbol.toStringTag,C=e=>typeof e==`object`&&typeof e.append==`function`&&typeof e.delete==`function`&&typeof e.get==`function`&&typeof e.getAll==`function`&&typeof e.has==`function`&&typeof e.set==`function`&&typeof e.sort==`function`&&e[S]===`URLSearchParams`,w=e=>e&&typeof e==`object`&&typeof e.arrayBuffer==`function`&&typeof e.type==`string`&&typeof e.stream==`function`&&typeof e.constructor==`function`&&/^(Blob|File)$/.test(e[S]),T=e=>typeof e==`object`&&(e[S]===`AbortSignal`||e[S]===`EventTarget`),E=(e,t)=>{let n=new URL(t).hostname,r=new URL(e).hostname;return n===r||n.endsWith(`.${r}`)},ie=(e,t)=>new URL(t).protocol===new URL(e).protocol}));async function O(e){if(e[A].disturbed)throw TypeError(`body used already for: ${e.url}`);if(e[A].disturbed=!0,e[A].error)throw e[A].error;let{body:t}=e;if(t===null||!(t instanceof u))return l.alloc(0);let n=[],r=0;try{for await(let i of t){if(e.size>0&&r+i.length>e.size){let n=new x(`content size at ${e.url} over limit: ${e.size}`,`max-size`);throw t.destroy(n),n}r+=i.length,n.push(i)}}catch(t){throw t instanceof y?t:new x(`Invalid response body while trying to fetch ${e.url}: ${t.message}`,`system`,t)}if(t.readableEnded===!0||t._readableState.ended===!0)try{return n.every(e=>typeof e==`string`)?l.from(n.join(``)):l.concat(n,r)}catch(t){throw new x(`Could not create Buffer from response body for ${e.url}: ${t.message}`,`system`,t)}else throw new x(`Premature close of server response while trying to fetch ${e.url}`)}var k,A,j,M,N,P,F,ae,I=e((()=>{o(),n(),re(),b(),D(),k=m(u.pipeline),A=Symbol(`Body internals`),j=class{constructor(e,{size:t=0}={}){let n=null;e===null?e=null:C(e)?e=l.from(e.toString()):w(e)||l.isBuffer(e)||(h.isAnyArrayBuffer(e)?e=l.from(e):ArrayBuffer.isView(e)?e=l.from(e.buffer,e.byteOffset,e.byteLength):e instanceof u||(e instanceof r?(e=a(e),n=e.type.split(`=`)[1]):e=l.from(String(e))));let i=e;l.isBuffer(e)?i=u.Readable.from(e):w(e)&&(i=u.Readable.from(e.stream())),this[A]={body:e,stream:i,boundary:n,disturbed:!1,error:null},this.size=t,e instanceof u&&e.on(`error`,e=>{let t=e instanceof y?e:new x(`Invalid response body while trying to fetch ${this.url}: ${e.message}`,`system`,e);this[A].error=t})}get body(){return this[A].stream}get bodyUsed(){return this[A].disturbed}async arrayBuffer(){let{buffer:e,byteOffset:t,byteLength:n}=await O(this);return e.slice(t,t+n)}async formData(){let e=this.headers.get(`content-type`);if(e.startsWith(`application/x-www-form-urlencoded`)){let e=new r,t=new URLSearchParams(await this.text());for(let[n,r]of t)e.append(n,r);return e}let{toFormData:t}=await import(`./multipart-parser-u0QlX_zW.mjs`);return t(this.body,e)}async blob(){let e=this.headers&&this.headers.get(`content-type`)||this[A].body&&this[A].body.type||``;return new i([await this.arrayBuffer()],{type:e})}async json(){let e=await this.text();return JSON.parse(e)}async text(){let e=await O(this);return new TextDecoder().decode(e)}buffer(){return O(this)}},j.prototype.buffer=p(j.prototype.buffer,`Please use 'response.arrayBuffer()' instead of 'response.buffer()'`,`node-fetch#buffer`),Object.defineProperties(j.prototype,{body:{enumerable:!0},bodyUsed:{enumerable:!0},arrayBuffer:{enumerable:!0},blob:{enumerable:!0},json:{enumerable:!0},text:{enumerable:!0},data:{get:p(()=>{},`data doesn't exist, use json(), text(), arrayBuffer(), or body instead`,`https://github.com/node-fetch/node-fetch/issues/1000 (response)`)}}),M=(e,t)=>{let n,r,{body:i}=e[A];if(e.bodyUsed)throw Error(`cannot clone body after it is used`);return i instanceof u&&typeof i.getBoundary!=`function`&&(n=new d({highWaterMark:t}),r=new d({highWaterMark:t}),i.pipe(n),i.pipe(r),e[A].stream=n,i=r),i},N=p(e=>e.getBoundary(),`form-data doesn't follow the spec and requires special treatment. Use alternative package`,`https://github.com/node-fetch/node-fetch/issues/1167`),P=(e,t)=>e===null?null:typeof e==`string`?`text/plain;charset=UTF-8`:C(e)?`application/x-www-form-urlencoded;charset=UTF-8`:w(e)?e.type||null:l.isBuffer(e)||h.isAnyArrayBuffer(e)||ArrayBuffer.isView(e)?null:e instanceof r?`multipart/form-data; boundary=${t[A].boundary}`:e&&typeof e.getBoundary==`function`?`multipart/form-data;boundary=${N(e)}`:e instanceof u?null:`text/plain;charset=UTF-8`,F=e=>{let{body:t}=e[A];return t===null?0:w(t)?t.size:l.isBuffer(t)?t.length:t&&typeof t.getLengthSync==`function`&&t.hasKnownLength&&t.hasKnownLength()?t.getLengthSync():null},ae=async(e,{body:t})=>{t===null?e.end():await k(t,e)}}));function oe(e=[]){return new z(e.reduce((e,t,n,r)=>(n%2==0&&e.push(r.slice(n,n+2)),e),[]).filter(([e,t])=>{try{return L(e),R(e,String(t)),!0}catch{return!1}}))}var L,R,z,B=e((()=>{L=typeof v.validateHeaderName==`function`?v.validateHeaderName:e=>{if(!/^[\^`\-\w!#$%&'*+.|~]+$/.test(e)){let t=TypeError(`Header name must be a valid HTTP token [${e}]`);throw Object.defineProperty(t,`code`,{value:`ERR_INVALID_HTTP_TOKEN`}),t}},R=typeof v.validateHeaderValue==`function`?v.validateHeaderValue:(e,t)=>{if(/[^\t\u0020-\u007E\u0080-\u00FF]/.test(t)){let t=TypeError(`Invalid character in header content ["${e}"]`);throw Object.defineProperty(t,`code`,{value:`ERR_INVALID_CHAR`}),t}},z=class e extends URLSearchParams{constructor(t){let n=[];if(t instanceof e){let e=t.raw();for(let[t,r]of Object.entries(e))n.push(...r.map(e=>[t,e]))}else if(t!=null)if(typeof t==`object`&&!h.isBoxedPrimitive(t)){let e=t[Symbol.iterator];if(e==null)n.push(...Object.entries(t));else{if(typeof e!=`function`)throw TypeError(`Header pairs must be iterable`);n=[...t].map(e=>{if(typeof e!=`object`||h.isBoxedPrimitive(e))throw TypeError(`Each header pair must be an iterable object`);return[...e]}).map(e=>{if(e.length!==2)throw TypeError(`Each header pair must be a name/value tuple`);return[...e]})}}else throw TypeError(`Failed to construct 'Headers': The provided value is not of type '(sequence<sequence<ByteString>> or record<ByteString, ByteString>)`);return n=n.length>0?n.map(([e,t])=>(L(e),R(e,String(t)),[String(e).toLowerCase(),String(t)])):void 0,super(n),new Proxy(this,{get(e,t,n){switch(t){case`append`:case`set`:return(n,r)=>(L(n),R(n,String(r)),URLSearchParams.prototype[t].call(e,String(n).toLowerCase(),String(r)));case`delete`:case`has`:case`getAll`:return n=>(L(n),URLSearchParams.prototype[t].call(e,String(n).toLowerCase()));case`keys`:return()=>(e.sort(),new Set(URLSearchParams.prototype.keys.call(e)).keys());default:return Reflect.get(e,t,n)}}})}get[Symbol.toStringTag](){return this.constructor.name}toString(){return Object.prototype.toString.call(this)}get(e){let t=this.getAll(e);if(t.length===0)return null;let n=t.join(`, `);return/^content-encoding$/i.test(e)&&(n=n.toLowerCase()),n}forEach(e,t=void 0){for(let n of this.keys())Reflect.apply(e,t,[this.get(n),n,this])}*values(){for(let e of this.keys())yield this.get(e)}*entries(){for(let e of this.keys())yield[e,this.get(e)]}[Symbol.iterator](){return this.entries()}raw(){return[...this.keys()].reduce((e,t)=>(e[t]=this.getAll(t),e),{})}[Symbol.for(`nodejs.util.inspect.custom`)](){return[...this.keys()].reduce((e,t)=>{let n=this.getAll(t);return t===`host`?e[t]=n[0]:e[t]=n.length>1?n:n[0],e},{})}},Object.defineProperties(z.prototype,[`get`,`entries`,`forEach`,`values`].reduce((e,t)=>(e[t]={enumerable:!0},e),{}))})),V,H,U=e((()=>{V=new Set([301,302,303,307,308]),H=e=>V.has(e)})),W,G,se=e((()=>{B(),I(),U(),W=Symbol(`Response internals`),G=class e extends j{constructor(e=null,t={}){super(e,t);let n=t.status==null?200:t.status,r=new z(t.headers);if(e!==null&&!r.has(`Content-Type`)){let t=P(e,this);t&&r.append(`Content-Type`,t)}this[W]={type:`default`,url:t.url,status:n,statusText:t.statusText||``,headers:r,counter:t.counter,highWaterMark:t.highWaterMark}}get type(){return this[W].type}get url(){return this[W].url||``}get status(){return this[W].status}get ok(){return this[W].status>=200&&this[W].status<300}get redirected(){return this[W].counter>0}get statusText(){return this[W].statusText}get headers(){return this[W].headers}get highWaterMark(){return this[W].highWaterMark}clone(){return new e(M(this,this.highWaterMark),{type:this.type,url:this.url,status:this.status,statusText:this.statusText,headers:this.headers,ok:this.ok,redirected:this.redirected,size:this.size,highWaterMark:this.highWaterMark})}static redirect(t,n=302){if(!H(n))throw RangeError(`Failed to execute "redirect" on "response": Invalid status code`);return new e(null,{headers:{location:new URL(t).toString()},status:n})}static error(){let t=new e(null,{status:0,statusText:``});return t[W].type=`error`,t}static json(t=void 0,n={}){let r=JSON.stringify(t);if(r===void 0)throw TypeError(`data is not JSON serializable`);let i=new z(n&&n.headers);return i.has(`content-type`)||i.set(`content-type`,`application/json`),new e(r,{...n,headers:i})}get[Symbol.toStringTag](){return`Response`}},Object.defineProperties(G.prototype,{type:{enumerable:!0},url:{enumerable:!0},status:{enumerable:!0},ok:{enumerable:!0},redirected:{enumerable:!0},statusText:{enumerable:!0},headers:{enumerable:!0},clone:{enumerable:!0}})})),K,ce=e((()=>{K=e=>{if(e.search)return e.search;let t=e.href.length-1,n=e.hash||(e.href[t]===`#`?`#`:``);return e.href[t-n.length]===`?`?`?`:``}}));function q(e,t=!1){return e==null||(e=new URL(e),/^(about|blob|data):$/.test(e.protocol))?`no-referrer`:(e.username=``,e.password=``,e.hash=``,t&&(e.pathname=``,e.search=``),e)}function le(e){if(!Y.has(e))throw TypeError(`Invalid referrerPolicy: ${e}`);return e}function ue(e){if(/^(http|ws)s:$/.test(e.protocol))return!0;let t=e.host.replace(/(^\[)|(]$)/g,``),n=_(t);return n===4&&/^127\./.test(t)||n===6&&/^(((0+:){7})|(::(0+:){0,6}))0*1$/.test(t)?!0:e.host===`localhost`||e.host.endsWith(`.localhost`)?!1:e.protocol===`file:`}function J(e){return/^about:(blank|srcdoc)$/.test(e)||e.protocol===`data:`||/^(blob|filesystem):$/.test(e.protocol)?!0:ue(e)}function de(e,{referrerURLCallback:t,referrerOriginCallback:n}={}){if(e.referrer===`no-referrer`||e.referrerPolicy===``)return null;let r=e.referrerPolicy;if(e.referrer===`about:client`)return`no-referrer`;let i=e.referrer,a=q(i),o=q(i,!0);a.toString().length>4096&&(a=o),t&&(a=t(a)),n&&(o=n(o));let s=new URL(e.url);switch(r){case`no-referrer`:return`no-referrer`;case`origin`:return o;case`unsafe-url`:return a;case`strict-origin`:return J(a)&&!J(s)?`no-referrer`:o.toString();case`strict-origin-when-cross-origin`:return a.origin===s.origin?a:J(a)&&!J(s)?`no-referrer`:o;case`same-origin`:return a.origin===s.origin?a:`no-referrer`;case`origin-when-cross-origin`:return a.origin===s.origin?a:o;case`no-referrer-when-downgrade`:return J(a)&&!J(s)?`no-referrer`:a;default:throw TypeError(`Invalid referrerPolicy: ${r}`)}}function fe(e){let t=(e.get(`referrer-policy`)||``).split(/[,\s]+/),n=``;for(let e of t)e&&Y.has(e)&&(n=e);return n}var Y,X,pe=e((()=>{Y=new Set([``,`no-referrer`,`no-referrer-when-downgrade`,`same-origin`,`origin`,`strict-origin`,`origin-when-cross-origin`,`strict-origin-when-cross-origin`,`unsafe-url`]),X=`strict-origin-when-cross-origin`})),Z,Q,me,$,he,ge=e((()=>{B(),I(),D(),ce(),pe(),Z=Symbol(`Request internals`),Q=e=>typeof e==`object`&&typeof e[Z]==`object`,me=p(()=>{},`.data is not a valid RequestInit property, use .body instead`,`https://github.com/node-fetch/node-fetch/issues/1000 (request)`),$=class e extends j{constructor(e,t={}){let n;if(Q(e)?n=new URL(e.url):(n=new URL(e),e={}),n.username!==``||n.password!==``)throw TypeError(`${n} is an url with embedded credentials.`);let r=t.method||e.method||`GET`;if(/^(delete|get|head|options|post|put)$/i.test(r)&&(r=r.toUpperCase()),!Q(t)&&`data`in t&&me(),(t.body!=null||Q(e)&&e.body!==null)&&(r===`GET`||r===`HEAD`))throw TypeError(`Request with GET/HEAD method cannot have body`);let i=t.body?t.body:Q(e)&&e.body!==null?M(e):null;super(i,{size:t.size||e.size||0});let a=new z(t.headers||e.headers||{});if(i!==null&&!a.has(`Content-Type`)){let e=P(i,this);e&&a.set(`Content-Type`,e)}let o=Q(e)?e.signal:null;if(`signal`in t&&(o=t.signal),o!=null&&!T(o))throw TypeError(`Expected signal to be an instanceof AbortSignal or EventTarget`);let s=t.referrer==null?e.referrer:t.referrer;if(s===``)s=`no-referrer`;else if(s){let e=new URL(s);s=/^about:(\/\/)?client$/.test(e)?`client`:e}else s=void 0;this[Z]={method:r,redirect:t.redirect||e.redirect||`follow`,headers:a,parsedURL:n,signal:o,referrer:s},this.follow=t.follow===void 0?e.follow===void 0?20:e.follow:t.follow,this.compress=t.compress===void 0?e.compress===void 0?!0:e.compress:t.compress,this.counter=t.counter||e.counter||0,this.agent=t.agent||e.agent,this.highWaterMark=t.highWaterMark||e.highWaterMark||16384,this.insecureHTTPParser=t.insecureHTTPParser||e.insecureHTTPParser||!1,this.referrerPolicy=t.referrerPolicy||e.referrerPolicy||``}get method(){return this[Z].method}get url(){return c(this[Z].parsedURL)}get headers(){return this[Z].headers}get redirect(){return this[Z].redirect}get signal(){return this[Z].signal}get referrer(){if(this[Z].referrer===`no-referrer`)return``;if(this[Z].referrer===`client`)return`about:client`;if(this[Z].referrer)return this[Z].referrer.toString()}get referrerPolicy(){return this[Z].referrerPolicy}set referrerPolicy(e){this[Z].referrerPolicy=le(e)}clone(){return new e(this)}get[Symbol.toStringTag](){return`Request`}},Object.defineProperties($.prototype,{method:{enumerable:!0},url:{enumerable:!0},headers:{enumerable:!0},redirect:{enumerable:!0},clone:{enumerable:!0},signal:{enumerable:!0},referrer:{enumerable:!0},referrerPolicy:{enumerable:!0}}),he=e=>{let{parsedURL:t}=e[Z],n=new z(e[Z].headers);n.has(`Accept`)||n.set(`Accept`,`*/*`);let r=null;if(e.body===null&&/^(post|put)$/i.test(e.method)&&(r=`0`),e.body!==null){let t=F(e);typeof t==`number`&&!Number.isNaN(t)&&(r=String(t))}r&&n.set(`Content-Length`,r),e.referrerPolicy===``&&(e.referrerPolicy=X),e.referrer&&e.referrer!==`no-referrer`?e[Z].referrer=de(e):e[Z].referrer=`no-referrer`,e[Z].referrer instanceof URL&&n.set(`Referer`,e.referrer),n.has(`User-Agent`)||n.set(`User-Agent`,`node-fetch`),e.compress&&!n.has(`Accept-Encoding`)&&n.set(`Accept-Encoding`,`gzip, deflate, br`);let{agent:i}=e;typeof i==`function`&&(i=i(t));let a=K(t);return{parsedURL:t,options:{path:t.pathname+a,method:e.method,headers:n[Symbol.for(`nodejs.util.inspect.custom`)](),insecureHTTPParser:e.insecureHTTPParser,agent:i}}}})),_e,ve=e((()=>{b(),_e=class extends y{constructor(e,t=`aborted`){super(e,t)}}}));async function ye(e,t){return new Promise((n,r)=>{let i=new $(e,t),{parsedURL:a,options:o}=he(i);if(!xe.has(a.protocol))throw TypeError(`node-fetch cannot load ${e}. URL scheme "${a.protocol.replace(/:$/,``)}" is not supported.`);if(a.protocol===`data:`){let e=te(i.url);n(new G(e,{headers:{"Content-Type":e.typeFull}}));return}let s=(a.protocol===`https:`?ee:v).request,{signal:c}=i,l=null,p=()=>{let e=new _e(`The operation was aborted.`);r(e),i.body&&i.body instanceof u.Readable&&i.body.destroy(e),!(!l||!l.body)&&l.body.emit(`error`,e)};if(c&&c.aborted){p();return}let m=()=>{p(),_()},h=s(a.toString(),o);c&&c.addEventListener(`abort`,m);let _=()=>{h.abort(),c&&c.removeEventListener(`abort`,m)};h.on(`error`,e=>{r(new x(`request to ${i.url} failed, reason: ${e.message}`,`system`,e)),_()}),be(h,e=>{l&&l.body&&l.body.destroy(e)}),process.version<`v14`&&h.on(`socket`,e=>{let t;e.prependListener(`end`,()=>{t=e._eventsCount}),e.prependListener(`close`,n=>{if(l&&t<e._eventsCount&&!n){let e=Error(`Premature close`);e.code=`ERR_STREAM_PREMATURE_CLOSE`,l.body.emit(`error`,e)}})}),h.on(`response`,e=>{h.setTimeout(0);let a=oe(e.rawHeaders);if(H(e.statusCode)){let o=a.get(`Location`),s=null;try{s=o===null?null:new URL(o,i.url)}catch{if(i.redirect!==`manual`){r(new x(`uri requested responds with an invalid redirect URL: ${o}`,`invalid-redirect`)),_();return}}switch(i.redirect){case`error`:r(new x(`uri requested responds with a redirect, redirect mode is set to error: ${i.url}`,`no-redirect`)),_();return;case`manual`:break;case`follow`:{if(s===null)break;if(i.counter>=i.follow){r(new x(`maximum redirect reached at: ${i.url}`,`max-redirect`)),_();return}let o={headers:new z(i.headers),follow:i.follow,counter:i.counter+1,agent:i.agent,compress:i.compress,method:i.method,body:M(i),signal:i.signal,size:i.size,referrer:i.referrer,referrerPolicy:i.referrerPolicy};if(!E(i.url,s)||!ie(i.url,s))for(let e of[`authorization`,`www-authenticate`,`cookie`,`cookie2`])o.headers.delete(e);if(e.statusCode!==303&&i.body&&t.body instanceof u.Readable){r(new x(`Cannot follow redirect with body being a readable stream`,`unsupported-redirect`)),_();return}(e.statusCode===303||(e.statusCode===301||e.statusCode===302)&&i.method===`POST`)&&(o.method=`GET`,o.body=void 0,o.headers.delete(`content-length`));let c=fe(a);c&&(o.referrerPolicy=c),n(ye(new $(s,o))),_();return}default:return r(TypeError(`Redirect option '${i.redirect}' is not a valid value of RequestRedirect`))}}c&&e.once(`end`,()=>{c.removeEventListener(`abort`,m)});let o=f(e,new d,e=>{e&&r(e)});process.version<`v12.10`&&e.on(`aborted`,m);let s={url:i.url,status:e.statusCode,statusText:e.statusMessage,headers:a,size:i.size,counter:i.counter,highWaterMark:i.highWaterMark},p=a.get(`Content-Encoding`);if(!i.compress||i.method===`HEAD`||p===null||e.statusCode===204||e.statusCode===304){l=new G(o,s),n(l);return}let v={flush:g.Z_SYNC_FLUSH,finishFlush:g.Z_SYNC_FLUSH};if(p===`gzip`||p===`x-gzip`){o=f(o,g.createGunzip(v),e=>{e&&r(e)}),l=new G(o,s),n(l);return}if(p===`deflate`||p===`x-deflate`){let t=f(e,new d,e=>{e&&r(e)});t.once(`data`,e=>{o=(e[0]&15)==8?f(o,g.createInflate(),e=>{e&&r(e)}):f(o,g.createInflateRaw(),e=>{e&&r(e)}),l=new G(o,s),n(l)}),t.once(`end`,()=>{l||(l=new G(o,s),n(l))});return}if(p===`br`){o=f(o,g.createBrotliDecompress(),e=>{e&&r(e)}),l=new G(o,s),n(l);return}l=new G(o,s),n(l)}),ae(h,i).catch(r)})}function be(e,t){let n=l.from(`0\r
3
3
  \r
4
4
  `),r=!1,i=!1,a;e.on(`response`,e=>{let{headers:t}=e;r=t[`transfer-encoding`]===`chunked`&&!t[`content-length`]}),e.on(`socket`,o=>{let s=()=>{if(r&&!i){let e=Error(`Premature close`);e.code=`ERR_STREAM_PREMATURE_CLOSE`,t(e)}},c=e=>{i=l.compare(e.slice(-5),n)===0,!i&&a&&(i=l.compare(a.slice(-3),n.slice(0,3))===0&&l.compare(e.slice(-2),n.slice(3))===0),a=e};o.prependListener(`close`,s),o.on(`data`,c),e.on(`close`,()=>{o.removeListener(`close`,s),o.removeListener(`data`,c)})})}var xe;e((()=>{ne(),I(),se(),B(),ge(),re(),ve(),U(),n(),D(),pe(),s(),xe=new Set([`data:`,`http:`,`https:`])}))();export{ye as default};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ function e(e){return e.totalTokens||e.input+e.output+e.cacheRead+e.cacheWrite}function t(e){try{return JSON.stringify(e)??`undefined`}catch{return`[unserializable]`}}function n(e){if(typeof e==`string`)return e.length;let t=0;for(let n of e)t+=n.type===`text`?n.text.length:4800;return t}function r(e){return Math.ceil(e.length/4)}function i(e){return Math.ceil(n(e)/4)}function a(e){let n=0;if(e.role===`user`||e.role===`toolResult`)return i(e.content);for(let r of e.content)r.type===`text`?n+=r.text.length:r.type===`thinking`?n+=r.thinking.length:n+=r.name.length+t(r.arguments).length;return Math.ceil(n/4)}function o(t){let n=-1/0,r;for(let i=0;i<t.length;i++){let a=t[i];if(a.role===`assistant`){let t=a;t.timestamp>=n&&t.stopReason!==`aborted`&&t.stopReason!==`error`&&e(t.usage)>0&&(r={usage:t.usage,index:i})}n=Math.max(n,a.timestamp)}return r}function s(t){let n=o(t);if(n){let r=e(n.usage),i=0;for(let e=n.index+1;e<t.length;e++)i+=a(t[e]);return{tokens:r+i,usageTokens:r,trailingTokens:i,lastUsageIndex:n.index}}let r=0;for(let e of t)r+=a(e);return{tokens:r,usageTokens:0,trailingTokens:r,lastUsageIndex:null}}function c(e){return!e||e.length===0?0:r(t(e))}function l(e){return Array.isArray(e)}function u(e){if(l(e))return s(e);let t=s(e.messages);if(t.lastUsageIndex!==null){let n=new Set(e.messages.slice(t.lastUsageIndex+1).filter(e=>e.role===`toolResult`).flatMap(e=>e.addedToolNames??[])),r=c(e.tools?.filter(e=>n.has(e.name)));return{tokens:t.tokens+r,usageTokens:t.usageTokens,trailingTokens:t.trailingTokens+r,lastUsageIndex:t.lastUsageIndex}}let n=(e.systemPrompt?r(e.systemPrompt):0)+c(e.tools);return{tokens:t.tokens+n,usageTokens:t.usageTokens,trailingTokens:t.trailingTokens+n,lastUsageIndex:t.lastUsageIndex}}function d(e,t,n){if(e.contextWindow<=0)return Math.max(1,n);let r=e.contextWindow-u(t).tokens-4096;return Math.min(n,Math.max(1,r))}function f(e,t,n,r){return{temperature:n?.temperature,maxTokens:d(e,t,n?.maxTokens??e.maxTokens),signal:n?.signal,apiKey:r||n?.apiKey,transport:n?.transport,cacheRetention:n?.cacheRetention,sessionId:n?.sessionId,headers:n?.headers,onPayload:n?.onPayload,onResponse:n?.onResponse,timeoutMs:n?.timeoutMs,websocketConnectTimeoutMs:n?.websocketConnectTimeoutMs,maxRetries:n?.maxRetries,maxRetryDelayMs:n?.maxRetryDelayMs,metadata:n?.metadata,env:n?.env}}function p(e){return e===`xhigh`||e===`max`?`high`:e}function m(e,t,n,r){let i={minimal:1024,low:2048,medium:8192,high:16384,...r}[p(n)],a=e===void 0?t:Math.min(e+i,t);return a<=i&&(i=Math.max(0,a-1024)),{maxTokens:a,thinkingBudget:i}}function h(e,t){let n=[],r=!1;for(let i of e){if(i.type===`image`){r||n.push({type:`text`,text:t}),r=!0;continue}n.push(i),r=i.text===t}return n}function g(e,t){return t.input.includes(`image`)?e:e.map(e=>e.role===`user`&&Array.isArray(e.content)?{...e,content:h(e.content,`(image omitted: model does not support images)`)}:e.role===`toolResult`?{...e,content:h(e.content,`(tool image omitted: model does not support images)`)}:e)}function _(e,t,n){let r=new Map,i=g(e.map(e=>e.content==null?{...e,content:[]}:e),t).map(e=>{if(e.role===`user`)return e;if(e.role===`toolResult`){let t=r.get(e.toolCallId);return t&&t!==e.toolCallId?{...e,toolCallId:t}:e}if(e.role===`assistant`){let i=e,a=i.provider===t.provider&&i.api===t.api&&i.model===t.id,o=i.content.flatMap(e=>{if(e.type===`thinking`)return e.redacted?a?e:[]:a&&e.thinkingSignature?e:!e.thinking||e.thinking.trim()===``?[]:a?e:{type:`text`,text:e.thinking};if(e.type===`text`)return a?e:{type:`text`,text:e.text};if(e.type===`toolCall`){let o=e,s=o;if(!a&&o.thoughtSignature&&(s={...o},delete s.thoughtSignature),!a&&n){let e=n(o.id,t,i);e!==o.id&&(r.set(o.id,e),s={...s,id:e})}return s}return e});return{...i,content:o}}return e}),a=[],o=[],s=new Set,c=()=>{if(o.length>0){for(let e of o)s.has(e.id)||a.push({role:`toolResult`,toolCallId:e.id,toolName:e.name,content:[{type:`text`,text:`No result provided`}],isError:!0,timestamp:Date.now()});o=[],s=new Set}};for(let e=0;e<i.length;e++){let t=i[e];if(t.role===`assistant`){c();let e=t;if(e.stopReason===`error`||e.stopReason===`aborted`)continue;let n=e.content.filter(e=>e.type===`toolCall`);n.length>0&&(o=n,s=new Set),a.push(t)}else t.role===`toolResult`?(s.add(t.toolCallId),a.push(t)):(t.role===`user`&&c(),a.push(t))}return c(),a}export{d as i,m as n,f as r,_ as t};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ function e(e){return e.totalTokens||e.input+e.output+e.cacheRead+e.cacheWrite}function t(e){try{return JSON.stringify(e)??`undefined`}catch{return`[unserializable]`}}function n(e){if(typeof e==`string`)return e.length;let t=0;for(let n of e)t+=n.type===`text`?n.text.length:4800;return t}function r(e){return Math.ceil(e.length/4)}function i(e){return Math.ceil(n(e)/4)}function a(e){let n=0;if(e.role===`user`||e.role===`toolResult`)return i(e.content);for(let r of e.content)r.type===`text`?n+=r.text.length:r.type===`thinking`?n+=r.thinking.length:n+=r.name.length+t(r.arguments).length;return Math.ceil(n/4)}function o(t){let n=-1/0,r;for(let i=0;i<t.length;i++){let a=t[i];if(a.role===`assistant`){let t=a;t.timestamp>=n&&t.stopReason!==`aborted`&&t.stopReason!==`error`&&e(t.usage)>0&&(r={usage:t.usage,index:i})}n=Math.max(n,a.timestamp)}return r}function s(t){let n=o(t);if(n){let r=e(n.usage),i=0;for(let e=n.index+1;e<t.length;e++)i+=a(t[e]);return{tokens:r+i,usageTokens:r,trailingTokens:i,lastUsageIndex:n.index}}let r=0;for(let e of t)r+=a(e);return{tokens:r,usageTokens:0,trailingTokens:r,lastUsageIndex:null}}function c(e){return!e||e.length===0?0:r(t(e))}function l(e){return Array.isArray(e)}function u(e){if(l(e))return s(e);let t=s(e.messages);if(t.lastUsageIndex!==null){let n=new Set(e.messages.slice(t.lastUsageIndex+1).filter(e=>e.role===`toolResult`).flatMap(e=>e.addedToolNames??[])),r=c(e.tools?.filter(e=>n.has(e.name)));return{tokens:t.tokens+r,usageTokens:t.usageTokens,trailingTokens:t.trailingTokens+r,lastUsageIndex:t.lastUsageIndex}}let n=(e.systemPrompt?r(e.systemPrompt):0)+c(e.tools);return{tokens:t.tokens+n,usageTokens:t.usageTokens,trailingTokens:t.trailingTokens+n,lastUsageIndex:t.lastUsageIndex}}function d(e,t,n){if(e.contextWindow<=0)return Math.max(1,n);let r=e.contextWindow-u(t).tokens-4096;return Math.min(n,Math.max(1,r))}function f(e,t,n,r){return{temperature:n?.temperature,maxTokens:d(e,t,n?.maxTokens??e.maxTokens),signal:n?.signal,apiKey:r||n?.apiKey,transport:n?.transport,cacheRetention:n?.cacheRetention,sessionId:n?.sessionId,headers:n?.headers,onPayload:n?.onPayload,onResponse:n?.onResponse,timeoutMs:n?.timeoutMs,websocketConnectTimeoutMs:n?.websocketConnectTimeoutMs,maxRetries:n?.maxRetries,maxRetryDelayMs:n?.maxRetryDelayMs,metadata:n?.metadata,env:n?.env}}function p(e){return e===`xhigh`||e===`max`?`high`:e}function m(e,t,n,r){let i={minimal:1024,low:2048,medium:8192,high:16384,...r}[p(n)],a=e===void 0?t:Math.min(e+i,t);return a<=i&&(i=Math.max(0,a-1024)),{maxTokens:a,thinkingBudget:i}}function h(e,t){let n=[],r=!1;for(let i of e){if(i.type===`image`){r||n.push({type:`text`,text:t}),r=!0;continue}n.push(i),r=i.text===t}return n}function g(e,t){return t.input.includes(`image`)?e:e.map(e=>e.role===`user`&&Array.isArray(e.content)?{...e,content:h(e.content,`(image omitted: model does not support images)`)}:e.role===`toolResult`?{...e,content:h(e.content,`(tool image omitted: model does not support images)`)}:e)}function _(e,t,n){let r=new Map,i=g(e.map(e=>e.content==null?{...e,content:[]}:e),t).map(e=>{if(e.role===`user`)return e;if(e.role===`toolResult`){let t=r.get(e.toolCallId);return t&&t!==e.toolCallId?{...e,toolCallId:t}:e}if(e.role===`assistant`){let i=e,a=i.provider===t.provider&&i.api===t.api&&i.model===t.id,o=i.content.flatMap(e=>{if(e.type===`thinking`)return e.redacted?a?e:[]:a&&e.thinkingSignature?e:!e.thinking||e.thinking.trim()===``?[]:a?e:{type:`text`,text:e.thinking};if(e.type===`text`)return a?e:{type:`text`,text:e.text};if(e.type===`toolCall`){let o=e,s=o;if(!a&&o.thoughtSignature&&(s={...o},delete s.thoughtSignature),!a&&n){let e=n(o.id,t,i);e!==o.id&&(r.set(o.id,e),s={...s,id:e})}return s}return e});return{...i,content:o}}return e}),a=[],o=[],s=new Set,c=()=>{if(o.length>0){for(let e of o)s.has(e.id)||a.push({role:`toolResult`,toolCallId:e.id,toolName:e.name,content:[{type:`text`,text:`No result provided`}],isError:!0,timestamp:Date.now()});o=[],s=new Set}};for(let e=0;e<i.length;e++){let t=i[e];if(t.role===`assistant`){c();let e=t;if(e.stopReason===`error`||e.stopReason===`aborted`)continue;let n=e.content.filter(e=>e.type===`toolCall`);n.length>0&&(o=n,s=new Set),a.push(t)}else t.role===`toolResult`?(s.add(t.toolCallId),a.push(t)):(t.role===`user`&&c(),a.push(t))}return c(),a}export{d as i,m as n,f as r,_ as t};
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import"./index.mjs";import"./init-BwjB5mke.mjs";export{};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pen.dev/cli",
3
- "version": "0.2.8",
3
+ "version": "0.3.0",
4
4
  "description": "CLI tool for running the pen.dev AI agent manipulating .pen design files",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",
@@ -34,10 +34,10 @@
34
34
  "author": "High Agency, Inc.",
35
35
  "license": "UNLICENSED",
36
36
  "dependencies": {
37
- "@anthropic-ai/claude-agent-sdk": "^0.3.197",
37
+ "@anthropic-ai/claude-agent-sdk": "^0.3.206",
38
38
  "@inquirer/prompts": "^8.3.0",
39
39
  "@node-ipc/node-ipc": "^11.0.3",
40
- "@openai/codex-sdk": "^0.142.5",
40
+ "@openai/codex-sdk": "^0.144.1",
41
41
  "eventemitter3": "^5.0.1",
42
42
  "semver": "^7.7.4",
43
43
  "sharp": "^0.34.5",