@agimon-ai/po-logsink 0.0.1-alpha.76 → 0.0.1-alpha.78

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/cli.cjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- const e=require("./logSinkConfig-BNh46IFF.cjs"),t=require("./LogStorageService-1aDDCsCf.cjs"),n=require("./container-eY4E1Zy2.cjs"),r=require("./node-CSSvy-ks.cjs"),i=require("./stdio-rRU7ai29.cjs");let a=require("zod"),o=require("node:fs/promises");o=e.a(o,1);let s=require("node:path");s=e.a(s,1);let c=require("node:child_process"),l=require("node:util"),u=require("node:url"),d=require("@agimon-ai/foundation-port-registry"),f=require("@agimon-ai/foundation-process-registry"),p=require("commander"),m=require("@hono/node-server"),h=require("node:crypto"),g=require("hono"),_=require("hono-rate-limiter"),v=require("hono/cors"),y=require("hono/html"),b=require("hono/jsx/jsx-runtime");var x=`0.0.1-alpha.76`;const S=a.z.object({service:a.z.string().optional(),level:a.z.string().optional(),traceId:a.z.string().optional(),search:a.z.string().optional(),limit:a.z.coerce.number().min(1).max(1e3).default(25),offset:a.z.coerce.number().min(0).default(0)}),C=a.z.object({groupBy:a.z.enum([`session`,`workflow-run`,`workflow-name`,`job`,`step`,`agent`,`model`,`provider`]).optional(),startTime:a.z.string().optional(),endTime:a.z.string().optional(),period:a.z.enum([`day`,`week`,`month`,`all`]).optional(),bucket:a.z.enum([`hour`,`day`,`week`,`month`]).optional(),sessionId:a.z.string().optional(),workflowRunId:a.z.string().optional(),workflowName:a.z.string().optional(),jobName:a.z.string().optional(),stepName:a.z.string().optional(),agentName:a.z.string().optional(),service:a.z.array(a.z.string()).optional(),model:a.z.array(a.z.string()).optional(),provider:a.z.array(a.z.string()).optional(),limit:a.z.coerce.number().min(1).max(500).optional(),sort:a.z.enum([`last-seen`,`total-tokens`,`issues`]).optional(),toolLimit:a.z.coerce.number().min(1).max(500).optional(),toolSort:a.z.enum([`p90-total-tokens`,`avg-total-tokens`,`invocations`]).optional()});function w(e,t){let n=e.req.queries(t)??[],r=e.req.query(t),i=(n.length>0?n:r?[r]:[]).flatMap(e=>e.split(`,`)).map(e=>e.trim()).filter(e=>e.length>0);return i.length>0?i:void 0}function T(e){let n=new g.Hono,r=e.get(t.d.LogQueryService),i=e.get(t.d.LogSearchService),a=e.get(t.d.LogMetricsService);return n.get(`/logs`,async e=>{try{let{service:t,level:n,traceId:a,search:o,limit:s,offset:c}=S.parse({service:e.req.query(`service`),level:e.req.query(`level`),traceId:e.req.query(`traceId`),search:e.req.query(`search`),limit:e.req.query(`limit`),offset:e.req.query(`offset`)}),l,u=0;if(o){let e={};t&&(e.service=t),n&&(e.level=n);let r=await i.searchLogsPaginated(o,{...e,offset:c},s);l=r.results,u=r.total}else{let e=n?n.split(`,`):[`info`,`warn`,`error`,`fatal`],i=await r.queryLogs({level:e,service:t||void 0,traceId:a||void 0,limit:s,offset:c});l=i.logs,u=i.total}return e.json({logs:l,total:u,hasMore:c+s<u})}catch(t){return console.error(`Failed to query logs:`,t),e.json({error:`Failed to query logs`,message:t instanceof Error?t.message:String(t)},500)}}),n.get(`/services`,async e=>{try{let t=await r.getActiveServices();return e.json({services:t,total:t.length})}catch(t){return console.error(`Failed to get services:`,t),e.json({error:`Failed to get services`,message:t instanceof Error?t.message:String(t)},500)}}),n.get(`/stats`,async e=>{try{let t=await r.getStatistics(),n=t.reduce((e,t)=>e+t.count,0),i=t.filter(e=>e.level===`error`||e.level===`fatal`).reduce((e,t)=>e+t.count,0),a=new Set(t.map(e=>e.service)).size;return e.json({totalLogs:n,errors:i,services:a,breakdown:t})}catch(t){return console.error(`Failed to get statistics:`,t),e.json({error:`Failed to get statistics`,message:t instanceof Error?t.message:String(t)},500)}}),n.get(`/metrics`,async e=>{try{let t=C.parse({groupBy:e.req.query(`groupBy`),startTime:e.req.query(`startTime`),endTime:e.req.query(`endTime`),period:e.req.query(`period`),bucket:e.req.query(`bucket`),sessionId:e.req.query(`sessionId`),workflowRunId:e.req.query(`workflowRunId`),workflowName:e.req.query(`workflowName`),jobName:e.req.query(`jobName`),stepName:e.req.query(`stepName`),agentName:e.req.query(`agentName`),service:w(e,`service`),model:w(e,`model`),provider:w(e,`provider`),limit:e.req.query(`limit`),sort:e.req.query(`sort`),toolLimit:e.req.query(`toolLimit`),toolSort:e.req.query(`toolSort`)}),n=await a.getMetrics({sessionId:t.sessionId,workflowRunId:t.workflowRunId,workflowName:t.workflowName,jobName:t.jobName,stepName:t.stepName,agentName:t.agentName,service:t.service,model:t.model,provider:t.provider,startTime:t.startTime?new Date(t.startTime):void 0,endTime:t.endTime?new Date(t.endTime):void 0},{groupBy:t.groupBy,sort:t.sort,toolSort:t.toolSort,limit:t.limit,toolLimit:t.toolLimit,period:t.period,bucket:t.bucket});return e.json(n)}catch(t){return console.error(`Failed to get metrics:`,t),e.json({error:`Failed to get metrics`,message:t instanceof Error?t.message:String(t)},500)}}),n}function ee(e){return e.toLocaleString(`en-US`,{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1})}const E=`controls-section`,D=`input-field`,O=`table-container`,k=`log-table`,A=`compact-table`,j=`level-trace`,te=`level-debug`,ne=`level-info`,re=`level-warn`,ie=`level-error`,ae=`level-fatal`,oe=`stats-container`,M=`stat-card`,se=`trace-link`,ce=`timestamp-cell`,le=`service-cell`,ue=`pagination-btn`,de=`log-entry-group`,fe=`metadata-row`,pe=`message-row`,me=`message-full-cell`;function he(e){let t=e.toLowerCase();return t===`trace`?j:t===`debug`?te:t===`info`?ne:t===`warn`?re:t===`error`?ie:t===`fatal`?ae:``}function ge(e){if(!e||typeof e!=`object`)return null;let t=e,n={};for(let[e,r]of Object.entries(t))e!==`trace.id`&&e!==`span.id`&&(n[e]=r);return Object.keys(n).length>0?n:null}function _e({logs:e}){return/* @__PURE__ */ (0,b.jsx)(`div`,{class:O,children:/* @__PURE__ */ (0,b.jsxs)(`table`,{class:k,children:[/* @__PURE__ */ (0,b.jsx)(`thead`,{children:/* @__PURE__ */ (0,b.jsxs)(`tr`,{children:[/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Timestamp`}),/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Level`}),/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Service`}),/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Trace ID`})]})}),e.map(e=>{let t=ge(e.metadata);return/* @__PURE__ */ (0,b.jsxs)(`tbody`,{class:de,children:[/* @__PURE__ */ (0,b.jsxs)(`tr`,{class:fe,children:[/* @__PURE__ */ (0,b.jsx)(`td`,{class:ce,children:ee(e.timestamp)}),/* @__PURE__ */ (0,b.jsx)(`td`,{class:he(e.level),children:e.level.toUpperCase()}),/* @__PURE__ */ (0,b.jsx)(`td`,{class:le,children:e.service}),/* @__PURE__ */ (0,b.jsx)(`td`,{children:e.traceId?/* @__PURE__ */ (0,b.jsxs)(`span`,{class:se,onclick:`dashboard.filterByTrace('${e.traceId}')`,children:[e.traceId.slice(0,8),`...`]}):/* @__PURE__ */ (0,b.jsx)(`span`,{children:`-`})})]}),/* @__PURE__ */ (0,b.jsx)(`tr`,{class:pe,children:/* @__PURE__ */ (0,b.jsxs)(`td`,{colspan:4,class:me,children:[/* @__PURE__ */ (0,b.jsx)(`div`,{children:e.message}),t&&/* @__PURE__ */ (0,b.jsx)(`pre`,{class:`attributes-cell`,children:JSON.stringify(t,null,2)})]})})]},e.id)})]})})}function N(e){return Math.round(e).toLocaleString()}function ve(e){return`${e.toFixed(1)}%`}function ye(e){return e?e.toISOString():`-`}function be({metrics:e}){return/* @__PURE__ */ (0,b.jsxs)(`section`,{class:`metrics-section`,children:[/* @__PURE__ */ (0,b.jsx)(`div`,{class:`section-header`,children:/* @__PURE__ */ (0,b.jsx)(`h2`,{children:`Workflow Metrics`})}),/* @__PURE__ */ (0,b.jsxs)(`div`,{class:E,children:[/* @__PURE__ */ (0,b.jsx)(`input`,{id:`metrics-model-filter`,class:D,type:`text`,placeholder:`Model`}),/* @__PURE__ */ (0,b.jsx)(`input`,{id:`metrics-provider-filter`,class:D,type:`text`,placeholder:`Provider`}),/* @__PURE__ */ (0,b.jsx)(`button`,{type:`button`,class:`btn`,onclick:`dashboard.fetchMetrics()`,children:`Apply Metrics Filters`})]}),/* @__PURE__ */ (0,b.jsxs)(`div`,{id:`metrics-summary`,class:oe,children:[/* @__PURE__ */ (0,b.jsxs)(`div`,{class:M,children:[/* @__PURE__ */ (0,b.jsx)(`h3`,{children:`Workflow Runs`}),/* @__PURE__ */ (0,b.jsx)(`div`,{id:`metrics-group-count`,class:`value`,children:e.totals.groupCount.toLocaleString()})]}),/* @__PURE__ */ (0,b.jsxs)(`div`,{class:M,children:[/* @__PURE__ */ (0,b.jsx)(`h3`,{children:`Failed Runs`}),/* @__PURE__ */ (0,b.jsx)(`div`,{id:`metrics-failed-groups`,class:`value`,children:e.totals.failedGroups.toLocaleString()})]}),/* @__PURE__ */ (0,b.jsxs)(`div`,{class:M,children:[/* @__PURE__ */ (0,b.jsx)(`h3`,{children:`Total Tokens`}),/* @__PURE__ */ (0,b.jsx)(`div`,{id:`metrics-total-tokens`,class:`value`,children:N(e.totals.totalTokens)})]}),/* @__PURE__ */ (0,b.jsxs)(`div`,{class:M,children:[/* @__PURE__ */ (0,b.jsx)(`h3`,{children:`Token Coverage`}),/* @__PURE__ */ (0,b.jsx)(`div`,{id:`metrics-token-coverage`,class:`value`,children:ve(e.totals.tokenCoveragePercent)})]})]}),/* @__PURE__ */ (0,b.jsxs)(`div`,{class:`metrics-grid`,children:[/* @__PURE__ */ (0,b.jsxs)(`div`,{class:O,children:[/* @__PURE__ */ (0,b.jsx)(`h3`,{children:`Top Workflow Runs`}),/* @__PURE__ */ (0,b.jsxs)(`table`,{class:A,children:[/* @__PURE__ */ (0,b.jsx)(`thead`,{children:/* @__PURE__ */ (0,b.jsxs)(`tr`,{children:[/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Workflow`}),/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Last Seen`}),/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Tokens`}),/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Issues`})]})}),/* @__PURE__ */ (0,b.jsx)(`tbody`,{id:`workflow-metrics-body`,children:e.groups.slice(0,10).map(e=>/* @__PURE__ */ (0,b.jsxs)(`tr`,{children:[/* @__PURE__ */ (0,b.jsx)(`td`,{children:e.key}),/* @__PURE__ */ (0,b.jsx)(`td`,{children:ye(e.lastSeen)}),/* @__PURE__ */ (0,b.jsx)(`td`,{children:N(e.totalTokens)}),/* @__PURE__ */ (0,b.jsx)(`td`,{children:e.issueCount.toLocaleString()})]}))})]})]}),/* @__PURE__ */ (0,b.jsxs)(`div`,{class:O,children:[/* @__PURE__ */ (0,b.jsx)(`h3`,{children:`Top Tools By Token Use`}),/* @__PURE__ */ (0,b.jsxs)(`table`,{class:A,children:[/* @__PURE__ */ (0,b.jsx)(`thead`,{children:/* @__PURE__ */ (0,b.jsxs)(`tr`,{children:[/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Tool`}),/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Invocations`}),/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Call p90`}),/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Output p90`})]})}),/* @__PURE__ */ (0,b.jsx)(`tbody`,{id:`tool-metrics-body`,children:e.tools.rows.slice(0,10).map(e=>/* @__PURE__ */ (0,b.jsxs)(`tr`,{children:[/* @__PURE__ */ (0,b.jsx)(`td`,{children:e.toolName}),/* @__PURE__ */ (0,b.jsx)(`td`,{children:e.invocationCount.toLocaleString()}),/* @__PURE__ */ (0,b.jsx)(`td`,{children:N(e.toolCallTurn.p90TotalTokens)}),/* @__PURE__ */ (0,b.jsx)(`td`,{children:N(e.toolOutputImpact.p90TotalTokens)})]}))})]})]})]})]})}function xe(){return/* @__PURE__ */ (0,b.jsx)(`input`,{id:`search-input`,type:`text`,class:D,placeholder:`Search logs...`,oninput:`dashboard.handleSearchInput(event)`})}function Se({services:e}){return/* @__PURE__ */ (0,b.jsxs)(`select`,{id:`service-select`,class:`select-field`,onchange:`dashboard.handleServiceChange(event)`,children:[/* @__PURE__ */ (0,b.jsx)(`option`,{value:``,children:`All Services`}),e.map(e=>/* @__PURE__ */ (0,b.jsx)(`option`,{value:e,children:e},e))]})}function Ce({stats:e}){return/* @__PURE__ */ (0,b.jsxs)(`div`,{class:oe,children:[/* @__PURE__ */ (0,b.jsxs)(`div`,{class:M,children:[/* @__PURE__ */ (0,b.jsx)(`h3`,{children:`Total Logs`}),/* @__PURE__ */ (0,b.jsx)(`div`,{class:`value`,children:e.totalLogs.toLocaleString()})]}),/* @__PURE__ */ (0,b.jsxs)(`div`,{class:M,children:[/* @__PURE__ */ (0,b.jsx)(`h3`,{children:`Errors`}),/* @__PURE__ */ (0,b.jsx)(`div`,{class:`value`,children:e.errors.toLocaleString()})]}),/* @__PURE__ */ (0,b.jsxs)(`div`,{class:M,children:[/* @__PURE__ */ (0,b.jsx)(`h3`,{children:`Services`}),/* @__PURE__ */ (0,b.jsx)(`div`,{class:`value`,children:e.services})]})]})}function we({initialLogs:e,services:t,stats:n,metrics:r}){return/* @__PURE__ */ (0,b.jsxs)(`div`,{class:`dashboard-container`,children:[/* @__PURE__ */ (0,b.jsxs)(`div`,{class:`dashboard-header`,children:[/* @__PURE__ */ (0,b.jsx)(`h1`,{children:`Log Dashboard`}),/* @__PURE__ */ (0,b.jsx)(`p`,{children:`Real-time log streaming with auto-refresh (3 seconds)`})]}),/* @__PURE__ */ (0,b.jsx)(Ce,{stats:n}),/* @__PURE__ */ (0,b.jsx)(be,{metrics:r}),/* @__PURE__ */ (0,b.jsxs)(`div`,{class:E,children:[/* @__PURE__ */ (0,b.jsx)(xe,{}),/* @__PURE__ */ (0,b.jsx)(Se,{services:t}),/* @__PURE__ */ (0,b.jsx)(`button`,{type:`button`,id:`refresh-btn`,class:`btn`,onclick:`dashboard.manualRefresh()`,children:`Refresh Now`})]}),/* @__PURE__ */ (0,b.jsx)(_e,{logs:e}),/* @__PURE__ */ (0,b.jsxs)(`div`,{id:`pagination-controls`,class:`pagination-container`,children:[/* @__PURE__ */ (0,b.jsx)(`button`,{type:`button`,id:`prev-btn`,class:ue,onclick:`dashboard.prevPage()`,disabled:!0,children:`Previous`}),/* @__PURE__ */ (0,b.jsx)(`span`,{id:`page-info`,class:`page-info`,children:`Page 1`}),/* @__PURE__ */ (0,b.jsx)(`button`,{type:`button`,id:`next-btn`,class:ue,onclick:`dashboard.nextPage()`,children:`Next`})]}),/* @__PURE__ */ (0,b.jsx)(`script`,{children:(0,y.raw)(`
2
+ const e=require("./logSinkConfig-BNh46IFF.cjs"),t=require("./LogStorageService-1aDDCsCf.cjs"),n=require("./container-eY4E1Zy2.cjs"),r=require("./node-CSSvy-ks.cjs"),i=require("./stdio-rRU7ai29.cjs");let a=require("zod"),o=require("node:fs/promises");o=e.a(o,1);let s=require("node:path");s=e.a(s,1);let c=require("node:child_process"),l=require("node:util"),u=require("node:url"),d=require("@agimon-ai/foundation-port-registry"),f=require("@agimon-ai/foundation-process-registry"),p=require("commander"),m=require("@hono/node-server"),h=require("node:crypto"),g=require("hono"),_=require("hono-rate-limiter"),v=require("hono/cors"),y=require("hono/html"),b=require("hono/jsx/jsx-runtime");var x=`0.0.1-alpha.78`;const S=a.z.object({service:a.z.string().optional(),level:a.z.string().optional(),traceId:a.z.string().optional(),search:a.z.string().optional(),limit:a.z.coerce.number().min(1).max(1e3).default(25),offset:a.z.coerce.number().min(0).default(0)}),C=a.z.object({groupBy:a.z.enum([`session`,`workflow-run`,`workflow-name`,`job`,`step`,`agent`,`model`,`provider`]).optional(),startTime:a.z.string().optional(),endTime:a.z.string().optional(),period:a.z.enum([`day`,`week`,`month`,`all`]).optional(),bucket:a.z.enum([`hour`,`day`,`week`,`month`]).optional(),sessionId:a.z.string().optional(),workflowRunId:a.z.string().optional(),workflowName:a.z.string().optional(),jobName:a.z.string().optional(),stepName:a.z.string().optional(),agentName:a.z.string().optional(),service:a.z.array(a.z.string()).optional(),model:a.z.array(a.z.string()).optional(),provider:a.z.array(a.z.string()).optional(),limit:a.z.coerce.number().min(1).max(500).optional(),sort:a.z.enum([`last-seen`,`total-tokens`,`issues`]).optional(),toolLimit:a.z.coerce.number().min(1).max(500).optional(),toolSort:a.z.enum([`p90-total-tokens`,`avg-total-tokens`,`invocations`]).optional()});function w(e,t){let n=e.req.queries(t)??[],r=e.req.query(t),i=(n.length>0?n:r?[r]:[]).flatMap(e=>e.split(`,`)).map(e=>e.trim()).filter(e=>e.length>0);return i.length>0?i:void 0}function T(e){let n=new g.Hono,r=e.get(t.d.LogQueryService),i=e.get(t.d.LogSearchService),a=e.get(t.d.LogMetricsService);return n.get(`/logs`,async e=>{try{let{service:t,level:n,traceId:a,search:o,limit:s,offset:c}=S.parse({service:e.req.query(`service`),level:e.req.query(`level`),traceId:e.req.query(`traceId`),search:e.req.query(`search`),limit:e.req.query(`limit`),offset:e.req.query(`offset`)}),l,u=0;if(o){let e={};t&&(e.service=t),n&&(e.level=n);let r=await i.searchLogsPaginated(o,{...e,offset:c},s);l=r.results,u=r.total}else{let e=n?n.split(`,`):[`info`,`warn`,`error`,`fatal`],i=await r.queryLogs({level:e,service:t||void 0,traceId:a||void 0,limit:s,offset:c});l=i.logs,u=i.total}return e.json({logs:l,total:u,hasMore:c+s<u})}catch(t){return console.error(`Failed to query logs:`,t),e.json({error:`Failed to query logs`,message:t instanceof Error?t.message:String(t)},500)}}),n.get(`/services`,async e=>{try{let t=await r.getActiveServices();return e.json({services:t,total:t.length})}catch(t){return console.error(`Failed to get services:`,t),e.json({error:`Failed to get services`,message:t instanceof Error?t.message:String(t)},500)}}),n.get(`/stats`,async e=>{try{let t=await r.getStatistics(),n=t.reduce((e,t)=>e+t.count,0),i=t.filter(e=>e.level===`error`||e.level===`fatal`).reduce((e,t)=>e+t.count,0),a=new Set(t.map(e=>e.service)).size;return e.json({totalLogs:n,errors:i,services:a,breakdown:t})}catch(t){return console.error(`Failed to get statistics:`,t),e.json({error:`Failed to get statistics`,message:t instanceof Error?t.message:String(t)},500)}}),n.get(`/metrics`,async e=>{try{let t=C.parse({groupBy:e.req.query(`groupBy`),startTime:e.req.query(`startTime`),endTime:e.req.query(`endTime`),period:e.req.query(`period`),bucket:e.req.query(`bucket`),sessionId:e.req.query(`sessionId`),workflowRunId:e.req.query(`workflowRunId`),workflowName:e.req.query(`workflowName`),jobName:e.req.query(`jobName`),stepName:e.req.query(`stepName`),agentName:e.req.query(`agentName`),service:w(e,`service`),model:w(e,`model`),provider:w(e,`provider`),limit:e.req.query(`limit`),sort:e.req.query(`sort`),toolLimit:e.req.query(`toolLimit`),toolSort:e.req.query(`toolSort`)}),n=await a.getMetrics({sessionId:t.sessionId,workflowRunId:t.workflowRunId,workflowName:t.workflowName,jobName:t.jobName,stepName:t.stepName,agentName:t.agentName,service:t.service,model:t.model,provider:t.provider,startTime:t.startTime?new Date(t.startTime):void 0,endTime:t.endTime?new Date(t.endTime):void 0},{groupBy:t.groupBy,sort:t.sort,toolSort:t.toolSort,limit:t.limit,toolLimit:t.toolLimit,period:t.period,bucket:t.bucket});return e.json(n)}catch(t){return console.error(`Failed to get metrics:`,t),e.json({error:`Failed to get metrics`,message:t instanceof Error?t.message:String(t)},500)}}),n}function ee(e){return e.toLocaleString(`en-US`,{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1})}const E=`controls-section`,D=`input-field`,O=`table-container`,k=`log-table`,A=`compact-table`,j=`level-trace`,te=`level-debug`,ne=`level-info`,re=`level-warn`,ie=`level-error`,ae=`level-fatal`,oe=`stats-container`,M=`stat-card`,se=`trace-link`,ce=`timestamp-cell`,le=`service-cell`,ue=`pagination-btn`,de=`log-entry-group`,fe=`metadata-row`,pe=`message-row`,me=`message-full-cell`;function he(e){let t=e.toLowerCase();return t===`trace`?j:t===`debug`?te:t===`info`?ne:t===`warn`?re:t===`error`?ie:t===`fatal`?ae:``}function ge(e){if(!e||typeof e!=`object`)return null;let t=e,n={};for(let[e,r]of Object.entries(t))e!==`trace.id`&&e!==`span.id`&&(n[e]=r);return Object.keys(n).length>0?n:null}function _e({logs:e}){return/* @__PURE__ */ (0,b.jsx)(`div`,{class:O,children:/* @__PURE__ */ (0,b.jsxs)(`table`,{class:k,children:[/* @__PURE__ */ (0,b.jsx)(`thead`,{children:/* @__PURE__ */ (0,b.jsxs)(`tr`,{children:[/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Timestamp`}),/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Level`}),/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Service`}),/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Trace ID`})]})}),e.map(e=>{let t=ge(e.metadata);return/* @__PURE__ */ (0,b.jsxs)(`tbody`,{class:de,children:[/* @__PURE__ */ (0,b.jsxs)(`tr`,{class:fe,children:[/* @__PURE__ */ (0,b.jsx)(`td`,{class:ce,children:ee(e.timestamp)}),/* @__PURE__ */ (0,b.jsx)(`td`,{class:he(e.level),children:e.level.toUpperCase()}),/* @__PURE__ */ (0,b.jsx)(`td`,{class:le,children:e.service}),/* @__PURE__ */ (0,b.jsx)(`td`,{children:e.traceId?/* @__PURE__ */ (0,b.jsxs)(`span`,{class:se,onclick:`dashboard.filterByTrace('${e.traceId}')`,children:[e.traceId.slice(0,8),`...`]}):/* @__PURE__ */ (0,b.jsx)(`span`,{children:`-`})})]}),/* @__PURE__ */ (0,b.jsx)(`tr`,{class:pe,children:/* @__PURE__ */ (0,b.jsxs)(`td`,{colspan:4,class:me,children:[/* @__PURE__ */ (0,b.jsx)(`div`,{children:e.message}),t&&/* @__PURE__ */ (0,b.jsx)(`pre`,{class:`attributes-cell`,children:JSON.stringify(t,null,2)})]})})]},e.id)})]})})}function N(e){return Math.round(e).toLocaleString()}function ve(e){return`${e.toFixed(1)}%`}function ye(e){return e?e.toISOString():`-`}function be({metrics:e}){return/* @__PURE__ */ (0,b.jsxs)(`section`,{class:`metrics-section`,children:[/* @__PURE__ */ (0,b.jsx)(`div`,{class:`section-header`,children:/* @__PURE__ */ (0,b.jsx)(`h2`,{children:`Workflow Metrics`})}),/* @__PURE__ */ (0,b.jsxs)(`div`,{class:E,children:[/* @__PURE__ */ (0,b.jsx)(`input`,{id:`metrics-model-filter`,class:D,type:`text`,placeholder:`Model`}),/* @__PURE__ */ (0,b.jsx)(`input`,{id:`metrics-provider-filter`,class:D,type:`text`,placeholder:`Provider`}),/* @__PURE__ */ (0,b.jsx)(`button`,{type:`button`,class:`btn`,onclick:`dashboard.fetchMetrics()`,children:`Apply Metrics Filters`})]}),/* @__PURE__ */ (0,b.jsxs)(`div`,{id:`metrics-summary`,class:oe,children:[/* @__PURE__ */ (0,b.jsxs)(`div`,{class:M,children:[/* @__PURE__ */ (0,b.jsx)(`h3`,{children:`Workflow Runs`}),/* @__PURE__ */ (0,b.jsx)(`div`,{id:`metrics-group-count`,class:`value`,children:e.totals.groupCount.toLocaleString()})]}),/* @__PURE__ */ (0,b.jsxs)(`div`,{class:M,children:[/* @__PURE__ */ (0,b.jsx)(`h3`,{children:`Failed Runs`}),/* @__PURE__ */ (0,b.jsx)(`div`,{id:`metrics-failed-groups`,class:`value`,children:e.totals.failedGroups.toLocaleString()})]}),/* @__PURE__ */ (0,b.jsxs)(`div`,{class:M,children:[/* @__PURE__ */ (0,b.jsx)(`h3`,{children:`Total Tokens`}),/* @__PURE__ */ (0,b.jsx)(`div`,{id:`metrics-total-tokens`,class:`value`,children:N(e.totals.totalTokens)})]}),/* @__PURE__ */ (0,b.jsxs)(`div`,{class:M,children:[/* @__PURE__ */ (0,b.jsx)(`h3`,{children:`Token Coverage`}),/* @__PURE__ */ (0,b.jsx)(`div`,{id:`metrics-token-coverage`,class:`value`,children:ve(e.totals.tokenCoveragePercent)})]})]}),/* @__PURE__ */ (0,b.jsxs)(`div`,{class:`metrics-grid`,children:[/* @__PURE__ */ (0,b.jsxs)(`div`,{class:O,children:[/* @__PURE__ */ (0,b.jsx)(`h3`,{children:`Top Workflow Runs`}),/* @__PURE__ */ (0,b.jsxs)(`table`,{class:A,children:[/* @__PURE__ */ (0,b.jsx)(`thead`,{children:/* @__PURE__ */ (0,b.jsxs)(`tr`,{children:[/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Workflow`}),/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Last Seen`}),/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Tokens`}),/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Issues`})]})}),/* @__PURE__ */ (0,b.jsx)(`tbody`,{id:`workflow-metrics-body`,children:e.groups.slice(0,10).map(e=>/* @__PURE__ */ (0,b.jsxs)(`tr`,{children:[/* @__PURE__ */ (0,b.jsx)(`td`,{children:e.key}),/* @__PURE__ */ (0,b.jsx)(`td`,{children:ye(e.lastSeen)}),/* @__PURE__ */ (0,b.jsx)(`td`,{children:N(e.totalTokens)}),/* @__PURE__ */ (0,b.jsx)(`td`,{children:e.issueCount.toLocaleString()})]}))})]})]}),/* @__PURE__ */ (0,b.jsxs)(`div`,{class:O,children:[/* @__PURE__ */ (0,b.jsx)(`h3`,{children:`Top Tools By Token Use`}),/* @__PURE__ */ (0,b.jsxs)(`table`,{class:A,children:[/* @__PURE__ */ (0,b.jsx)(`thead`,{children:/* @__PURE__ */ (0,b.jsxs)(`tr`,{children:[/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Tool`}),/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Invocations`}),/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Call p90`}),/* @__PURE__ */ (0,b.jsx)(`th`,{children:`Output p90`})]})}),/* @__PURE__ */ (0,b.jsx)(`tbody`,{id:`tool-metrics-body`,children:e.tools.rows.slice(0,10).map(e=>/* @__PURE__ */ (0,b.jsxs)(`tr`,{children:[/* @__PURE__ */ (0,b.jsx)(`td`,{children:e.toolName}),/* @__PURE__ */ (0,b.jsx)(`td`,{children:e.invocationCount.toLocaleString()}),/* @__PURE__ */ (0,b.jsx)(`td`,{children:N(e.toolCallTurn.p90TotalTokens)}),/* @__PURE__ */ (0,b.jsx)(`td`,{children:N(e.toolOutputImpact.p90TotalTokens)})]}))})]})]})]})]})}function xe(){return/* @__PURE__ */ (0,b.jsx)(`input`,{id:`search-input`,type:`text`,class:D,placeholder:`Search logs...`,oninput:`dashboard.handleSearchInput(event)`})}function Se({services:e}){return/* @__PURE__ */ (0,b.jsxs)(`select`,{id:`service-select`,class:`select-field`,onchange:`dashboard.handleServiceChange(event)`,children:[/* @__PURE__ */ (0,b.jsx)(`option`,{value:``,children:`All Services`}),e.map(e=>/* @__PURE__ */ (0,b.jsx)(`option`,{value:e,children:e},e))]})}function Ce({stats:e}){return/* @__PURE__ */ (0,b.jsxs)(`div`,{class:oe,children:[/* @__PURE__ */ (0,b.jsxs)(`div`,{class:M,children:[/* @__PURE__ */ (0,b.jsx)(`h3`,{children:`Total Logs`}),/* @__PURE__ */ (0,b.jsx)(`div`,{class:`value`,children:e.totalLogs.toLocaleString()})]}),/* @__PURE__ */ (0,b.jsxs)(`div`,{class:M,children:[/* @__PURE__ */ (0,b.jsx)(`h3`,{children:`Errors`}),/* @__PURE__ */ (0,b.jsx)(`div`,{class:`value`,children:e.errors.toLocaleString()})]}),/* @__PURE__ */ (0,b.jsxs)(`div`,{class:M,children:[/* @__PURE__ */ (0,b.jsx)(`h3`,{children:`Services`}),/* @__PURE__ */ (0,b.jsx)(`div`,{class:`value`,children:e.services})]})]})}function we({initialLogs:e,services:t,stats:n,metrics:r}){return/* @__PURE__ */ (0,b.jsxs)(`div`,{class:`dashboard-container`,children:[/* @__PURE__ */ (0,b.jsxs)(`div`,{class:`dashboard-header`,children:[/* @__PURE__ */ (0,b.jsx)(`h1`,{children:`Log Dashboard`}),/* @__PURE__ */ (0,b.jsx)(`p`,{children:`Real-time log streaming with auto-refresh (3 seconds)`})]}),/* @__PURE__ */ (0,b.jsx)(Ce,{stats:n}),/* @__PURE__ */ (0,b.jsx)(be,{metrics:r}),/* @__PURE__ */ (0,b.jsxs)(`div`,{class:E,children:[/* @__PURE__ */ (0,b.jsx)(xe,{}),/* @__PURE__ */ (0,b.jsx)(Se,{services:t}),/* @__PURE__ */ (0,b.jsx)(`button`,{type:`button`,id:`refresh-btn`,class:`btn`,onclick:`dashboard.manualRefresh()`,children:`Refresh Now`})]}),/* @__PURE__ */ (0,b.jsx)(_e,{logs:e}),/* @__PURE__ */ (0,b.jsxs)(`div`,{id:`pagination-controls`,class:`pagination-container`,children:[/* @__PURE__ */ (0,b.jsx)(`button`,{type:`button`,id:`prev-btn`,class:ue,onclick:`dashboard.prevPage()`,disabled:!0,children:`Previous`}),/* @__PURE__ */ (0,b.jsx)(`span`,{id:`page-info`,class:`page-info`,children:`Page 1`}),/* @__PURE__ */ (0,b.jsx)(`button`,{type:`button`,id:`next-btn`,class:ue,onclick:`dashboard.nextPage()`,children:`Next`})]}),/* @__PURE__ */ (0,b.jsx)(`script`,{children:(0,y.raw)(`
3
3
  class DashboardManager {
4
4
  constructor() {
5
5
  this.filters = {
package/dist/cli.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- import{a as e,d as t,o as n,s as r}from"./LogStorageService-Dl45MerD.mjs";import{i,n as a,r as o,t as s}from"./container-BmHquIFU.mjs";import{i as c,n as l,r as u}from"./logSinkConfig-Bh_Mlqvc.mjs";import{d}from"./node-CFzq1tsu.mjs";import{a as f,c as p,i as m,n as h,o as g,r as _,s as ee,t as v}from"./stdio-BRiHn_FV.mjs";import{z as y}from"zod";import*as b from"node:fs/promises";import{readFile as x}from"node:fs/promises";import te,{dirname as ne,join as re}from"node:path";import{execFile as S}from"node:child_process";import{promisify as ie}from"node:util";import{fileURLToPath as C}from"node:url";import{DEFAULT_PORT_RANGE as w,PortRegistryService as ae}from"@agimon-ai/foundation-port-registry";import{createProcessLease as T,createProcessRegistryService as oe,resolveSiblingRegistryPath as se}from"@agimon-ai/foundation-process-registry";import{Command as E,InvalidArgumentError as D}from"commander";import{serve as ce}from"@hono/node-server";import{createHash as le}from"node:crypto";import{Hono as ue}from"hono";import{rateLimiter as de}from"hono-rate-limiter";import{cors as fe}from"hono/cors";import{raw as pe}from"hono/html";import{jsx as O,jsxs as k}from"hono/jsx/jsx-runtime";var me=`0.0.1-alpha.76`;const he=y.object({service:y.string().optional(),level:y.string().optional(),traceId:y.string().optional(),search:y.string().optional(),limit:y.coerce.number().min(1).max(1e3).default(25),offset:y.coerce.number().min(0).default(0)}),ge=y.object({groupBy:y.enum([`session`,`workflow-run`,`workflow-name`,`job`,`step`,`agent`,`model`,`provider`]).optional(),startTime:y.string().optional(),endTime:y.string().optional(),period:y.enum([`day`,`week`,`month`,`all`]).optional(),bucket:y.enum([`hour`,`day`,`week`,`month`]).optional(),sessionId:y.string().optional(),workflowRunId:y.string().optional(),workflowName:y.string().optional(),jobName:y.string().optional(),stepName:y.string().optional(),agentName:y.string().optional(),service:y.array(y.string()).optional(),model:y.array(y.string()).optional(),provider:y.array(y.string()).optional(),limit:y.coerce.number().min(1).max(500).optional(),sort:y.enum([`last-seen`,`total-tokens`,`issues`]).optional(),toolLimit:y.coerce.number().min(1).max(500).optional(),toolSort:y.enum([`p90-total-tokens`,`avg-total-tokens`,`invocations`]).optional()});function A(e,t){let n=e.req.queries(t)??[],r=e.req.query(t),i=(n.length>0?n:r?[r]:[]).flatMap(e=>e.split(`,`)).map(e=>e.trim()).filter(e=>e.length>0);return i.length>0?i:void 0}function _e(e){let n=new ue,r=e.get(t.LogQueryService),i=e.get(t.LogSearchService),a=e.get(t.LogMetricsService);return n.get(`/logs`,async e=>{try{let{service:t,level:n,traceId:a,search:o,limit:s,offset:c}=he.parse({service:e.req.query(`service`),level:e.req.query(`level`),traceId:e.req.query(`traceId`),search:e.req.query(`search`),limit:e.req.query(`limit`),offset:e.req.query(`offset`)}),l,u=0;if(o){let e={};t&&(e.service=t),n&&(e.level=n);let r=await i.searchLogsPaginated(o,{...e,offset:c},s);l=r.results,u=r.total}else{let e=n?n.split(`,`):[`info`,`warn`,`error`,`fatal`],i=await r.queryLogs({level:e,service:t||void 0,traceId:a||void 0,limit:s,offset:c});l=i.logs,u=i.total}return e.json({logs:l,total:u,hasMore:c+s<u})}catch(t){return console.error(`Failed to query logs:`,t),e.json({error:`Failed to query logs`,message:t instanceof Error?t.message:String(t)},500)}}),n.get(`/services`,async e=>{try{let t=await r.getActiveServices();return e.json({services:t,total:t.length})}catch(t){return console.error(`Failed to get services:`,t),e.json({error:`Failed to get services`,message:t instanceof Error?t.message:String(t)},500)}}),n.get(`/stats`,async e=>{try{let t=await r.getStatistics(),n=t.reduce((e,t)=>e+t.count,0),i=t.filter(e=>e.level===`error`||e.level===`fatal`).reduce((e,t)=>e+t.count,0),a=new Set(t.map(e=>e.service)).size;return e.json({totalLogs:n,errors:i,services:a,breakdown:t})}catch(t){return console.error(`Failed to get statistics:`,t),e.json({error:`Failed to get statistics`,message:t instanceof Error?t.message:String(t)},500)}}),n.get(`/metrics`,async e=>{try{let t=ge.parse({groupBy:e.req.query(`groupBy`),startTime:e.req.query(`startTime`),endTime:e.req.query(`endTime`),period:e.req.query(`period`),bucket:e.req.query(`bucket`),sessionId:e.req.query(`sessionId`),workflowRunId:e.req.query(`workflowRunId`),workflowName:e.req.query(`workflowName`),jobName:e.req.query(`jobName`),stepName:e.req.query(`stepName`),agentName:e.req.query(`agentName`),service:A(e,`service`),model:A(e,`model`),provider:A(e,`provider`),limit:e.req.query(`limit`),sort:e.req.query(`sort`),toolLimit:e.req.query(`toolLimit`),toolSort:e.req.query(`toolSort`)}),n=await a.getMetrics({sessionId:t.sessionId,workflowRunId:t.workflowRunId,workflowName:t.workflowName,jobName:t.jobName,stepName:t.stepName,agentName:t.agentName,service:t.service,model:t.model,provider:t.provider,startTime:t.startTime?new Date(t.startTime):void 0,endTime:t.endTime?new Date(t.endTime):void 0},{groupBy:t.groupBy,sort:t.sort,toolSort:t.toolSort,limit:t.limit,toolLimit:t.toolLimit,period:t.period,bucket:t.bucket});return e.json(n)}catch(t){return console.error(`Failed to get metrics:`,t),e.json({error:`Failed to get metrics`,message:t instanceof Error?t.message:String(t)},500)}}),n}function ve(e){return e.toLocaleString(`en-US`,{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1})}const ye=`controls-section`,j=`input-field`,M=`table-container`,be=`log-table`,xe=`compact-table`,Se=`level-trace`,Ce=`level-debug`,we=`level-info`,Te=`level-warn`,Ee=`level-error`,De=`level-fatal`,Oe=`stats-container`,N=`stat-card`,ke=`trace-link`,Ae=`timestamp-cell`,je=`service-cell`,Me=`pagination-btn`,Ne=`log-entry-group`,Pe=`metadata-row`,Fe=`message-row`,Ie=`message-full-cell`;function Le(e){let t=e.toLowerCase();return t===`trace`?Se:t===`debug`?Ce:t===`info`?we:t===`warn`?Te:t===`error`?Ee:t===`fatal`?De:``}function Re(e){if(!e||typeof e!=`object`)return null;let t=e,n={};for(let[e,r]of Object.entries(t))e!==`trace.id`&&e!==`span.id`&&(n[e]=r);return Object.keys(n).length>0?n:null}function ze({logs:e}){return/* @__PURE__ */ O(`div`,{class:M,children:/* @__PURE__ */ k(`table`,{class:be,children:[/* @__PURE__ */ O(`thead`,{children:/* @__PURE__ */ k(`tr`,{children:[/* @__PURE__ */ O(`th`,{children:`Timestamp`}),/* @__PURE__ */ O(`th`,{children:`Level`}),/* @__PURE__ */ O(`th`,{children:`Service`}),/* @__PURE__ */ O(`th`,{children:`Trace ID`})]})}),e.map(e=>{let t=Re(e.metadata);return/* @__PURE__ */ k(`tbody`,{class:Ne,children:[/* @__PURE__ */ k(`tr`,{class:Pe,children:[/* @__PURE__ */ O(`td`,{class:Ae,children:ve(e.timestamp)}),/* @__PURE__ */ O(`td`,{class:Le(e.level),children:e.level.toUpperCase()}),/* @__PURE__ */ O(`td`,{class:je,children:e.service}),/* @__PURE__ */ O(`td`,{children:e.traceId?/* @__PURE__ */ k(`span`,{class:ke,onclick:`dashboard.filterByTrace('${e.traceId}')`,children:[e.traceId.slice(0,8),`...`]}):/* @__PURE__ */ O(`span`,{children:`-`})})]}),/* @__PURE__ */ O(`tr`,{class:Fe,children:/* @__PURE__ */ k(`td`,{colspan:4,class:Ie,children:[/* @__PURE__ */ O(`div`,{children:e.message}),t&&/* @__PURE__ */ O(`pre`,{class:`attributes-cell`,children:JSON.stringify(t,null,2)})]})})]},e.id)})]})})}function P(e){return Math.round(e).toLocaleString()}function Be(e){return`${e.toFixed(1)}%`}function Ve(e){return e?e.toISOString():`-`}function He({metrics:e}){return/* @__PURE__ */ k(`section`,{class:`metrics-section`,children:[/* @__PURE__ */ O(`div`,{class:`section-header`,children:/* @__PURE__ */ O(`h2`,{children:`Workflow Metrics`})}),/* @__PURE__ */ k(`div`,{class:ye,children:[/* @__PURE__ */ O(`input`,{id:`metrics-model-filter`,class:j,type:`text`,placeholder:`Model`}),/* @__PURE__ */ O(`input`,{id:`metrics-provider-filter`,class:j,type:`text`,placeholder:`Provider`}),/* @__PURE__ */ O(`button`,{type:`button`,class:`btn`,onclick:`dashboard.fetchMetrics()`,children:`Apply Metrics Filters`})]}),/* @__PURE__ */ k(`div`,{id:`metrics-summary`,class:Oe,children:[/* @__PURE__ */ k(`div`,{class:N,children:[/* @__PURE__ */ O(`h3`,{children:`Workflow Runs`}),/* @__PURE__ */ O(`div`,{id:`metrics-group-count`,class:`value`,children:e.totals.groupCount.toLocaleString()})]}),/* @__PURE__ */ k(`div`,{class:N,children:[/* @__PURE__ */ O(`h3`,{children:`Failed Runs`}),/* @__PURE__ */ O(`div`,{id:`metrics-failed-groups`,class:`value`,children:e.totals.failedGroups.toLocaleString()})]}),/* @__PURE__ */ k(`div`,{class:N,children:[/* @__PURE__ */ O(`h3`,{children:`Total Tokens`}),/* @__PURE__ */ O(`div`,{id:`metrics-total-tokens`,class:`value`,children:P(e.totals.totalTokens)})]}),/* @__PURE__ */ k(`div`,{class:N,children:[/* @__PURE__ */ O(`h3`,{children:`Token Coverage`}),/* @__PURE__ */ O(`div`,{id:`metrics-token-coverage`,class:`value`,children:Be(e.totals.tokenCoveragePercent)})]})]}),/* @__PURE__ */ k(`div`,{class:`metrics-grid`,children:[/* @__PURE__ */ k(`div`,{class:M,children:[/* @__PURE__ */ O(`h3`,{children:`Top Workflow Runs`}),/* @__PURE__ */ k(`table`,{class:xe,children:[/* @__PURE__ */ O(`thead`,{children:/* @__PURE__ */ k(`tr`,{children:[/* @__PURE__ */ O(`th`,{children:`Workflow`}),/* @__PURE__ */ O(`th`,{children:`Last Seen`}),/* @__PURE__ */ O(`th`,{children:`Tokens`}),/* @__PURE__ */ O(`th`,{children:`Issues`})]})}),/* @__PURE__ */ O(`tbody`,{id:`workflow-metrics-body`,children:e.groups.slice(0,10).map(e=>/* @__PURE__ */ k(`tr`,{children:[/* @__PURE__ */ O(`td`,{children:e.key}),/* @__PURE__ */ O(`td`,{children:Ve(e.lastSeen)}),/* @__PURE__ */ O(`td`,{children:P(e.totalTokens)}),/* @__PURE__ */ O(`td`,{children:e.issueCount.toLocaleString()})]}))})]})]}),/* @__PURE__ */ k(`div`,{class:M,children:[/* @__PURE__ */ O(`h3`,{children:`Top Tools By Token Use`}),/* @__PURE__ */ k(`table`,{class:xe,children:[/* @__PURE__ */ O(`thead`,{children:/* @__PURE__ */ k(`tr`,{children:[/* @__PURE__ */ O(`th`,{children:`Tool`}),/* @__PURE__ */ O(`th`,{children:`Invocations`}),/* @__PURE__ */ O(`th`,{children:`Call p90`}),/* @__PURE__ */ O(`th`,{children:`Output p90`})]})}),/* @__PURE__ */ O(`tbody`,{id:`tool-metrics-body`,children:e.tools.rows.slice(0,10).map(e=>/* @__PURE__ */ k(`tr`,{children:[/* @__PURE__ */ O(`td`,{children:e.toolName}),/* @__PURE__ */ O(`td`,{children:e.invocationCount.toLocaleString()}),/* @__PURE__ */ O(`td`,{children:P(e.toolCallTurn.p90TotalTokens)}),/* @__PURE__ */ O(`td`,{children:P(e.toolOutputImpact.p90TotalTokens)})]}))})]})]})]})]})}function Ue(){return/* @__PURE__ */ O(`input`,{id:`search-input`,type:`text`,class:j,placeholder:`Search logs...`,oninput:`dashboard.handleSearchInput(event)`})}function We({services:e}){return/* @__PURE__ */ k(`select`,{id:`service-select`,class:`select-field`,onchange:`dashboard.handleServiceChange(event)`,children:[/* @__PURE__ */ O(`option`,{value:``,children:`All Services`}),e.map(e=>/* @__PURE__ */ O(`option`,{value:e,children:e},e))]})}function Ge({stats:e}){return/* @__PURE__ */ k(`div`,{class:Oe,children:[/* @__PURE__ */ k(`div`,{class:N,children:[/* @__PURE__ */ O(`h3`,{children:`Total Logs`}),/* @__PURE__ */ O(`div`,{class:`value`,children:e.totalLogs.toLocaleString()})]}),/* @__PURE__ */ k(`div`,{class:N,children:[/* @__PURE__ */ O(`h3`,{children:`Errors`}),/* @__PURE__ */ O(`div`,{class:`value`,children:e.errors.toLocaleString()})]}),/* @__PURE__ */ k(`div`,{class:N,children:[/* @__PURE__ */ O(`h3`,{children:`Services`}),/* @__PURE__ */ O(`div`,{class:`value`,children:e.services})]})]})}function Ke({initialLogs:e,services:t,stats:n,metrics:r}){return/* @__PURE__ */ k(`div`,{class:`dashboard-container`,children:[/* @__PURE__ */ k(`div`,{class:`dashboard-header`,children:[/* @__PURE__ */ O(`h1`,{children:`Log Dashboard`}),/* @__PURE__ */ O(`p`,{children:`Real-time log streaming with auto-refresh (3 seconds)`})]}),/* @__PURE__ */ O(Ge,{stats:n}),/* @__PURE__ */ O(He,{metrics:r}),/* @__PURE__ */ k(`div`,{class:ye,children:[/* @__PURE__ */ O(Ue,{}),/* @__PURE__ */ O(We,{services:t}),/* @__PURE__ */ O(`button`,{type:`button`,id:`refresh-btn`,class:`btn`,onclick:`dashboard.manualRefresh()`,children:`Refresh Now`})]}),/* @__PURE__ */ O(ze,{logs:e}),/* @__PURE__ */ k(`div`,{id:`pagination-controls`,class:`pagination-container`,children:[/* @__PURE__ */ O(`button`,{type:`button`,id:`prev-btn`,class:Me,onclick:`dashboard.prevPage()`,disabled:!0,children:`Previous`}),/* @__PURE__ */ O(`span`,{id:`page-info`,class:`page-info`,children:`Page 1`}),/* @__PURE__ */ O(`button`,{type:`button`,id:`next-btn`,class:Me,onclick:`dashboard.nextPage()`,children:`Next`})]}),/* @__PURE__ */ O(`script`,{children:pe(`
2
+ import{a as e,d as t,o as n,s as r}from"./LogStorageService-Dl45MerD.mjs";import{i,n as a,r as o,t as s}from"./container-BmHquIFU.mjs";import{i as c,n as l,r as u}from"./logSinkConfig-Bh_Mlqvc.mjs";import{d}from"./node-CFzq1tsu.mjs";import{a as f,c as p,i as m,n as h,o as g,r as _,s as ee,t as v}from"./stdio-BRiHn_FV.mjs";import{z as y}from"zod";import*as b from"node:fs/promises";import{readFile as x}from"node:fs/promises";import te,{dirname as ne,join as re}from"node:path";import{execFile as S}from"node:child_process";import{promisify as ie}from"node:util";import{fileURLToPath as C}from"node:url";import{DEFAULT_PORT_RANGE as w,PortRegistryService as ae}from"@agimon-ai/foundation-port-registry";import{createProcessLease as T,createProcessRegistryService as oe,resolveSiblingRegistryPath as se}from"@agimon-ai/foundation-process-registry";import{Command as E,InvalidArgumentError as D}from"commander";import{serve as ce}from"@hono/node-server";import{createHash as le}from"node:crypto";import{Hono as ue}from"hono";import{rateLimiter as de}from"hono-rate-limiter";import{cors as fe}from"hono/cors";import{raw as pe}from"hono/html";import{jsx as O,jsxs as k}from"hono/jsx/jsx-runtime";var me=`0.0.1-alpha.78`;const he=y.object({service:y.string().optional(),level:y.string().optional(),traceId:y.string().optional(),search:y.string().optional(),limit:y.coerce.number().min(1).max(1e3).default(25),offset:y.coerce.number().min(0).default(0)}),ge=y.object({groupBy:y.enum([`session`,`workflow-run`,`workflow-name`,`job`,`step`,`agent`,`model`,`provider`]).optional(),startTime:y.string().optional(),endTime:y.string().optional(),period:y.enum([`day`,`week`,`month`,`all`]).optional(),bucket:y.enum([`hour`,`day`,`week`,`month`]).optional(),sessionId:y.string().optional(),workflowRunId:y.string().optional(),workflowName:y.string().optional(),jobName:y.string().optional(),stepName:y.string().optional(),agentName:y.string().optional(),service:y.array(y.string()).optional(),model:y.array(y.string()).optional(),provider:y.array(y.string()).optional(),limit:y.coerce.number().min(1).max(500).optional(),sort:y.enum([`last-seen`,`total-tokens`,`issues`]).optional(),toolLimit:y.coerce.number().min(1).max(500).optional(),toolSort:y.enum([`p90-total-tokens`,`avg-total-tokens`,`invocations`]).optional()});function A(e,t){let n=e.req.queries(t)??[],r=e.req.query(t),i=(n.length>0?n:r?[r]:[]).flatMap(e=>e.split(`,`)).map(e=>e.trim()).filter(e=>e.length>0);return i.length>0?i:void 0}function _e(e){let n=new ue,r=e.get(t.LogQueryService),i=e.get(t.LogSearchService),a=e.get(t.LogMetricsService);return n.get(`/logs`,async e=>{try{let{service:t,level:n,traceId:a,search:o,limit:s,offset:c}=he.parse({service:e.req.query(`service`),level:e.req.query(`level`),traceId:e.req.query(`traceId`),search:e.req.query(`search`),limit:e.req.query(`limit`),offset:e.req.query(`offset`)}),l,u=0;if(o){let e={};t&&(e.service=t),n&&(e.level=n);let r=await i.searchLogsPaginated(o,{...e,offset:c},s);l=r.results,u=r.total}else{let e=n?n.split(`,`):[`info`,`warn`,`error`,`fatal`],i=await r.queryLogs({level:e,service:t||void 0,traceId:a||void 0,limit:s,offset:c});l=i.logs,u=i.total}return e.json({logs:l,total:u,hasMore:c+s<u})}catch(t){return console.error(`Failed to query logs:`,t),e.json({error:`Failed to query logs`,message:t instanceof Error?t.message:String(t)},500)}}),n.get(`/services`,async e=>{try{let t=await r.getActiveServices();return e.json({services:t,total:t.length})}catch(t){return console.error(`Failed to get services:`,t),e.json({error:`Failed to get services`,message:t instanceof Error?t.message:String(t)},500)}}),n.get(`/stats`,async e=>{try{let t=await r.getStatistics(),n=t.reduce((e,t)=>e+t.count,0),i=t.filter(e=>e.level===`error`||e.level===`fatal`).reduce((e,t)=>e+t.count,0),a=new Set(t.map(e=>e.service)).size;return e.json({totalLogs:n,errors:i,services:a,breakdown:t})}catch(t){return console.error(`Failed to get statistics:`,t),e.json({error:`Failed to get statistics`,message:t instanceof Error?t.message:String(t)},500)}}),n.get(`/metrics`,async e=>{try{let t=ge.parse({groupBy:e.req.query(`groupBy`),startTime:e.req.query(`startTime`),endTime:e.req.query(`endTime`),period:e.req.query(`period`),bucket:e.req.query(`bucket`),sessionId:e.req.query(`sessionId`),workflowRunId:e.req.query(`workflowRunId`),workflowName:e.req.query(`workflowName`),jobName:e.req.query(`jobName`),stepName:e.req.query(`stepName`),agentName:e.req.query(`agentName`),service:A(e,`service`),model:A(e,`model`),provider:A(e,`provider`),limit:e.req.query(`limit`),sort:e.req.query(`sort`),toolLimit:e.req.query(`toolLimit`),toolSort:e.req.query(`toolSort`)}),n=await a.getMetrics({sessionId:t.sessionId,workflowRunId:t.workflowRunId,workflowName:t.workflowName,jobName:t.jobName,stepName:t.stepName,agentName:t.agentName,service:t.service,model:t.model,provider:t.provider,startTime:t.startTime?new Date(t.startTime):void 0,endTime:t.endTime?new Date(t.endTime):void 0},{groupBy:t.groupBy,sort:t.sort,toolSort:t.toolSort,limit:t.limit,toolLimit:t.toolLimit,period:t.period,bucket:t.bucket});return e.json(n)}catch(t){return console.error(`Failed to get metrics:`,t),e.json({error:`Failed to get metrics`,message:t instanceof Error?t.message:String(t)},500)}}),n}function ve(e){return e.toLocaleString(`en-US`,{year:`numeric`,month:`2-digit`,day:`2-digit`,hour:`2-digit`,minute:`2-digit`,second:`2-digit`,hour12:!1})}const ye=`controls-section`,j=`input-field`,M=`table-container`,be=`log-table`,xe=`compact-table`,Se=`level-trace`,Ce=`level-debug`,we=`level-info`,Te=`level-warn`,Ee=`level-error`,De=`level-fatal`,Oe=`stats-container`,N=`stat-card`,ke=`trace-link`,Ae=`timestamp-cell`,je=`service-cell`,Me=`pagination-btn`,Ne=`log-entry-group`,Pe=`metadata-row`,Fe=`message-row`,Ie=`message-full-cell`;function Le(e){let t=e.toLowerCase();return t===`trace`?Se:t===`debug`?Ce:t===`info`?we:t===`warn`?Te:t===`error`?Ee:t===`fatal`?De:``}function Re(e){if(!e||typeof e!=`object`)return null;let t=e,n={};for(let[e,r]of Object.entries(t))e!==`trace.id`&&e!==`span.id`&&(n[e]=r);return Object.keys(n).length>0?n:null}function ze({logs:e}){return/* @__PURE__ */ O(`div`,{class:M,children:/* @__PURE__ */ k(`table`,{class:be,children:[/* @__PURE__ */ O(`thead`,{children:/* @__PURE__ */ k(`tr`,{children:[/* @__PURE__ */ O(`th`,{children:`Timestamp`}),/* @__PURE__ */ O(`th`,{children:`Level`}),/* @__PURE__ */ O(`th`,{children:`Service`}),/* @__PURE__ */ O(`th`,{children:`Trace ID`})]})}),e.map(e=>{let t=Re(e.metadata);return/* @__PURE__ */ k(`tbody`,{class:Ne,children:[/* @__PURE__ */ k(`tr`,{class:Pe,children:[/* @__PURE__ */ O(`td`,{class:Ae,children:ve(e.timestamp)}),/* @__PURE__ */ O(`td`,{class:Le(e.level),children:e.level.toUpperCase()}),/* @__PURE__ */ O(`td`,{class:je,children:e.service}),/* @__PURE__ */ O(`td`,{children:e.traceId?/* @__PURE__ */ k(`span`,{class:ke,onclick:`dashboard.filterByTrace('${e.traceId}')`,children:[e.traceId.slice(0,8),`...`]}):/* @__PURE__ */ O(`span`,{children:`-`})})]}),/* @__PURE__ */ O(`tr`,{class:Fe,children:/* @__PURE__ */ k(`td`,{colspan:4,class:Ie,children:[/* @__PURE__ */ O(`div`,{children:e.message}),t&&/* @__PURE__ */ O(`pre`,{class:`attributes-cell`,children:JSON.stringify(t,null,2)})]})})]},e.id)})]})})}function P(e){return Math.round(e).toLocaleString()}function Be(e){return`${e.toFixed(1)}%`}function Ve(e){return e?e.toISOString():`-`}function He({metrics:e}){return/* @__PURE__ */ k(`section`,{class:`metrics-section`,children:[/* @__PURE__ */ O(`div`,{class:`section-header`,children:/* @__PURE__ */ O(`h2`,{children:`Workflow Metrics`})}),/* @__PURE__ */ k(`div`,{class:ye,children:[/* @__PURE__ */ O(`input`,{id:`metrics-model-filter`,class:j,type:`text`,placeholder:`Model`}),/* @__PURE__ */ O(`input`,{id:`metrics-provider-filter`,class:j,type:`text`,placeholder:`Provider`}),/* @__PURE__ */ O(`button`,{type:`button`,class:`btn`,onclick:`dashboard.fetchMetrics()`,children:`Apply Metrics Filters`})]}),/* @__PURE__ */ k(`div`,{id:`metrics-summary`,class:Oe,children:[/* @__PURE__ */ k(`div`,{class:N,children:[/* @__PURE__ */ O(`h3`,{children:`Workflow Runs`}),/* @__PURE__ */ O(`div`,{id:`metrics-group-count`,class:`value`,children:e.totals.groupCount.toLocaleString()})]}),/* @__PURE__ */ k(`div`,{class:N,children:[/* @__PURE__ */ O(`h3`,{children:`Failed Runs`}),/* @__PURE__ */ O(`div`,{id:`metrics-failed-groups`,class:`value`,children:e.totals.failedGroups.toLocaleString()})]}),/* @__PURE__ */ k(`div`,{class:N,children:[/* @__PURE__ */ O(`h3`,{children:`Total Tokens`}),/* @__PURE__ */ O(`div`,{id:`metrics-total-tokens`,class:`value`,children:P(e.totals.totalTokens)})]}),/* @__PURE__ */ k(`div`,{class:N,children:[/* @__PURE__ */ O(`h3`,{children:`Token Coverage`}),/* @__PURE__ */ O(`div`,{id:`metrics-token-coverage`,class:`value`,children:Be(e.totals.tokenCoveragePercent)})]})]}),/* @__PURE__ */ k(`div`,{class:`metrics-grid`,children:[/* @__PURE__ */ k(`div`,{class:M,children:[/* @__PURE__ */ O(`h3`,{children:`Top Workflow Runs`}),/* @__PURE__ */ k(`table`,{class:xe,children:[/* @__PURE__ */ O(`thead`,{children:/* @__PURE__ */ k(`tr`,{children:[/* @__PURE__ */ O(`th`,{children:`Workflow`}),/* @__PURE__ */ O(`th`,{children:`Last Seen`}),/* @__PURE__ */ O(`th`,{children:`Tokens`}),/* @__PURE__ */ O(`th`,{children:`Issues`})]})}),/* @__PURE__ */ O(`tbody`,{id:`workflow-metrics-body`,children:e.groups.slice(0,10).map(e=>/* @__PURE__ */ k(`tr`,{children:[/* @__PURE__ */ O(`td`,{children:e.key}),/* @__PURE__ */ O(`td`,{children:Ve(e.lastSeen)}),/* @__PURE__ */ O(`td`,{children:P(e.totalTokens)}),/* @__PURE__ */ O(`td`,{children:e.issueCount.toLocaleString()})]}))})]})]}),/* @__PURE__ */ k(`div`,{class:M,children:[/* @__PURE__ */ O(`h3`,{children:`Top Tools By Token Use`}),/* @__PURE__ */ k(`table`,{class:xe,children:[/* @__PURE__ */ O(`thead`,{children:/* @__PURE__ */ k(`tr`,{children:[/* @__PURE__ */ O(`th`,{children:`Tool`}),/* @__PURE__ */ O(`th`,{children:`Invocations`}),/* @__PURE__ */ O(`th`,{children:`Call p90`}),/* @__PURE__ */ O(`th`,{children:`Output p90`})]})}),/* @__PURE__ */ O(`tbody`,{id:`tool-metrics-body`,children:e.tools.rows.slice(0,10).map(e=>/* @__PURE__ */ k(`tr`,{children:[/* @__PURE__ */ O(`td`,{children:e.toolName}),/* @__PURE__ */ O(`td`,{children:e.invocationCount.toLocaleString()}),/* @__PURE__ */ O(`td`,{children:P(e.toolCallTurn.p90TotalTokens)}),/* @__PURE__ */ O(`td`,{children:P(e.toolOutputImpact.p90TotalTokens)})]}))})]})]})]})]})}function Ue(){return/* @__PURE__ */ O(`input`,{id:`search-input`,type:`text`,class:j,placeholder:`Search logs...`,oninput:`dashboard.handleSearchInput(event)`})}function We({services:e}){return/* @__PURE__ */ k(`select`,{id:`service-select`,class:`select-field`,onchange:`dashboard.handleServiceChange(event)`,children:[/* @__PURE__ */ O(`option`,{value:``,children:`All Services`}),e.map(e=>/* @__PURE__ */ O(`option`,{value:e,children:e},e))]})}function Ge({stats:e}){return/* @__PURE__ */ k(`div`,{class:Oe,children:[/* @__PURE__ */ k(`div`,{class:N,children:[/* @__PURE__ */ O(`h3`,{children:`Total Logs`}),/* @__PURE__ */ O(`div`,{class:`value`,children:e.totalLogs.toLocaleString()})]}),/* @__PURE__ */ k(`div`,{class:N,children:[/* @__PURE__ */ O(`h3`,{children:`Errors`}),/* @__PURE__ */ O(`div`,{class:`value`,children:e.errors.toLocaleString()})]}),/* @__PURE__ */ k(`div`,{class:N,children:[/* @__PURE__ */ O(`h3`,{children:`Services`}),/* @__PURE__ */ O(`div`,{class:`value`,children:e.services})]})]})}function Ke({initialLogs:e,services:t,stats:n,metrics:r}){return/* @__PURE__ */ k(`div`,{class:`dashboard-container`,children:[/* @__PURE__ */ k(`div`,{class:`dashboard-header`,children:[/* @__PURE__ */ O(`h1`,{children:`Log Dashboard`}),/* @__PURE__ */ O(`p`,{children:`Real-time log streaming with auto-refresh (3 seconds)`})]}),/* @__PURE__ */ O(Ge,{stats:n}),/* @__PURE__ */ O(He,{metrics:r}),/* @__PURE__ */ k(`div`,{class:ye,children:[/* @__PURE__ */ O(Ue,{}),/* @__PURE__ */ O(We,{services:t}),/* @__PURE__ */ O(`button`,{type:`button`,id:`refresh-btn`,class:`btn`,onclick:`dashboard.manualRefresh()`,children:`Refresh Now`})]}),/* @__PURE__ */ O(ze,{logs:e}),/* @__PURE__ */ k(`div`,{id:`pagination-controls`,class:`pagination-container`,children:[/* @__PURE__ */ O(`button`,{type:`button`,id:`prev-btn`,class:Me,onclick:`dashboard.prevPage()`,disabled:!0,children:`Previous`}),/* @__PURE__ */ O(`span`,{id:`page-info`,class:`page-info`,children:`Page 1`}),/* @__PURE__ */ O(`button`,{type:`button`,id:`next-btn`,class:Me,onclick:`dashboard.nextPage()`,children:`Next`})]}),/* @__PURE__ */ O(`script`,{children:pe(`
3
3
  class DashboardManager {
4
4
  constructor() {
5
5
  this.filters = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agimon-ai/po-logsink",
3
- "version": "0.0.1-alpha.76",
3
+ "version": "0.0.1-alpha.78",
4
4
  "description": "Log sink MCP server with HTTP ingestion and AI analysis",
5
5
  "keywords": [
6
6
  "mcp",