@getvision/core 0.0.0-develop-20251031183955 → 0.0.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/index.js +1 -107
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9,112 +9,6 @@ var M=(a,e)=>()=>(e||a((e={exports:{}}).exports,e),e.exports);var L=import.meta.
|
|
|
9
9
|
* Copyright(c) 2014 Jonathan Ong
|
|
10
10
|
* Copyright(c) 2015 Douglas Christopher Wilson
|
|
11
11
|
* MIT Licensed
|
|
12
|
-
*/var j=O(),X=L("path").extname;var H=Object.create(null),y=G,z=Object.create(null);D(H,z);function G(a){if(!a||typeof a!=="string")return!1;var e=X("x."+a).toLowerCase().substr(1);if(!e)return!1;return z[e]||!1}function D(a,e){var i=["nginx","apache",void 0,"iana"];Object.keys(j).forEach(function(o){var c=j[o],s=c.extensions;if(!s||!s.length)return;a[o]=s;for(var p=0;p<s.length;p++){var t=s[p];if(e[t]){var v=i.indexOf(j[e[t]].source),h=i.indexOf(c.source);if(e[t]!=="application/octet-stream"&&(v>h||v===h&&e[t].substr(0,12)==="application/"))continue}e[t]=o}})}var aa=S(P(import.meta.url));async function Q(a,e,i){let n=a.url||"/",o=n.indexOf("?");if(o!==-1)n=n.substring(0,o);if(n==="/"||!n.includes("."))n="/index.html";let c=q(i,n);if(!c.startsWith(i))return!1;if(!I(c))return!1;try{let s=await E(c),p=y(c)||"application/octet-stream";return e.writeHead(200,{"Content-Type":p,"Cache-Control":"public, max-age=3600"}),e.end(s),!0}catch(s){return console.error("Error serving static file:",s),!1}}function V(){let a=q(aa,"../..");return q(a,"dist/ui")}class b{httpServer;wss;clients=new Set;rpc;options;constructor(a={}){this.options={port:a.port??9500,host:a.host??"localhost",maxTraces:a.maxTraces??1000,maxLogs:a.maxLogs??1e4,captureConsole:a.captureConsole??!0,enableCors:a.enableCors??!0},this.rpc=new w,this.httpServer=na((e,i)=>{this.handleHttp(e,i).catch((n)=>{console.error("HTTP handler error:",n),i.writeHead(500),i.end("Internal Server Error")})}),this.wss=new ea({server:this.httpServer,path:"/ws"}),this.setupServer()}async handleHttp(a,e){if(this.options.enableCors)e.setHeader("Access-Control-Allow-Origin","*"),e.setHeader("Access-Control-Allow-Methods","GET, POST, OPTIONS"),e.setHeader("Access-Control-Allow-Headers","Content-Type");if(a.method==="OPTIONS"){e.writeHead(200),e.end();return}if(a.url==="/health"){e.writeHead(200,{"Content-Type":"application/json"}),e.end(JSON.stringify({status:"ok",clients:this.clients.size}));return}let i=V();if(!await Q(a,e,i))e.writeHead(
|
|
13
|
-
<html lang="en">
|
|
14
|
-
<head>
|
|
15
|
-
<meta charset="UTF-8">
|
|
16
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
17
|
-
<title>Vision Dashboard</title>
|
|
18
|
-
<style>
|
|
19
|
-
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
20
|
-
body {
|
|
21
|
-
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
|
|
22
|
-
background: #0a0a0a;
|
|
23
|
-
color: #fff;
|
|
24
|
-
display: flex;
|
|
25
|
-
align-items: center;
|
|
26
|
-
justify-content: center;
|
|
27
|
-
min-height: 100vh;
|
|
28
|
-
}
|
|
29
|
-
.container {
|
|
30
|
-
text-align: center;
|
|
31
|
-
max-width: 600px;
|
|
32
|
-
padding: 2rem;
|
|
33
|
-
}
|
|
34
|
-
h1 { font-size: 2.5rem; margin-bottom: 1rem; }
|
|
35
|
-
.status {
|
|
36
|
-
display: inline-flex;
|
|
37
|
-
align-items: center;
|
|
38
|
-
gap: 0.5rem;
|
|
39
|
-
padding: 0.5rem 1rem;
|
|
40
|
-
background: #1a1a1a;
|
|
41
|
-
border-radius: 8px;
|
|
42
|
-
margin: 1rem 0;
|
|
43
|
-
}
|
|
44
|
-
.dot {
|
|
45
|
-
width: 8px;
|
|
46
|
-
height: 8px;
|
|
47
|
-
border-radius: 50%;
|
|
48
|
-
background: #22c55e;
|
|
49
|
-
animation: pulse 2s infinite;
|
|
50
|
-
}
|
|
51
|
-
@keyframes pulse {
|
|
52
|
-
0%, 100% { opacity: 1; }
|
|
53
|
-
50% { opacity: 0.5; }
|
|
54
|
-
}
|
|
55
|
-
.info {
|
|
56
|
-
background: #1a1a1a;
|
|
57
|
-
border-radius: 8px;
|
|
58
|
-
padding: 1.5rem;
|
|
59
|
-
margin-top: 2rem;
|
|
60
|
-
text-align: left;
|
|
61
|
-
}
|
|
62
|
-
.info h2 { font-size: 1.2rem; margin-bottom: 1rem; }
|
|
63
|
-
.info p { color: #888; line-height: 1.6; margin-bottom: 0.5rem; }
|
|
64
|
-
code {
|
|
65
|
-
background: #0a0a0a;
|
|
66
|
-
padding: 0.2rem 0.4rem;
|
|
67
|
-
border-radius: 4px;
|
|
68
|
-
color: #22c55e;
|
|
69
|
-
font-family: 'Monaco', monospace;
|
|
70
|
-
}
|
|
71
|
-
a { color: #3b82f6; text-decoration: none; }
|
|
72
|
-
a:hover { text-decoration: underline; }
|
|
73
|
-
</style>
|
|
74
|
-
</head>
|
|
75
|
-
<body>
|
|
76
|
-
<div class="container">
|
|
77
|
-
<h1>\uD83D\uDD2E Vision Dashboard</h1>
|
|
78
|
-
<div class="status">
|
|
79
|
-
<span class="dot"></span>
|
|
80
|
-
<span id="status">Connected to WebSocket</span>
|
|
81
|
-
</div>
|
|
82
|
-
|
|
83
|
-
<div class="info">
|
|
84
|
-
<h2>Dashboard UI Coming Soon!</h2>
|
|
85
|
-
<p>The Vision Dashboard backend is running and ready.</p>
|
|
86
|
-
<p>The React UI is currently in development. For now, you can:</p>
|
|
87
|
-
<ul style="margin-top: 1rem; padding-left: 1.5rem; color: #888;">
|
|
88
|
-
<li>Connect via WebSocket at <code>ws://${this.options.host}:${this.options.port}</code></li>
|
|
89
|
-
<li>Use JSON-RPC methods: <code>status</code>, <code>traces/list</code>, <code>routes/list</code></li>
|
|
90
|
-
<li>Watch traces in real-time as requests come in</li>
|
|
91
|
-
</ul>
|
|
92
|
-
<p style="margin-top: 1rem;">
|
|
93
|
-
See <a href="https://github.com/yourusername/vision" target="_blank">documentation</a> for more info.
|
|
94
|
-
</p>
|
|
95
|
-
</div>
|
|
96
|
-
</div>
|
|
97
|
-
|
|
98
|
-
<script>
|
|
99
|
-
const ws = new WebSocket('ws://${this.options.host}:${this.options.port}');
|
|
100
|
-
const status = document.getElementById('status');
|
|
101
|
-
|
|
102
|
-
ws.onopen = () => {
|
|
103
|
-
status.textContent = 'Connected to WebSocket \u2713';
|
|
104
|
-
console.log('\uD83D\uDD2E Connected to Vision Dashboard');
|
|
105
|
-
};
|
|
106
|
-
|
|
107
|
-
ws.onclose = () => {
|
|
108
|
-
status.textContent = 'Disconnected';
|
|
109
|
-
status.style.color = '#ef4444';
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
ws.onmessage = (event) => {
|
|
113
|
-
const data = JSON.parse(event.data);
|
|
114
|
-
console.log('\uD83D\uDCE8 Message:', data);
|
|
115
|
-
};
|
|
116
|
-
</script>
|
|
117
|
-
</body>
|
|
118
|
-
</html>`}setupServer(){this.httpServer.listen(this.options.port,this.options.host,()=>{console.log(`\uD83D\uDE80 Vision Dashboard running at http://${this.options.host}:${this.options.port}`),console.log(` WebSocket: ws://${this.options.host}:${this.options.port}/ws`)}),this.wss.on("connection",(a)=>{console.log("\uD83D\uDD0C Dashboard client connected"),this.clients.add(a),a.on("message",async(e)=>{let i=e.toString(),n=await this.rpc.handle(i);if(n)a.send(n)}),a.on("close",()=>{console.log("\uD83D\uDD0C Dashboard client disconnected"),this.clients.delete(a)}),a.on("error",(e)=>{console.error("WebSocket error:",e),this.clients.delete(a)}),a.send(JSON.stringify({jsonrpc:"2.0",method:"connection.established",params:{timestamp:Date.now()}}))}),this.wss.on("error",(a)=>{console.error("WebSocket server error:",a)}),this.httpServer.on("error",(a)=>{console.error("HTTP server error:",a)})}registerMethod(a,e){this.rpc.register(a,e)}broadcast(a){let e=this.rpc.createNotification(a.type,a.data);this.clients.forEach((i)=>{if(i.readyState===ia.OPEN)i.send(e)})}getClientCount(){return this.clients.size}async close(){return new Promise((a,e)=>{this.clients.forEach((i)=>i.close()),this.clients.clear(),this.wss.close((i)=>{this.httpServer.close((n)=>{if(i||n)e(i||n);else console.log("\u2705 Vision Dashboard server closed"),a()})})})}}import{webcrypto as $}from"crypto";var W="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var oa=128,u,m;function sa(a){if(!u||u.length<a)u=Buffer.allocUnsafe(a*oa),$.getRandomValues(u),m=0;else if(m+a>u.length)$.getRandomValues(u),m=0;m+=a}function d(a=21){sa(a|=0);let e="";for(let i=m-a;i<m;i++)e+=W[u[i]&63];return e}class f{traces=new Map;maxTraces;constructor(a=1000){this.maxTraces=a}createTrace(a,e){let i={id:d(),timestamp:Date.now(),method:a,path:e,spans:[]};return this.addTrace(i),i}addTrace(a){if(this.traces.size>=this.maxTraces){let e=this.traces.keys().next().value;if(e)this.traces.delete(e)}this.traces.set(a.id,a)}addSpan(a,e){let i=this.traces.get(a);if(i)i.spans.push(e)}completeTrace(a,e,i){let n=this.traces.get(a);if(n)n.statusCode=e,n.duration=i}getTrace(a){return this.traces.get(a)}getAllTraces(){return Array.from(this.traces.values()).reverse()}getTraces(a){let e=this.getAllTraces();if(a?.method)e=e.filter((i)=>i.method===a.method);if(a?.statusCode)e=e.filter((i)=>i.statusCode===a.statusCode);if(a?.minDuration)e=e.filter((i)=>(i.duration??0)>=a.minDuration);if(a?.limit)e=e.slice(0,a.limit);return e}clear(){this.traces.clear()}count(){return this.traces.size}}class g{activeSpans=new Map;startSpan(a,e,i){let n={id:d(),traceId:e,parentId:i,name:a,startTime:Date.now(),attributes:{},events:[]};return this.activeSpans.set(n.id,n),n}endSpan(a){let e=this.activeSpans.get(a);if(e)e.endTime=Date.now(),e.duration=e.endTime-e.startTime,this.activeSpans.delete(a);return e}setAttribute(a,e,i){let n=this.activeSpans.get(a);if(n&&n.attributes)n.attributes[e]=i}addEvent(a,e,i){let n=this.activeSpans.get(a);if(n){let o={name:e,timestamp:Date.now(),attributes:i};n.events?.push(o)}}getSpan(a){return this.activeSpans.get(a)}}class U{logs=[];maxLogs;constructor(a=1e4){this.maxLogs=a}addLog(a,e,i,n){let o={id:d(),timestamp:Date.now(),level:a,message:e,args:i,stack:n};if(this.logs.push(o),this.logs.length>this.maxLogs)this.logs.shift();return o}getAllLogs(){return[...this.logs].reverse()}getLogs(a){let e=this.logs;if(a?.level)e=e.filter((n)=>n.level===a.level);if(a?.search){let n=a.search.toLowerCase();e=e.filter((o)=>o.message.toLowerCase().includes(n)||o.args?.some((c)=>String(c).toLowerCase().includes(n)))}if(a?.since)e=e.filter((n)=>n.timestamp>=(a.since??0));let i=[...e].reverse();if(a?.limit)return i.slice(0,a.limit);return i}clear(){this.logs=[]}count(){return this.logs.length}}class F{originalConsole={log:console.log,info:console.info,warn:console.warn,error:console.error,debug:console.debug};logStore;onLog;constructor(a,e){this.logStore=a,this.onLog=e}start(){let a=(e,i)=>{return(...n)=>{i.apply(console,n);let o=n.map((s)=>{if(typeof s==="string")return s;if(s instanceof Error)return s.message;try{return JSON.stringify(s)}catch{return String(s)}}).join(" "),c;if(e==="error"){let s=n.find((p)=>p instanceof Error);if(s)c=s.stack}this.logStore.addLog(e,o,n,c),this.onLog?.(e,o,n,c)}};console.log=a("log",this.originalConsole.log),console.info=a("info",this.originalConsole.info),console.warn=a("warn",this.originalConsole.warn),console.error=a("error",this.originalConsole.error),console.debug=a("debug",this.originalConsole.debug)}stop(){console.log=this.originalConsole.log,console.info=this.originalConsole.info,console.warn=this.originalConsole.warn,console.error=this.originalConsole.error,console.debug=this.originalConsole.debug}}class J{server;traceStore;tracer;logStore;consoleInterceptor;routes=[];services=[];appStatus={name:"Unknown",version:"0.0.0",environment:"development",running:!1};constructor(a={}){if(this.server=new b(a),this.traceStore=new f(a.maxTraces),this.tracer=new g,this.logStore=new U(a.maxLogs),a.captureConsole!==!1)this.consoleInterceptor=new F(this.logStore,()=>{this.broadcast({type:"log.entry",data:this.logStore.getLogs({limit:1})[0]})}),this.consoleInterceptor.start();this.registerMethods()}registerMethods(){this.server.registerMethod("status",async()=>{return this.appStatus}),this.server.registerMethod("traces/list",async(a)=>{return this.traceStore.getTraces({method:a?.method,statusCode:a?.statusCode,minDuration:a?.minDuration,limit:a?.limit??100})}),this.server.registerMethod("traces/get",async(a)=>{if(!a?.traceId)throw Error("traceId is required");return this.traceStore.getTrace(a.traceId)}),this.server.registerMethod("traces/clear",async()=>{return this.traceStore.clear(),{success:!0}}),this.server.registerMethod("traces/export",async(a)=>{let e=a?.format||"json",i=this.traceStore.getAllTraces();if(e==="ndjson")return i.map((n)=>JSON.stringify(n)).join(`
|
|
12
|
+
*/var j=O(),X=L("path").extname;var H=Object.create(null),y=G,z=Object.create(null);D(H,z);function G(a){if(!a||typeof a!=="string")return!1;var e=X("x."+a).toLowerCase().substr(1);if(!e)return!1;return z[e]||!1}function D(a,e){var i=["nginx","apache",void 0,"iana"];Object.keys(j).forEach(function(o){var c=j[o],s=c.extensions;if(!s||!s.length)return;a[o]=s;for(var p=0;p<s.length;p++){var t=s[p];if(e[t]){var v=i.indexOf(j[e[t]].source),h=i.indexOf(c.source);if(e[t]!=="application/octet-stream"&&(v>h||v===h&&e[t].substr(0,12)==="application/"))continue}e[t]=o}})}var aa=S(P(import.meta.url));async function Q(a,e,i){let n=a.url||"/",o=n.indexOf("?");if(o!==-1)n=n.substring(0,o);if(n==="/"||!n.includes("."))n="/index.html";let c=q(i,n);if(!c.startsWith(i))return!1;if(!I(c))return!1;try{let s=await E(c),p=y(c)||"application/octet-stream";return e.writeHead(200,{"Content-Type":p,"Cache-Control":"public, max-age=3600"}),e.end(s),!0}catch(s){return console.error("Error serving static file:",s),!1}}function V(){let a=q(aa,"../..");return q(a,"dist/ui")}class b{httpServer;wss;clients=new Set;rpc;options;constructor(a={}){this.options={port:a.port??9500,host:a.host??"localhost",maxTraces:a.maxTraces??1000,maxLogs:a.maxLogs??1e4,captureConsole:a.captureConsole??!0,enableCors:a.enableCors??!0},this.rpc=new w,this.httpServer=na((e,i)=>{this.handleHttp(e,i).catch((n)=>{console.error("HTTP handler error:",n),i.writeHead(500),i.end("Internal Server Error")})}),this.wss=new ea({server:this.httpServer,path:"/ws"}),this.setupServer()}async handleHttp(a,e){if(this.options.enableCors)e.setHeader("Access-Control-Allow-Origin","*"),e.setHeader("Access-Control-Allow-Methods","GET, POST, OPTIONS"),e.setHeader("Access-Control-Allow-Headers","Content-Type");if(a.method==="OPTIONS"){e.writeHead(200),e.end();return}if(a.url==="/health"){e.writeHead(200,{"Content-Type":"application/json"}),e.end(JSON.stringify({status:"ok",clients:this.clients.size}));return}let i=V();if(!await Q(a,e,i))e.writeHead(404,{"Content-Type":"text/plain"}),e.end("Vision Dashboard UI not found. Build the UI or ensure adapters are running.")}setupServer(){this.httpServer.listen(this.options.port,this.options.host,()=>{console.log(`\uD83D\uDE80 Vision Dashboard running at http://${this.options.host}:${this.options.port}`),console.log(` WebSocket: ws://${this.options.host}:${this.options.port}/ws`)}),this.wss.on("connection",(a)=>{console.log("\uD83D\uDD0C Dashboard client connected"),this.clients.add(a),a.on("message",async(e)=>{let i=e.toString(),n=await this.rpc.handle(i);if(n)a.send(n)}),a.on("close",()=>{console.log("\uD83D\uDD0C Dashboard client disconnected"),this.clients.delete(a)}),a.on("error",(e)=>{console.error("WebSocket error:",e),this.clients.delete(a)}),a.send(JSON.stringify({jsonrpc:"2.0",method:"connection.established",params:{timestamp:Date.now()}}))}),this.wss.on("error",(a)=>{console.error("WebSocket server error:",a)}),this.httpServer.on("error",(a)=>{console.error("HTTP server error:",a)})}registerMethod(a,e){this.rpc.register(a,e)}broadcast(a){let e=this.rpc.createNotification(a.type,a.data);this.clients.forEach((i)=>{if(i.readyState===ia.OPEN)i.send(e)})}getClientCount(){return this.clients.size}async close(){return new Promise((a,e)=>{this.clients.forEach((i)=>i.close()),this.clients.clear(),this.wss.close((i)=>{this.httpServer.close((n)=>{if(i||n)e(i||n);else console.log("\u2705 Vision Dashboard server closed"),a()})})})}}import{webcrypto as $}from"crypto";var W="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";var oa=128,u,m;function sa(a){if(!u||u.length<a)u=Buffer.allocUnsafe(a*oa),$.getRandomValues(u),m=0;else if(m+a>u.length)$.getRandomValues(u),m=0;m+=a}function d(a=21){sa(a|=0);let e="";for(let i=m-a;i<m;i++)e+=W[u[i]&63];return e}class f{traces=new Map;maxTraces;constructor(a=1000){this.maxTraces=a}createTrace(a,e){let i={id:d(),timestamp:Date.now(),method:a,path:e,spans:[]};return this.addTrace(i),i}addTrace(a){if(this.traces.size>=this.maxTraces){let e=this.traces.keys().next().value;if(e)this.traces.delete(e)}this.traces.set(a.id,a)}addSpan(a,e){let i=this.traces.get(a);if(i)i.spans.push(e)}completeTrace(a,e,i){let n=this.traces.get(a);if(n)n.statusCode=e,n.duration=i}getTrace(a){return this.traces.get(a)}getAllTraces(){return Array.from(this.traces.values()).reverse()}getTraces(a){let e=this.getAllTraces();if(a?.method)e=e.filter((i)=>i.method===a.method);if(a?.statusCode)e=e.filter((i)=>i.statusCode===a.statusCode);if(a?.minDuration)e=e.filter((i)=>(i.duration??0)>=a.minDuration);if(a?.limit)e=e.slice(0,a.limit);return e}clear(){this.traces.clear()}count(){return this.traces.size}}class g{activeSpans=new Map;startSpan(a,e,i){let n={id:d(),traceId:e,parentId:i,name:a,startTime:Date.now(),attributes:{},events:[]};return this.activeSpans.set(n.id,n),n}endSpan(a){let e=this.activeSpans.get(a);if(e)e.endTime=Date.now(),e.duration=e.endTime-e.startTime,this.activeSpans.delete(a);return e}setAttribute(a,e,i){let n=this.activeSpans.get(a);if(n&&n.attributes)n.attributes[e]=i}addEvent(a,e,i){let n=this.activeSpans.get(a);if(n){let o={name:e,timestamp:Date.now(),attributes:i};n.events?.push(o)}}getSpan(a){return this.activeSpans.get(a)}}class U{logs=[];maxLogs;constructor(a=1e4){this.maxLogs=a}addLog(a,e,i,n){let o={id:d(),timestamp:Date.now(),level:a,message:e,args:i,stack:n};if(this.logs.push(o),this.logs.length>this.maxLogs)this.logs.shift();return o}getAllLogs(){return[...this.logs].reverse()}getLogs(a){let e=this.logs;if(a?.level)e=e.filter((n)=>n.level===a.level);if(a?.search){let n=a.search.toLowerCase();e=e.filter((o)=>o.message.toLowerCase().includes(n)||o.args?.some((c)=>String(c).toLowerCase().includes(n)))}if(a?.since)e=e.filter((n)=>n.timestamp>=(a.since??0));let i=[...e].reverse();if(a?.limit)return i.slice(0,a.limit);return i}clear(){this.logs=[]}count(){return this.logs.length}}class F{originalConsole={log:console.log,info:console.info,warn:console.warn,error:console.error,debug:console.debug};logStore;onLog;constructor(a,e){this.logStore=a,this.onLog=e}start(){let a=(e,i)=>{return(...n)=>{i.apply(console,n);let o=n.map((s)=>{if(typeof s==="string")return s;if(s instanceof Error)return s.message;try{return JSON.stringify(s)}catch{return String(s)}}).join(" "),c;if(e==="error"){let s=n.find((p)=>p instanceof Error);if(s)c=s.stack}this.logStore.addLog(e,o,n,c),this.onLog?.(e,o,n,c)}};console.log=a("log",this.originalConsole.log),console.info=a("info",this.originalConsole.info),console.warn=a("warn",this.originalConsole.warn),console.error=a("error",this.originalConsole.error),console.debug=a("debug",this.originalConsole.debug)}stop(){console.log=this.originalConsole.log,console.info=this.originalConsole.info,console.warn=this.originalConsole.warn,console.error=this.originalConsole.error,console.debug=this.originalConsole.debug}}class J{server;traceStore;tracer;logStore;consoleInterceptor;routes=[];services=[];appStatus={name:"Unknown",version:"0.0.0",environment:"development",running:!1};constructor(a={}){if(this.server=new b(a),this.traceStore=new f(a.maxTraces),this.tracer=new g,this.logStore=new U(a.maxLogs),a.captureConsole!==!1)this.consoleInterceptor=new F(this.logStore,()=>{this.broadcast({type:"log.entry",data:this.logStore.getLogs({limit:1})[0]})}),this.consoleInterceptor.start();this.registerMethods()}registerMethods(){this.server.registerMethod("status",async()=>{return this.appStatus}),this.server.registerMethod("traces/list",async(a)=>{return this.traceStore.getTraces({method:a?.method,statusCode:a?.statusCode,minDuration:a?.minDuration,limit:a?.limit??100})}),this.server.registerMethod("traces/get",async(a)=>{if(!a?.traceId)throw Error("traceId is required");return this.traceStore.getTrace(a.traceId)}),this.server.registerMethod("traces/clear",async()=>{return this.traceStore.clear(),{success:!0}}),this.server.registerMethod("traces/export",async(a)=>{let e=a?.format||"json",i=this.traceStore.getAllTraces();if(e==="ndjson")return i.map((n)=>JSON.stringify(n)).join(`
|
|
119
13
|
`);return JSON.stringify(i,null,2)}),this.server.registerMethod("routes/list",async()=>{return this.routes}),this.server.registerMethod("services/list",async()=>{return this.services}),this.server.registerMethod("version",async()=>{return{version:"0.0.1",name:"Vision Dashboard"}}),this.server.registerMethod("logs/list",async(a)=>{return this.logStore.getLogs({level:a?.level,search:a?.search,limit:a?.limit??100,since:a?.since})}),this.server.registerMethod("logs/clear",async()=>{return this.logStore.clear(),{success:!0}}),this.server.registerMethod("traces/addClientMetrics",async(a)=>{let{traceId:e,clientDuration:i}=a;if(!e||typeof i!=="number")throw Error("traceId and clientDuration are required");let n=this.traceStore.getTrace(e);if(n)n.metadata={...n.metadata||{},clientDuration:i};return{success:!0}})}setAppStatus(a){this.appStatus={...this.appStatus,...a},this.broadcast({type:"app.started",data:this.appStatus})}registerRoutes(a){this.routes=a}registerServices(a){this.services=a}createTrace(a,e){return this.traceStore.createTrace(a,e)}completeTrace(a,e,i){this.traceStore.completeTrace(a,e,i);let n=this.traceStore.getTrace(a);if(n)this.broadcast({type:"trace.new",data:n})}getTracer(){return this.tracer}getServer(){return this.server}createSpanHelper(a){return(e,i={},n)=>{let o=this.tracer.startSpan(e,a);for(let[c,s]of Object.entries(i))this.tracer.setAttribute(o.id,c,s);try{let c=n(),s=this.tracer.endSpan(o.id);if(s)this.traceStore.addSpan(a,s);return c}catch(c){this.tracer.setAttribute(o.id,"error",!0),this.tracer.setAttribute(o.id,"error.message",c instanceof Error?c.message:String(c));let s=this.tracer.endSpan(o.id);if(s)this.traceStore.addSpan(a,s);throw c}}}getTraceStore(){return this.traceStore}log(a,e,i){let n=i?[i]:void 0,o=this.logStore.addLog(a,e,n);return this.broadcast({type:"log.entry",data:o}),o}getLogStore(){return this.logStore}broadcast(a){this.server.broadcast(a)}logStdout(a){this.broadcast({type:"log.stdout",data:{message:a,timestamp:Date.now()}})}logStderr(a){this.broadcast({type:"log.stderr",data:{message:a,timestamp:Date.now()}})}getClientCount(){return this.server.getClientCount()}async close(){await this.server.close()}}function ca(a){try{let e=Z(a);return{template:R(e),fields:e}}catch(e){console.warn("Failed to generate template from Zod schema:",e);return}}function Z(a,e=[]){let i=[];if(!(a.def||a._def))return i;let o=a,c=o.def||o._def,s=c?.type||c?.typeName;if(s==="object"||s==="ZodObject"){let p=c?.shape,t=typeof p==="function"?p():p;for(let[v,h]of Object.entries(t||{})){let l=h,r=l.def||l._def,N=l.type==="optional"||r?.type==="optional"||r?.typeName==="ZodOptional"||r?.typeName==="ZodDefault",k=r?.description||l.description;if(!k&&r?.wrapped)k=(r.wrapped.def||r.wrapped._def)?.description||r.wrapped.description;let T=pa(l),_=Z(l,[...e,v]);i.push({name:v,type:T,description:k,required:!N,nested:_.length>0?_:void 0,example:ta(l,T)})}}return i}function pa(a){let e=a,i=e.def||e._def;while(i?.type==="optional"||i?.type==="nullable"||i?.type==="default"||i?.typeName==="ZodOptional"||i?.typeName==="ZodNullable"||i?.typeName==="ZodDefault")e=i?.innerType||i?.wrapped||e,i=e.def||e._def;switch(i?.type||i?.typeName||e.type){case"string":case"ZodString":return"string";case"number":case"ZodNumber":return"number";case"boolean":case"ZodBoolean":return"boolean";case"array":case"ZodArray":return"array";case"object":case"ZodObject":return"object";case"enum":case"ZodEnum":return"enum";case"date":case"ZodDate":return"date";default:return"any"}}function ta(a,e){switch(e){case"string":return"";case"number":return 0;case"boolean":return!1;case"array":return[];case"object":return{};default:return null}}function R(a,e=0){let i=[],n=" ".repeat(e);return i.push("{"),a.forEach((o,c)=>{let s=c===a.length-1,p=o.description||o.name;i.push(`${n} // ${p}`);let t;if(o.nested&&o.nested.length>0)t=R(o.nested,e+1);else t=JSON.stringify(o.example);i.push(`${n} "${o.name}": ${t}${s?"":","}`)}),i.push(`${n}}`),i.join(`
|
|
120
14
|
`)}import{readFileSync as ra,existsSync as Y}from"fs";import{join as la}from"path";import{spawn as ua}from"child_process";function ma(){try{let a=la(process.cwd(),"package.json");if(Y(a)){let e=JSON.parse(ra(a,"utf-8"));return{name:e.name||"unknown",version:e.version||"0.0.0"}}}catch(a){}return{name:"unknown",version:"0.0.0"}}function da(){let a={},e=["DATABASE_URL","DB_URL","POSTGRES_URL","MYSQL_URL","MONGODB_URL"];for(let n of e)if(process.env[n]){a.database=process.env[n];break}let i=["REDIS_URL","CACHE_URL","UPSTASH_REDIS_URL"];for(let n of i)if(process.env[n]){a.redis=process.env[n];break}return a}function K(){let a=["drizzle.config.ts","drizzle.config.js","drizzle.config.mjs"];for(let e of a)if(Y(e))return{detected:!0,configPath:e};return{detected:!1}}var x=null;function xa(a=4983){if(!K().detected)return console.warn("\u26A0\uFE0F Drizzle config not found. Skipping Drizzle Studio auto-start."),!1;console.log(`\uD83D\uDDC4\uFE0F Starting Drizzle Studio on port ${a}...`);try{return x=ua("npx",["drizzle-kit","studio","--port",String(a),"--host","0.0.0.0"],{stdio:"inherit",detached:!1}),x.on("error",(i)=>{console.error("\u274C Failed to start Drizzle Studio:",i.message)}),x.on("exit",(i)=>{if(i!==0&&i!==null)console.error(`\u274C Drizzle Studio exited with code ${i}`)}),console.log("\u2705 Drizzle Studio started"),!0}catch(i){return console.error("\u274C Failed to start Drizzle Studio:",i),!1}}function va(){if(x)x.kill(),x=null,console.log("\uD83D\uDED1 Drizzle Studio stopped")}export{va as stopDrizzleStudio,xa as startDrizzleStudio,ca as generateZodTemplate,K as detectDrizzle,ma as autoDetectPackageInfo,da as autoDetectIntegrations,b as VisionWebSocketServer,J as VisionCore,g as Tracer,f as TraceStore};
|