@@ -63,6 +63,7 @@ const getCachedAgents = unstable_cache(
6363 . select ( {
6464 publisher_id : schema . agentRun . publisher_id ,
6565 agent_name : schema . agentRun . agent_name ,
66+ weekly_runs : sql < number > `COUNT(*)` ,
6667 weekly_dollars : sql < number > `COALESCE(SUM(${ schema . agentRun . total_credits } ) / 100.0, 0)` ,
6768 } )
6869 . from ( schema . agentRun )
@@ -111,6 +112,7 @@ const getCachedAgents = unstable_cache(
111112 publisher_id : schema . agentRun . publisher_id ,
112113 agent_name : schema . agentRun . agent_name ,
113114 agent_version : schema . agentRun . agent_version ,
115+ weekly_runs : sql < number > `COUNT(*)` ,
114116 weekly_dollars : sql < number > `COALESCE(SUM(${ schema . agentRun . total_credits } ) / 100.0, 0)` ,
115117 } )
116118 . from ( schema . agentRun )
@@ -135,7 +137,10 @@ const getCachedAgents = unstable_cache(
135137 weeklyMetrics . forEach ( ( metric ) => {
136138 if ( metric . publisher_id && metric . agent_name ) {
137139 const key = `${ metric . publisher_id } /${ metric . agent_name } `
138- weeklyMap . set ( key , Number ( metric . weekly_dollars ) )
140+ weeklyMap . set ( key , {
141+ weekly_runs : Number ( metric . weekly_runs ) ,
142+ weekly_dollars : Number ( metric . weekly_dollars ) ,
143+ } )
139144 }
140145 } )
141146
@@ -144,8 +149,13 @@ const getCachedAgents = unstable_cache(
144149 usageMetrics . forEach ( ( metric ) => {
145150 if ( metric . publisher_id && metric . agent_name ) {
146151 const key = `${ metric . publisher_id } /${ metric . agent_name } `
152+ const weeklyData = weeklyMap . get ( key ) || {
153+ weekly_runs : 0 ,
154+ weekly_dollars : 0 ,
155+ }
147156 metricsMap . set ( key , {
148- weekly_dollars : weeklyMap . get ( key ) || 0 ,
157+ weekly_runs : weeklyData . weekly_runs ,
158+ weekly_dollars : weeklyData . weekly_dollars ,
149159 total_dollars : Number ( metric . total_dollars ) ,
150160 total_invocations : Number ( metric . total_invocations ) ,
151161 avg_cost_per_run : Number ( metric . avg_cost_per_run ) ,
@@ -160,7 +170,10 @@ const getCachedAgents = unstable_cache(
160170 perVersionWeeklyMetrics . forEach ( ( metric ) => {
161171 if ( metric . publisher_id && metric . agent_name && metric . agent_version ) {
162172 const key = `${ metric . publisher_id } /${ metric . agent_name } @${ metric . agent_version } `
163- perVersionWeeklyMap . set ( key , Number ( metric . weekly_dollars ) )
173+ perVersionWeeklyMap . set ( key , {
174+ weekly_runs : Number ( metric . weekly_runs ) ,
175+ weekly_dollars : Number ( metric . weekly_dollars ) ,
176+ } )
164177 }
165178 } )
166179
@@ -169,8 +182,13 @@ const getCachedAgents = unstable_cache(
169182 perVersionMetrics . forEach ( ( metric ) => {
170183 if ( metric . publisher_id && metric . agent_name && metric . agent_version ) {
171184 const key = `${ metric . publisher_id } /${ metric . agent_name } @${ metric . agent_version } `
185+ const weeklyData = perVersionWeeklyMap . get ( key ) || {
186+ weekly_runs : 0 ,
187+ weekly_dollars : 0 ,
188+ }
172189 perVersionMetricsMap . set ( key , {
173- weekly_dollars : perVersionWeeklyMap . get ( key ) || 0 ,
190+ weekly_runs : weeklyData . weekly_runs ,
191+ weekly_dollars : weeklyData . weekly_dollars ,
174192 total_dollars : Number ( metric . total_dollars ) ,
175193 total_invocations : Number ( metric . total_invocations ) ,
176194 avg_cost_per_run : Number ( metric . avg_cost_per_run ) ,
@@ -212,6 +230,7 @@ const getCachedAgents = unstable_cache(
212230 ( { agent, agentData, agentName } ) => {
213231 const agentKey = `${ agent . publisher . id } /${ agentName } `
214232 const metrics = metricsMap . get ( agentKey ) || {
233+ weekly_runs : 0 ,
215234 weekly_dollars : 0 ,
216235 total_dollars : 0 ,
217236 total_invocations : 0 ,
@@ -233,6 +252,7 @@ const getCachedAgents = unstable_cache(
233252 created_at : agent . created_at ,
234253 // Aggregated stats across all versions (for agent store)
235254 usage_count : metrics . total_invocations ,
255+ weekly_runs : metrics . weekly_runs ,
236256 weekly_spent : metrics . weekly_dollars ,
237257 total_spent : metrics . total_dollars ,
238258 avg_cost_per_invocation : metrics . avg_cost_per_run ,
0 commit comments