( metrics: SessionMetrics, )
| 33 | } |
| 34 | |
| 35 | export const computeSessionStats = ( |
| 36 | metrics: SessionMetrics, |
| 37 | ): ComputedSessionStats => { |
| 38 | const { models, tools } = metrics; |
| 39 | const totalApiTime = Object.values(models).reduce( |
| 40 | (acc, model) => acc + model.api.totalLatencyMs, |
| 41 | 0, |
| 42 | ); |
| 43 | const totalToolTime = tools.totalDurationMs; |
| 44 | const agentActiveTime = totalApiTime + totalToolTime; |
| 45 | const apiTimePercent = |
| 46 | agentActiveTime > 0 ? (totalApiTime / agentActiveTime) * 100 : 0; |
| 47 | const toolTimePercent = |
| 48 | agentActiveTime > 0 ? (totalToolTime / agentActiveTime) * 100 : 0; |
| 49 | |
| 50 | const totalCachedTokens = Object.values(models).reduce( |
| 51 | (acc, model) => acc + model.tokens.cached, |
| 52 | 0, |
| 53 | ); |
| 54 | const totalPromptTokens = Object.values(models).reduce( |
| 55 | (acc, model) => acc + model.tokens.prompt, |
| 56 | 0, |
| 57 | ); |
| 58 | const cacheEfficiency = |
| 59 | totalPromptTokens > 0 ? (totalCachedTokens / totalPromptTokens) * 100 : 0; |
| 60 | |
| 61 | const totalDecisions = |
| 62 | tools.totalDecisions.accept + |
| 63 | tools.totalDecisions.reject + |
| 64 | tools.totalDecisions.modify; |
| 65 | const successRate = |
| 66 | tools.totalCalls > 0 ? (tools.totalSuccess / tools.totalCalls) * 100 : 0; |
| 67 | const agreementRate = |
| 68 | totalDecisions > 0 |
| 69 | ? (tools.totalDecisions.accept / totalDecisions) * 100 |
| 70 | : 0; |
| 71 | |
| 72 | return { |
| 73 | totalApiTime, |
| 74 | totalToolTime, |
| 75 | agentActiveTime, |
| 76 | apiTimePercent, |
| 77 | toolTimePercent, |
| 78 | cacheEfficiency, |
| 79 | totalDecisions, |
| 80 | successRate, |
| 81 | agreementRate, |
| 82 | totalCachedTokens, |
| 83 | totalPromptTokens, |
| 84 | }; |
| 85 | }; |
no outgoing calls
no test coverage detected