@@ -47,7 +47,7 @@ export interface BuildStreamTextParamsOptions {
4747 * A function that returns the GitHub auth context for the GitHub tools and for Git authentication inside workspaces.
4848 * If not provided, the GitHub auth context will be created using the app ID and private key from the GitHub config.
4949 */
50- getGithubAppContext ?: ( ) => Promise < github . AppAuthOptions > ;
50+ getGithubAppContext ?: ( ) => Promise < github . AppAuthOptions | undefined > ;
5151}
5252
5353interface Logger {
@@ -264,23 +264,34 @@ export class Scout {
264264 }
265265 }
266266
267- buildStreamTextParams ( {
267+ async buildStreamTextParams ( {
268268 messages,
269269 chatID,
270270 model,
271271 providerOptions,
272272 tools : providedTools ,
273273 getGithubAppContext,
274274 systemPrompt = defaultSystemPrompt ,
275- } : BuildStreamTextParamsOptions ) : {
275+ } : BuildStreamTextParamsOptions ) : Promise < {
276276 model : LanguageModel ;
277277 messages : ModelMessage [ ] ;
278278 maxOutputTokens : number ;
279279 providerOptions ?: ProviderOptions ;
280280 tools : Tools ;
281- } {
281+ } > {
282282 this . printConfigWarnings ( ) ;
283283
284+ // Resolve the GitHub app context once for all tools
285+ const githubAppContext = this . github . config
286+ ? await (
287+ getGithubAppContext ??
288+ githubAppContextFactory ( {
289+ appId : this . github . config . appID ,
290+ privateKey : this . github . config . privateKey ,
291+ } )
292+ ) ( )
293+ : undefined ;
294+
284295 const slackMetadata = getSlackMetadata ( messages ) ;
285296 const respondingInSlack =
286297 this . slack . app !== undefined && slackMetadata !== undefined ;
@@ -291,13 +302,7 @@ export class Scout {
291302 case "docker" : {
292303 computeTools = createComputeTools < DockerWorkspaceInfo > ( {
293304 agent : this . agent ,
294- getGithubAppContext : this . github . config
295- ? ( getGithubAppContext ??
296- githubAppContextFactory ( {
297- appId : this . github . config . appID ,
298- privateKey : this . github . config . privateKey ,
299- } ) )
300- : undefined ,
305+ githubAppContext,
301306 initializeWorkspace : initializeDockerWorkspace ,
302307 createWorkspaceClient : getDockerWorkspaceClient ,
303308 } ) ;
@@ -307,13 +312,7 @@ export class Scout {
307312 const opts = computeConfig . options ;
308313 computeTools = createComputeTools < DaytonaWorkspaceInfo > ( {
309314 agent : this . agent ,
310- getGithubAppContext : this . github . config
311- ? ( getGithubAppContext ??
312- githubAppContextFactory ( {
313- appId : this . github . config . appID ,
314- privateKey : this . github . config . privateKey ,
315- } ) )
316- : undefined ,
315+ githubAppContext,
317316 initializeWorkspace : ( info ) =>
318317 initializeDaytonaWorkspace (
319318 this . logger ,
@@ -363,13 +362,7 @@ export class Scout {
363362 ? createGitHubTools ( {
364363 agent : this . agent ,
365364 chatID,
366- getGithubAppContext :
367- getGithubAppContext !== undefined
368- ? getGithubAppContext
369- : githubAppContextFactory ( {
370- appId : this . github . config . appID ,
371- privateKey : this . github . config . privateKey ,
372- } ) ,
365+ githubAppContext,
373366 } )
374367 : undefined ) ,
375368 ...computeTools ,
0 commit comments