UNPKG

eve

Version:

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

1 lines 973 B
import{z}from"#compiled/zod/index.js";import{httpServerUrlSchema}from"#shared/network-address.js";import{join}from"node:path";import{mkdir,readFile,rm,writeFile}from"node:fs/promises";const developmentServerStateSchema=z.object({url:httpServerUrlSchema}).strict();var DevelopmentServerState=class{appRoot;#e;#t;constructor(e){this.appRoot=e.appRoot,this.#e=join(this.appRoot,`.eve`),this.#t=join(this.#e,`dev-server-state.v1.json`)}async read(){let e;try{e=await readFile(this.#t,`utf8`)}catch(e){if(isErrnoException(e,`ENOENT`))return;throw e}try{let t=developmentServerStateSchema.safeParse(JSON.parse(e));return t.success?t.data.url:void 0}catch{return}}async write(e){let t=developmentServerStateSchema.parse({url:e});await mkdir(this.#e,{recursive:!0}),await writeFile(this.#t,`${JSON.stringify(t)}\n`,`utf8`)}async remove(){await rm(this.#t,{force:!0})}};function isErrnoException(e,t){return e instanceof Error&&`code`in e&&e.code===t}export{DevelopmentServerState};