diff --git a/extensions/copilot/src/extension/prompts/node/panel/toolCalling.tsx b/extensions/copilot/src/extension/prompts/node/panel/toolCalling.tsx index 160566dca24..4be8cb9de0f 100644 --- a/extensions/copilot/src/extension/prompts/node/panel/toolCalling.tsx +++ b/extensions/copilot/src/extension/prompts/node/panel/toolCalling.tsx @@ -728,8 +728,8 @@ class PrimitiveToolResult extends PromptEle constructor( props: T, - @IPromptEndpoint protected readonly endpoint: IPromptEndpoint, - @IAuthenticationService private readonly authService: IAuthenticationService, + @IPromptEndpoint protected readonly endpoint?: IPromptEndpoint, + @IAuthenticationService private readonly authService?: IAuthenticationService, @ILogService private readonly logService?: ILogService, @IImageService private readonly imageService?: IImageService, @IConfigurationService private readonly configurationService?: IConfigurationService, @@ -780,7 +780,7 @@ class PrimitiveToolResult extends PromptEle } protected async onImage(part: LanguageModelDataPart, _imageIndex?: number) { - if (!this.endpoint.supportsVision) { + if (!this.endpoint?.supportsVision) { return '[Image content is not available because vision is not supported by the current model or is disabled by your organization.]'; } @@ -789,7 +789,7 @@ class PrimitiveToolResult extends PromptEle : false; // Anthropic (from CAPI) currently does not support image uploads from tool calls. - const canUpload = uploadsEnabled && modelCanUseMcpResultImageURL(this.endpoint); + const canUpload = uploadsEnabled && !!this.endpoint && modelCanUseMcpResultImageURL(this.endpoint); // Enforce image budgets only when images will be inlined as base64. // When uploads are available, the request body stays small (URL reference). @@ -820,10 +820,10 @@ class PrimitiveToolResult extends PromptEle // Only call getGitHubSession when uploads are potentially available let uploadToken: string | undefined; if (canUpload) { - uploadToken = (await this.authService.getGitHubSession('any', { silent: true }))?.accessToken; + uploadToken = (await this.authService?.getGitHubSession('any', { silent: true }))?.accessToken; } - return Promise.resolve(imageDataPartToTSX(part, uploadToken, this.endpoint.urlOrRequestMetadata, this.logService, this.imageService)); + return Promise.resolve(imageDataPartToTSX(part, uploadToken, this.endpoint?.urlOrRequestMetadata, this.logService, this.imageService)); } protected onTSX(part: JSONTree.PromptElementJSON) { @@ -956,8 +956,8 @@ export class ToolResult extends PrimitiveToolResult { return content; } - const tokens = await this.endpoint.acquireTokenizer().tokenLength(content); - if (tokens < truncateAtTokens) { + const tokens = await this.endpoint?.acquireTokenizer().tokenLength(content); + if (!tokens || tokens < truncateAtTokens) { return content; }