UNPKG

eve

Version:

Filesystem-first framework for durable backend AI agents that run anywhere.

1 lines • 3.51 kB
import{remoteHost}from"./target.js";import{clipVisible,stripAnsi,visibleLength}from"#cli/ui/terminal-text.js";import{formatModelSummary}from"#shared/model-summary.js";function formatDevBuildStatus(e,t){let n=e.phase===`complete`;return`${n?t.glyph.success:t.glyph.validating} ${n?e.summary.replace(/ changed$/u,` updated`):`${e.summary.replace(/ (?:added|changed|removed)$/u,``)} updating…`}`}function renderModel(e){if(e.model===void 0)return;let t=e.theme.colors,n={model:e.model};if(e.reasoning!==void 0&&(n.reasoning=e.reasoning),e.fastMode===!0&&(n.fastGlyph=e.theme.glyph.fast),e.remote!==void 0){n.model=stripAnsi(e.model).replace(/\s+/gu,` `).trim();let r=stripAnsi(formatModelSummary(n)).replace(/\s+/gu,` `).trim();return t.dim(r)}return t.dim(formatModelSummary(n))}const EXTERNAL_PROVIDER_DISPLAY_NAMES={codex:`chatgpt-sub`};function renderEndpoint(e){if(e.remote!==void 0||e.endpoint===void 0)return;let t=e.theme.colors,n=e.theme.glyph,clause=(e,n)=>`${e}${t.dim(n)}`;if(e.endpoint.kind===`external`){let r=EXTERNAL_PROVIDER_DISPLAY_NAMES[e.endpoint.provider]??e.endpoint.provider;return`${t.dim(r)}${n.external}`}if(e.endpoint.kind===`chatgpt`)switch(e.endpoint.state){case`ready`:return`${t.dim(`chatgpt-sub`)}${n.external}`;case`checking`:return t.dim(`chatgpt-sub checking…`);case`signed-out`:case`reauth-required`:return t.yellow(`${n.warning} chatgpt-sub login · /login`);case`unavailable`:return t.yellow(`${n.warning} chatgpt-sub unavailable`)}if(!e.endpoint.connected)return t.yellow(`${n.warning} ai-gateway`);if(e.endpoint.credential===`api-key`)return clause(`ai-gateway`,`(api-key)`);if(e.endpoint.credential===`oauth`){let n=e.vercel?.modelTeamSlug;return t.dim(n?`Vercel · ${n}`:`Vercel`)}let r=e.vercel?.identity?.projectName;return clause(`ai-gateway`,`(${r===void 0?`oidc`:`oidc:${r}`})`)}function buildStatusLine(e){let{theme:t,width:n}=e,r=t.colors,i=e.devBuild===void 0?void 0:formatDevBuildStatus(e.devBuild,t),a=e.logLevel===void 0?void 0:r.cyan(`logs: ${e.logLevel}`),o=renderModel(e),s=e.remote===void 0?void 0:formatRemoteStatus(e.remote,t),c=renderEndpoint(e),l=s?.full,u=s?.badge,d=r.dim(` · `),compose=(e,t)=>{let n=t.filter(e=>e!==void 0).join(d);return e===void 0||n.length===0?e??n:`${e} ${n}`},f=[compose(l,[a,o,c]),compose(l,[a,o]),compose(l,[a]),compose(u,[a]),compose(u,[])];if(i!==void 0){for(let e of f){let t=visibleLength(e),r=visibleLength(i);if(!(t+(t>0?2:0)+r>n))return`${e}${` `.repeat(n-t-r)}${i}`}return clipVisible(i,n)}if(f[0].length===0)return;for(let e of f)if(e.length>0&&visibleLength(e)<=n)return e;let p=f.findLast(e=>e.length>0);return clipVisible(p,n)}function formatRemoteStatus(e,t){let n=t.colors,r=e.deployment===void 0?remoteHost(e.target):`${e.deployment.projectName} (${e.deployment.environment})`,i=formatRemoteBadge(` ${t.unicode?`↗`:`->`} ${r} `,e.connection.state,t),a;switch(e.connection.state){case`checking`:a=n.dim(`Checking access…`);break;case`ready`:break;case`auth-required`:a=n.yellow(`Authenticate via OIDC`);break;case`authenticating`:a=n.dim(`Authenticating via OIDC…`);break;case`auth-failed`:a=n.yellow(`Authentication failed`);break;case`unavailable`:a=n.yellow(`Remote unavailable`)}return{badge:i,full:a===void 0?i:`${i} ${a}`}}function formatRemoteBadge(e,t,n){let r=n.colors;switch(t){case`checking`:return r.inverse(r.gray(e));case`ready`:return r.inverse(r.blue(e));case`unavailable`:case`auth-required`:case`authenticating`:case`auth-failed`:return r.inverse(r.yellow(e))}}export{buildStatusLine};