@@ -17,7 +17,7 @@ import { Button } from "~/components/ui/button";
1717import { Card } from "~/components/ui/card" ;
1818import { LongText } from "~/components/ui/long-text" ;
1919import { Text as UIText } from "~/components/ui/text" ;
20- import { getAuthHeaders } from "~/utils/api" ;
20+ import { getAuthHeaders , queryClient , trpc } from "~/utils/api" ;
2121import { getApiUrl } from "~/utils/base-url" ;
2222import { iconColor } from "~/utils/ui" ;
2323
@@ -243,7 +243,7 @@ function ToolInvocationComponent({
243243 </ Card >
244244 ) ;
245245 case "call" : {
246- const args = toolInvocation . args as
246+ const _args = toolInvocation . args as
247247 | { description ?: string }
248248 | undefined ;
249249 return (
@@ -353,10 +353,40 @@ export default function NewTrackableScreen() {
353353 } ,
354354 ) ;
355355
356+ const processedToolCallIds = useRef ( new Set < string > ( ) ) ;
357+
356358 useEffect ( ( ) => {
357359 if ( scrollViewRef . current ) {
358360 scrollViewRef . current . scrollToEnd ( { animated : true } ) ;
359361 }
362+
363+ const lastMessage = messages [ messages . length - 1 ] ;
364+ if ( lastMessage ) {
365+ for ( const part of lastMessage . parts ) {
366+ if (
367+ part . type === "tool-invocation" &&
368+ part . toolInvocation . toolName === "generateConsumptionTrackables" &&
369+ part . toolInvocation . state === "result" &&
370+ ! processedToolCallIds . current . has ( part . toolInvocation . toolCallId )
371+ ) {
372+ queryClient
373+ . invalidateQueries ( {
374+ queryKey : trpc . trackables . getTrackablesForParentType . queryKey ( {
375+ trackableParentType : "consumption" ,
376+ } ) ,
377+ } )
378+ . then ( ( ) => {
379+ processedToolCallIds . current . add ( part . toolInvocation . toolCallId ) ;
380+ } )
381+ . catch ( ( error : Error ) => {
382+ console . error (
383+ "Failed to invalidate consumption trackables queries:" ,
384+ error ,
385+ ) ;
386+ } ) ;
387+ }
388+ }
389+ }
360390 } , [ messages ] ) ;
361391
362392 const onActualSubmit = ( ) => {
0 commit comments