import { fetchAuthorizationServerMetadata } from "../../../../../../base/common/oauth.js"; import { URI } from "../../../../../../base/common/uri.js"; import { type IAgentEntitlementHint } from "../../../../../../platform/agentHost/common/meta/agentEntitlementHintMeta.js"; import { IDefaultAccountService } from "../../../../../../platform/defaultAccount/common/defaultAccount.service.js"; import { type McpAuthRequirement, type McpOAuthClient, type ModelSelection, type ProtectedResourceMetadata } from "../../../../../../platform/agentHost/common/state/protocol/state.js"; import type { AuthenticateTarget, McpServerAuthenticateTarget } from "../../../../../../platform/agentHost/common/state/sessionProtocol.js"; import type { IAgentConnection } from "../../../../../../platform/agentHost/common/agentService.js"; import { ICommandService } from "../../../../../../platform/commands/common/commands.service.js"; import { IConfigurationService } from "../../../../../../platform/configuration/common/configuration.service.js"; import { type AgentInfo } from "../../../../../../platform/agentHost/common/state/sessionState.js"; import { ServicesAccessor } from "../../../../../../platform/instantiation/common/instantiation.js"; import { ILogService } from "../../../../../../platform/log/common/log.service.js"; import { ITelemetryService } from "../../../../../../platform/telemetry/common/telemetry.service.js"; import { AuthenticationSession } from "../../../../../services/authentication/common/authentication.js"; import { IAuthenticationService } from "../../../../../services/authentication/common/authentication.service.js"; /** * Stable identity for an agent-host MCP server, used as the key for * remembered authentication (allowed-server access, account preference and * usage). Agent-host customization ids are **not** stable across reloads — * bare/top-level ids embed the agent-host session id, and synced child ids * embed a per-sync nonce — so keying remembered auth on them orphans the * grant on every reload. Instead we key on the session's host `authority` * plus the server `name` and its resource `url`, all of which are stable * for a given server across sessions and reloads. */ export declare function agentHostMcpServerId(authority: string, serverName: string, resourceUrl: string): string; /** * Whether creating a session with the selected model requires the agent's protected-resource authentication. */ export declare function modelRequiresAgentAuthentication(agent: AgentInfo | undefined, model: ModelSelection | undefined): boolean; /** * Tracks the last bearer token pushed to a given agent host connection * for each protected resource, so that redundant `authenticate` RPCs can * be suppressed when neither the resource nor the token has changed. * * One instance per connection. Owned by the contribution that drives * authentication for that connection so the cache is dropped naturally * when the connection is disposed. */ export declare class AgentHostAuthTokenCache { private readonly _completedTokens; private readonly _pendingAuthentications; private readonly _keyGenerations; private readonly _rejectedSessions; private _globalGeneration; /** * Forwards a token once per resource/scope/target combination. Same-token callers share * and await an in-flight authentication. */ authenticate(resource: string, scopes: readonly string[] | undefined, token: string, authenticate: () => Promise, accountId?: string, entitlement?: IAgentEntitlementHint, target?: AuthenticateTarget): Promise; /** * Clear the cached token for a specific resource/scope pair, a whole resource, * or all resources if no argument is given. Call after a failed `authenticate` * RPC or when the agent host process restarts. */ clear(resource?: string, scopes?: readonly string[]): void; rejectSession(resource: string, scopes: readonly string[] | undefined, session: AuthenticationSession): void; getRejectedSession(resource: string, scopes: readonly string[] | undefined): RejectedAuthenticationSession | undefined; clearRejectedSession(resource: string, scopes: readonly string[] | undefined): void; private _invalidateKey; private _isCurrentGeneration; private _key; } interface RejectedAuthenticationSession { readonly id: string; readonly accessToken: string; readonly accountId: string; } export type AuthenticationSessionSelection = { readonly kind: "selected"; readonly session: AuthenticationSession; readonly match: "exact" | "superset"; } | { readonly kind: "none"; } | { readonly kind: "accountMismatch"; }; export interface IAuthenticationAccountPreference { /** The preferred account, or `undefined` when it has no session among the candidates. */ readonly accountId: string | undefined; /** Whether another account may be used when it is the only signed-in account. */ readonly fallbackToSoleAccount: boolean; } /** * Selects the session that grants every requested scope with the fewest extra scopes. With a * preference, only the preferred account's sessions qualify. When that account cannot satisfy the * scopes, another account is chosen only if the preference allows falling back and it is the sole * signed-in account; otherwise using it would override the user's choice of account. */ export declare function selectAuthenticationSession(sessions: readonly AuthenticationSession[], requestedScopes: readonly string[], preference?: IAuthenticationAccountPreference): AuthenticationSessionSelection; /** * Coordinates recovery from authentication challenges for one agent-host connection. */ export declare class AgentHostAuthenticationRecovery { private readonly _telemetryService; private readonly _resentTokens; private readonly _pendingRecoveries; constructor(_telemetryService: ITelemetryService); clear(): void; recover(accessor: ServicesAccessor, resource: ProtectedResourceMetadata, options: IAgentHostAuthenticationOptions): Promise; private _recover; } /** * Resolves an authentication session for a protected resource by trying each * authorization server in order. First attempts an exact scope match, * then falls back to finding the session whose scopes are the narrowest * superset of the requested scopes. */ export declare function resolveSessionForResource(resourceServer: URI, authorizationServers: readonly string[], scopes: readonly string[], authenticationService: IAuthenticationService, logService: ILogService, logPrefix: string): Promise; export interface IAgentHostAuthenticateRequest { readonly target?: AuthenticateTarget; readonly resource: string; readonly scopes?: readonly string[]; /** An empty token revokes the credential previously forwarded for this resource and scope set. */ readonly token: string; /** The access token's remaining lifetime in seconds, when known. */ readonly expiresIn?: number; readonly _meta?: Record; } export interface IAgentHostAuthenticationOptions { readonly authTokenCache?: AgentHostAuthTokenCache; readonly logPrefix: string; /** Prefer this signed-in session's account when several accounts can satisfy the resource. */ readonly preferredSessionId?: string; readonly isCurrent?: () => boolean; /** Returns true after renewing a connection-owned credential, or false to use normal provider recovery. */ readonly renewAuthentication?: (resource: ProtectedResourceMetadata) => Promise; readonly authenticate: (request: IAgentHostAuthenticateRequest) => Promise; } export interface IAgentHostMcpAuthenticationOptionsBase { /** Echoes the host-advertised session URI and MCP customization id that issued the challenge, when known. */ readonly target: McpServerAuthenticateTarget | undefined; readonly allowInteraction: boolean; readonly authTokenCache?: AgentHostAuthTokenCache; readonly logPrefix: string; readonly mcpServerId: string; readonly mcpServerName: string; readonly mcpServerUrl: string; readonly oauthClient?: McpOAuthClient; readonly scopes: readonly string[]; readonly authorizationServerMetadataFetcher?: typeof fetchAuthorizationServerMetadata; /** * Identifies the agent host backing this MCP server so remembered-auth * entries can be surfaced in their own section of the "Manage Trusted MCP * Servers" picker. When set, the resolved host label (via * {@link ILabelService.getHostLabel}) is recorded on the allowed-server * entry. Omit for non-agent-host callers. */ readonly agentHost?: { readonly scheme: string; readonly authority: string; }; readonly authenticate: (request: IAgentHostAuthenticateRequest) => Promise; } /** Resolves initial authentication without mistaking an unavailable provider for a signed-out account. */ export declare function resolveProtectedResourceAuthentication(accessor: ServicesAccessor, resource: ProtectedResourceMetadata, logPrefix: string): Promise; /** * Resolves and forwards bearer tokens for the protected resources declared by * the agents currently published from an agent host. */ export declare function authenticateProtectedResources(accessor: ServicesAccessor, agents: readonly AgentInfo[], options: IAgentHostAuthenticationOptions): Promise; export declare function authenticateAgentProtectedResourcesWithToken(agents: readonly AgentInfo[], token: string, options: Pick): Promise; export declare function authenticateProtectedResourcesWithToken(protectedResources: readonly ProtectedResourceMetadata[], token: string, options: Pick): Promise; /** * Reconciles resources backed by an authentication session that was explicitly * removed. * * A removal event proves the provider is live and managing its sessions, which * is what makes an empty resolution trustworthy here -- unlike the polling path, * where "no token" cannot be distinguished from "not loaded yet". It does not, * however, prove the credential is gone: a provider may host several accounts, * and signing out of one leaves the others usable. Re-resolving keeps a partial * sign-out from revoking a credential the host still needs, which would restart * provider clients and move the Claude proxy port for no reason. * * Only resources the removed sessions could have satisfied are reconciled. One * provider commonly serves several resources with different scope sets (GitHub * serves both the Copilot and repository challenges), and a resource the removed * session never covered must not be re-evaluated against this client's view of * the world -- another client may be the one supplying its credential. */ export declare function revokeAuthenticationForRemovedSessions(accessor: ServicesAccessor, agents: readonly AgentInfo[], providerId: string, removedSessions: readonly Pick[], options: IAgentHostAuthenticationOptions): Promise; /** * Resolves and forwards a bearer token for a single protected resource. */ export declare function authenticateProtectedResource(accessor: ServicesAccessor, resource: ProtectedResourceMetadata, options: IAgentHostAuthenticationOptions): Promise; /** * Prompts the user to authenticate one of the provided protected resources and * forwards the resulting token to the agent host connection. */ export declare class AgentHostInteractiveAuthentication { private readonly authenticationService; private readonly commandService; private readonly logService; private readonly telemetryService; private readonly configurationService; private readonly defaultAccountService; constructor(authenticationService: IAuthenticationService, commandService: ICommandService, logService: ILogService, telemetryService: ITelemetryService, configurationService: IConfigurationService, defaultAccountService: IDefaultAccountService); request(resource: ProtectedResourceMetadata, options: IAgentHostAuthenticationOptions): Promise; } export declare function resolveAuthenticationInteractively(accessor: ServicesAccessor, protectedResources: readonly ProtectedResourceMetadata[], options: IAgentHostAuthenticationOptions): Promise; /** * Forwards the GitHub Copilot credential of the account that authorized Copilot Connectors, without prompting and * preferring that account's session that also grants the Connector scope. Connector-owned servers use this * credential, so this is how an authorization of the account reaches them. Never falls back to another account. */ export declare function authenticateCopilotConnectorCredential(accessor: ServicesAccessor, authorizedSessionId: string, authenticate: (request: IAgentHostAuthenticateRequest) => Promise): Promise; /** Supplies a previously authorized MCP token without creating sessions or prompting for access. */ export declare function autoAuthenticateMcpServer(accessor: ServicesAccessor, connection: Pick, agentHost: { readonly scheme: string; readonly authority: string; }, serverName: string, auth: Pick, target: McpServerAuthenticateTarget | undefined): Promise; /** Resolves an MCP credential, propagating discovery and provider failures for interactive requests. */ export declare function resolveMcpServerAuthentication(accessor: ServicesAccessor, protectedResource: ProtectedResourceMetadata, options: IAgentHostMcpAuthenticationOptionsBase): Promise; export {};