eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
1 lines • 2.1 kB
JavaScript
import{InvalidArgumentError}from"#compiled/commander/index.js";import{encodeBasicCredentials}from"#internal/http/basic-auth.js";function parseDevelopmentHeaderOption(e,t={}){let n=e.indexOf(`:`);if(n<1)throw new InvalidArgumentError(`Expected header in "Name: value" format, received "${e}".`);let r=e.slice(0,n).trim(),i=e.slice(n+1).trim();try{new Headers([[r,i]])}catch{throw new InvalidArgumentError(`Expected a valid HTTP header, received "${e}".`)}return mergeDevelopmentHeaders(t,{[r]:i})??{}}function resolveDevelopmentUrlTarget(e,t){if(e.url!==void 0&&t!==void 0)throw new InvalidArgumentError(`Pass either --url or a bare URL, not both.`);let n=e.url??t;if(n===void 0){if(e.header!==void 0)throw new InvalidArgumentError(`The --header option can only be used with --url or a bare URL.`);return}if(e.host!==void 0)throw new InvalidArgumentError(`The --host option cannot be used with --url.`);if(e.port!==void 0)throw new InvalidArgumentError(`The --port option cannot be used with --url.`);if(e.ui===!1)throw new InvalidArgumentError(`The --no-ui option cannot be used with --url.`);let r=URL.parse(n);if(r===null)throw new InvalidArgumentError(`Expected an absolute http(s) URL, received "${n}".`);let i=mergeDevelopmentHeaders(extractDevelopmentUrlHeaders(r),e.header),a=r.toString();return i===void 0?{serverUrl:a}:{headers:i,serverUrl:a}}function mergeDevelopmentHeaders(e,t){if(e===void 0)return t;if(t===void 0)return e;let n={},r=new Set(Object.keys(t).map(e=>e.toLowerCase()));for(let[t,i]of Object.entries(e))r.has(t.toLowerCase())||(n[t]=i);for(let[e,r]of Object.entries(t))n[e]=r;return n}function extractDevelopmentUrlHeaders(e){if(e.username===``&&e.password===``)return;let t=decodeUrlUserInfo(e.username,`username`),n=decodeUrlUserInfo(e.password,`password`);return e.username=``,e.password=``,{Authorization:`Basic ${encodeBasicCredentials(t,n)}`}}function decodeUrlUserInfo(e,t){try{return decodeURIComponent(e)}catch{throw new InvalidArgumentError(`Expected a valid URL-encoded ${t} in URL userinfo.`)}}export{parseDevelopmentHeaderOption,resolveDevelopmentUrlTarget};