@withgauge/cli 0.28.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/batchWorker.js +1 -1
- package/dist/{chatApi-HF2R3SVR.js → chatApi-G5BMHJOC.js} +1 -1
- package/dist/{chunk-TAFB66SK.js → chunk-4SZPSHNF.js} +1 -1
- package/dist/{chunk-Y4Y2AKDY.js → chunk-MKC7K5NV.js} +1 -1
- package/dist/{chunk-PMX3NOGH.js → chunk-QJ2UAX2V.js} +1 -1
- package/dist/{chunk-PVTU7NGL.js → chunk-VHV7YMN5.js} +1 -1
- package/dist/{chunk-AZKXHO6C.js → chunk-ZXRPUGCO.js} +1 -1
- package/dist/{chunk-PUNARKS2.js → chunk-ZZK6V3ZF.js} +1 -1
- package/dist/index.js +33 -25
- package/dist/{orgDirectory-QCOOVF65.js → orgDirectory-52KLEIVN.js} +1 -1
- package/dist/watchServer.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createdOrganization,credentialKind,fetchDirectory,findOrganization,isUuid,keyOrganization,legacySelection,missingAgentsOrg,productsLabel,resolveOrgValue,resolveSelection}from"./chunk-
|
|
1
|
+
import{createdOrganization,credentialKind,fetchDirectory,findOrganization,isUuid,keyOrganization,legacySelection,missingAgentsOrg,productsLabel,resolveOrgValue,resolveSelection}from"./chunk-ZXRPUGCO.js";import"./chunk-QJ2UAX2V.js";import"./chunk-OIGVDK3F.js";import"./chunk-PSBF4TEK.js";export{createdOrganization,credentialKind,fetchDirectory,findOrganization,isUuid,keyOrganization,legacySelection,missingAgentsOrg,productsLabel,resolveOrgValue,resolveSelection};
|
package/dist/watchServer.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getWatchSession,listWatchSessions,readWatchDiff,readWatchTrace}from"./chunk-
|
|
1
|
+
import{getWatchSession,listWatchSessions,readWatchDiff,readWatchTrace}from"./chunk-MKC7K5NV.js";import"./chunk-ZZK6V3ZF.js";import"./chunk-QV7MOO3M.js";import"./chunk-QJ2UAX2V.js";import"./chunk-OIGVDK3F.js";import"./chunk-PSBF4TEK.js";import{readFile as readFile2,rename,rm,writeFile}from"fs/promises";import{join}from"path";import{existsSync}from"fs";import{readFile}from"fs/promises";import{createServer}from"http";import{fileURLToPath}from"url";var WATCH_HOST="127.0.0.1";var WATCH_FIRST_PORT=4040;var WATCH_PORT_ATTEMPTS=50;var ASSETS={"/":["index.html","text/html; charset=utf-8"],"/style.css":["style.css","text/css; charset=utf-8"],"/app.js":["app.js","text/javascript; charset=utf-8"],"/favicon.svg":["favicon.svg","image/svg+xml"],"/logo-for-light.png":["logo-for-light.png","image/png"],"/logo-for-dark.png":["logo-for-dark.png","image/png"]};var assetDir=[new URL("./watch/",import.meta.url),new URL("../watch/",import.meta.url)].map(url2=>fileURLToPath(url2)).find(dir=>existsSync(`${dir}index.html`));function listenOnFreePort(server2,port2=WATCH_FIRST_PORT,attempts=WATCH_PORT_ATTEMPTS){return new Promise((resolve,reject)=>{const tryPort=(candidate,left)=>{const onError=error=>{server2.off("listening",onListening);if(error.code==="EADDRINUSE"&&left>1)tryPort(candidate+1,left-1);else reject(error)};const onListening=()=>{server2.off("error",onError);resolve(candidate)};server2.once("error",onError);server2.once("listening",onListening);server2.listen(candidate,WATCH_HOST)};tryPort(port2,attempts)})}function send(res,status,type,body){res.writeHead(status,{"content-type":type,"cache-control":"no-store","x-content-type-options":"nosniff"});res.end(body)}var json=(res,status,value)=>send(res,status,"application/json; charset=utf-8",JSON.stringify(value));function createWatchServer(gaugeDir2,version2,onRequest=()=>{}){return createServer(async(req,res)=>{onRequest();const port2=req.socket.address().port;if(req.headers.host!==`${WATCH_HOST}:${port2}`&&req.headers.host!==`localhost:${port2}`)return send(res,403,"text/plain","Forbidden");if(req.method!=="GET")return send(res,405,"text/plain","Method not allowed");const url2=new URL(req.url??"/",`http://${WATCH_HOST}`);try{const asset=ASSETS[url2.pathname];if(asset){if(!assetDir)return send(res,500,"text/plain","Gauge watch assets are missing; reinstall the CLI.");return send(res,200,asset[1],await readFile(assetDir+asset[0]))}if(url2.pathname==="/api/health")return json(res,200,{gauge:"watch",version:version2,gaugeDir:gaugeDir2});if(url2.pathname==="/api/sessions")return json(res,200,{sessions:await listWatchSessions(gaugeDir2)});const match=/^\/api\/sessions\/([A-Za-z0-9_-]+)(\/trace|\/diff)?$/.exec(url2.pathname);if(match){const[,id,part]=match;if(part==="/diff"){const diff=await readWatchDiff(gaugeDir2,id);return diff===void 0?json(res,404,{error:"not_found"}):send(res,200,"text/plain; charset=utf-8",diff)}const after=Number(url2.searchParams.get("after")??-1);const value=part==="/trace"?await readWatchTrace(gaugeDir2,id,Number.isFinite(after)?after:-1):await getWatchSession(gaugeDir2,id);return value?json(res,200,value):json(res,404,{error:"not_found"})}json(res,404,{error:"not_found"})}catch(error){json(res,500,{error:String(error)})}})}var IDLE_MS=30*6e4;var STALE_MS=60*6e4;var[gaugeDir,version]=process.argv.slice(2);var statePath=join(gaugeDir,"watch.json");var lastRequest=Date.now();var server=createWatchServer(gaugeDir,version,()=>{lastRequest=Date.now()});var port=await listenOnFreePort(server);var url=`http://${WATCH_HOST}:${port}`;await writeFile(`${statePath}.tmp`,JSON.stringify({pid:process.pid,port,url,version,startedAt:new Date().toISOString()}),{mode:384});await rename(`${statePath}.tmp`,statePath);console.log(`Gauge watch listening on ${url}`);async function shutdown(){try{const saved=JSON.parse(await readFile2(statePath,"utf8"));if(saved.pid===process.pid)await rm(statePath,{force:true})}catch{}server.close();process.exit(0)}process.on("SIGTERM",shutdown);process.on("SIGINT",shutdown);setInterval(async()=>{if(Date.now()-lastRequest<IDLE_MS)return;const sessions=await listWatchSessions(gaugeDir).catch(()=>[]);const active=sessions.some(session=>session.live&&Date.now()-Date.parse(session.updatedAt??session.createdAt??"")<STALE_MS);if(!active)await shutdown()},6e4).unref();
|