function n(n,{encode:e=!1}={}){return n.filter((({name:n})=>"string"==typeof n&&n.trim().length>0)).map((({name:n,value:r})=>{const t=e?encodeURIComponent(n):n;if(void 0===r)return t;return`${t}=${e?encodeURIComponent(r):r}`})).join("&")}function e(n,{decode:e=!1}={}){if(!n||!n.length)return[];try{const[r,...t]=n.split("#"),o=r.split("&");return o.map((n=>{const[r,...t]=n.split("=");if(!r)return null;const o=n.includes("=")?e?decodeURIComponent(t.join("=")):t.join("="):void 0;return{name:e?decodeURIComponent(r):r,value:o}})).filter((n=>null!==n))}catch(n){return console.error("Error parsing query params:",n),[]}}const r=r=>{if(!r||"string"!=typeof r)return r;const[t,...o]=r.split("#"),[c,...i]=t.split("?");if(!i||0===i.length)return r;return`${c}?${n(e(i.join("?"),{decode:!1}),{encode:!0})}${o.length>0?`#${o.join("#")}`:""}`},t=n=>n.replace(/^https?:\/\/[^/?#]*/,"")||"/",o=n=>{var e;if(!Array.isArray(n))return"";const r=new URLSearchParams;for(const t of n)"object"==typeof t&&null!==t&&"name"in t&&r.append(t.name,String(null!==(e=t.value)&&void 0!==e?e:""));return r.toString()},c=n=>{var e;return"FormData"===(null===(e=null==n?void 0:n.constructor)||void 0===e?void 0:e.name)},i=n=>{if("string"!=typeof n)return null;const e=n.match(/boundary="([^"]+)"|boundary=([^;\s]+)/i);return e?e[1]||e[2]:null},a=/\{\{([^}]+)\}\}/g;function l(n,e=a){const r=new RegExp(e,"g");const t={};let o=n,c=!1;return r.test(n)&&(c=!0,o=n.replace(r,(function(n){const e=`bruno-var-hash-${function(n){let e,r=5381;for(let t=0;t<n.length;t++)e=n.charCodeAt(t),r=(r<<5)+r+e|0;return""+r}(n)}`;return t[e]=n,e}))),{hashed:o,restore(n){if(!c)return n;let e=n;for(const n in t){const r=t[n];e=e.replaceAll(n,r)}return e}}}const u=/[^{}\s](?:[^{}]*[^{}\s])?/,s=new RegExp(`^\\?(${u.source})$`),f=new RegExp(`{{\\?(${u.source})}}`,"g"),d=n=>{const e=new Set;let r;for(;null!==(r=f.exec(n));)e.add(r[1]);return Array.from(e)};function p(n){const e=new Set;try{if("string"==typeof n){d(n).forEach((n=>e.add(n)))}else if(Array.isArray(n))for(const r of n){p(r).forEach((n=>e.add(n)))}else if("object"==typeof n&&null!==n)for(const r in n){p(n[r]).forEach((n=>e.add(n)))}}catch(n){console.error("Error extracting prompt variables:",n)}return Array.from(e)}const m=n=>Array.isArray(n)?n.filter((n=>n.name&&""!==n.name.trim())).map((n=>{const e=n.value||"";if(e.includes("\n")||e.includes("\r")){const r=e.replace(/\r/g,"\\r").replace(/\n/g,"\\n");return`${n.name}="${r}"`}if(e.includes("#")){if(!e.includes("'"))return`${n.name}='${e}'`;if(!e.includes("`"))return`${n.name}=\`${e}\``;const r=e.replace(/"/g,'\\"');return`${n.name}="${r}"`}return e!==e.trim()?e.includes("'")?e.includes("`")?`${n.name}="${e}"`:`${n.name}=\`${e}\``:`${n.name}='${e}'`:`${n.name}=${e}`})).join("\n"):"";export{f as PROMPT_VARIABLE_TEMPLATE_PATTERN,s as PROMPT_VARIABLE_TEXT_PATTERN,o as buildFormUrlEncodedPayload,n as buildQueryString,r as encodeUrl,i as extractBoundaryFromContentType,p as extractPromptVariables,d as extractPromptVariablesFromString,c as isFormData,m as jsonToDotenv,e as parseQueryParams,l as patternHasher,t as stripOrigin};
//# sourceMappingURL=index.js.map
