@@ -9,6 +9,7 @@ import * as Host from '../../../core/host/host.js';
99import * as i18n from '../../../core/i18n/i18n.js' ;
1010import * as Platform from '../../../core/platform/platform.js' ;
1111import * as Root from '../../../core/root/root.js' ;
12+ import * as SDK from '../../../core/sdk/sdk.js' ;
1213import * as TimelineUtils from '../../../panels/timeline/utils/utils.js' ;
1314import { html , type TemplateResult } from '../../../ui/lit/lit.js' ;
1415import * as Trace from '../../trace/trace.js' ;
@@ -816,7 +817,7 @@ export class PerformanceAgent extends AiAgent<TimelineUtils.AIContext.AgentFocus
816817 return ;
817818 }
818819
819- const { parsedTrace, insightSet} = focus . data ;
820+ const { parsedTrace, insightSet, traceMetadata } = focus . data ;
820821
821822 this . declareFunction < { insightName : string } , { details : string } > ( 'getInsightDetails' , {
822823 description :
@@ -1033,6 +1034,51 @@ export class PerformanceAgent extends AiAgent<TimelineUtils.AIContext.AgentFocus
10331034 } ,
10341035
10351036 } ) ;
1037+
1038+ const isFresh = TimelineUtils . FreshRecording . Tracker . instance ( ) . recordingIsFresh ( parsedTrace ) ;
1039+ const hasScriptContents = traceMetadata . enhancedTraceVersion && parsedTrace . Scripts . scripts . some ( s => s . content ) ;
1040+
1041+ if ( isFresh || hasScriptContents ) {
1042+ this . declareFunction < { url : string } , { content : string } > ( 'getResourceContent' , {
1043+ description : 'Returns the content of the resource with the given url. Only use this for text resource types.' ,
1044+ parameters : {
1045+ type : Host . AidaClient . ParametersTypes . OBJECT ,
1046+ description : '' ,
1047+ nullable : false ,
1048+ properties : {
1049+ url : {
1050+ type : Host . AidaClient . ParametersTypes . STRING ,
1051+ description : 'The url for the resource.' ,
1052+ nullable : false ,
1053+ } ,
1054+ } ,
1055+ } ,
1056+ displayInfoFromArgs : args => {
1057+ return { title : lockedString ( 'Looking at resource content…' ) , action : `getResourceContent(${ args . url } )` } ;
1058+ } ,
1059+ handler : async args => {
1060+ debugLog ( 'Function call: getResourceContent' ) ;
1061+
1062+ const url = args . url as Platform . DevToolsPath . UrlString ;
1063+ const resource = SDK . ResourceTreeModel . ResourceTreeModel . resourceForURL ( url ) ;
1064+ if ( ! resource ) {
1065+ if ( ! resource ) {
1066+ return { error : 'Resource not found' } ;
1067+ }
1068+ }
1069+
1070+ const content = resource . content ;
1071+ if ( ! content ) {
1072+ return { error : 'Resource has no content' } ;
1073+ }
1074+
1075+ const key = `getResourceContent(${ args . url } )` ;
1076+ this . #cacheFunctionResult( focus , key , content ) ;
1077+ return { result : { content} } ;
1078+ } ,
1079+
1080+ } ) ;
1081+ }
10361082 }
10371083
10381084 #declareFunctions( context : ConversationContext < TimelineUtils . AIContext . AgentFocus > ) : void {
0 commit comments