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(t,n={}){let r=t.indexOf(`:`);if(r<1)throw new InvalidArgumentError(`Expected header in "Name: value" format, received "${t}".`);let i=t.slice(0,r).trim(),a=t.slice(r+1).trim();try{new Headers([[i,a]])}catch{throw new InvalidArgumentError(`Expected a valid HTTP header, received "${t}".`)}return mergeDevelopmentHeaders(n,{[i]:a})??{}}function resolveDevelopmentUrlTarget(t,n){if(t.url!==void 0&&n!==void 0)throw new InvalidArgumentError(`Pass either --url or a bare URL, not both.`);let r=t.url??n;if(r===void 0){if(t.header!==void 0)throw new InvalidArgumentError(`The --header option can only be used with --url or a bare URL.`);return}if(t.host!==void 0)throw new InvalidArgumentError(`The --host option cannot be used with --url.`);if(t.port!==void 0)throw new InvalidArgumentError(`The --port option cannot be used with --url.`);if(t.ui===!1)throw new InvalidArgumentError(`The --no-ui option cannot be used with --url.`);let i=URL.parse(r);if(i===null)throw new InvalidArgumentError(`Expected an absolute http(s) URL, received "${r}".`);let a=mergeDevelopmentHeaders(extractDevelopmentUrlHeaders(i),t.header),o=i.toString();return a===void 0?{serverUrl:o}:{headers:a,serverUrl:o}}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 n=decodeUrlUserInfo(e.username,`username`),r=decodeUrlUserInfo(e.password,`password`);return e.username=``,e.password=``,{Authorization:`Basic ${encodeBasicCredentials(n,r)}`}}function decodeUrlUserInfo(t,n){try{return decodeURIComponent(t)}catch{throw new InvalidArgumentError(`Expected a valid URL-encoded ${n} in URL userinfo.`)}}export{parseDevelopmentHeaderOption,resolveDevelopmentUrlTarget};