import type { Response as NodeResponse } from 'node-fetch'; import { URI } from 'vscode-uri'; import type { TelemetryEventInput } from '@sourcegraph/telemetry'; import type { AuthStatus } from '../../auth/types'; import type { ConfigurationWithAccessToken } from '../../configuration'; export type BrowserOrNodeResponse = Response | NodeResponse; export declare function isNodeResponse(response: BrowserOrNodeResponse): response is NodeResponse; export type FuzzyFindFilesResponse = { __typename?: 'Query'; search: { results: { results: Array; }; } | null; }; export type FuzzyFindSymbolsResponse = { __typename?: 'Query'; search: { results: { results: FuzzyFindSymbol[]; }; }; }; type FuzzyFindFile = { file: { path: string; url: string; name: string; byteSize: number; isDirectory: boolean; }; repository: { id: string; name: string; }; }; type FuzzyFindSymbol = { symbols: { name: string; location: { range: { start: { line: number; }; end: { line: number; }; }; resource: { path: string; }; }; }[]; repository: { id: string; name: string; }; }; interface CodyClientConfig { codyEnabled: boolean; chatEnabled: boolean; autoCompleteEnabled: boolean; customCommandsEnabled: boolean; attributionEnabled: boolean; smartContextWindowEnabled: boolean; modelsAPIEnabled: boolean; } interface CodyConfigFeatures { chat: boolean; autoComplete: boolean; commands: boolean; attribution: boolean; } interface PackageListResponse { packageRepoReferences: { nodes: { id: string; name: string; kind: string; repository: { id: string; name: string; url: string; }; }[]; pageInfo: { endCursor: string | null; }; }; } export interface RepoListResponse { repositories: { nodes: { name: string; id: string; }[]; pageInfo: { endCursor: string | null; }; }; } export interface RepoSearchResponse { repositories: { nodes: { name: string; id: string; url: string; }[]; pageInfo: { endCursor: string | null; }; }; } interface FileMatchSearchResponse { search: { results: { results: { __typename: string; repository: { name: string; }; file: { url: string; path: string; commit: { oid: string; }; }; }[]; }; }; } interface FileContentsResponse { repository: { commit: { file: { path: string; url: string; content: string; } | null; } | null; } | null; } type LogEventResponse = unknown; type RecordContextResponse = unknown; interface RankContextResponse { rankContext: { ranker: string; used: number[]; ignored: number[]; }; } export interface EmbeddingsSearchResult { repoName?: string; revision?: string; uri: URI; startLine: number; endLine: number; content: string; } export interface ChatIntentResult { intent: string; score: number; } /** * Experimental API. */ export interface InputContextItem { content: string; retriever: string; score?: number; } export interface ContextSearchResult { repoName: string; commit: string; uri: URI; path: string; startLine: number; endLine: number; content: string; } /** * A prompt that can be shared and reused. See Prompt in the Sourcegraph GraphQL API. */ export interface Prompt { id: string; name: string; nameWithOwner: string; owner: { namespaceName: string; }; description?: string; draft: boolean; definition: { text: string; }; url: string; } export interface ContextFilters { include?: CodyContextFilterItem[] | null; exclude?: CodyContextFilterItem[] | null; } export interface CodyContextFilterItem { repoNamePattern: string; filePathPatterns?: string[]; } /** * Default value used on the client in case context filters are not set. */ export declare const INCLUDE_EVERYTHING_CONTEXT_FILTERS: { include: { repoNamePattern: string; }[]; exclude: null; }; /** * Default value used on the client in case client encounters errors * fetching or parsing context filters. */ export declare const EXCLUDE_EVERYTHING_CONTEXT_FILTERS: { include: null; exclude: { repoNamePattern: string; }[]; }; interface SearchAttributionResults { limitHit: boolean; nodes: { repositoryName: string; }[]; } export interface CodyLLMSiteConfiguration { chatModel?: string; chatModelMaxTokens?: number; fastChatModel?: string; fastChatModelMaxTokens?: number; completionModel?: string; completionModelMaxTokens?: number; provider?: string; smartContextWindow?: boolean; } export interface CurrentUserCodySubscription { status: string; plan: string; applyProRateLimits: boolean; currentPeriodStartAt: Date; currentPeriodEndAt: Date; } export interface CurrentUserInfo { id: string; hasVerifiedEmail: boolean; username: string; displayName?: string; avatarURL: string; primaryEmail?: { email: string; } | null; organizations: { nodes: { name: string; id: string; }[]; }; } /** * @deprecated Use 'TelemetryEvent' instead. */ export interface event { event: string; userCookieID: string; url: string; source: string; argument?: string | unknown; publicArgument?: string | unknown; client: string; connectedSiteID?: string; hashedLicenseKey?: string; } export type GraphQLAPIClientConfig = Pick & Pick, 'telemetryLevel'>; export declare let customUserAgent: string | undefined; export declare function addCustomUserAgent(headers: Headers): void; export declare function setUserAgent(newUseragent: string): void; export declare class SourcegraphGraphQLAPIClient { private dotcomUrl; anonymousUserID: string | undefined; /** * Should be set on extension activation via `localStorage.onConfigurationChange(config)` * Done to avoid passing the graphql client around as a parameter and instead * access it as a singleton via the module import. */ private _config; private get config(); private isAgentTesting; constructor(config?: GraphQLAPIClientConfig | null); setConfig(newConfig: GraphQLAPIClientConfig): void; /** * Tells if the underlying configuration contains an access token, i.e. if requests made right * now would likely be authenticated. This can be used to avoid making requests that would * otherwise just fail due to requiring auth. */ hasAccessToken(): boolean; /** * If set, anonymousUID is transmitted as 'X-Sourcegraph-Actor-Anonymous-UID' * which is automatically picked up by Sourcegraph backends 5.2+ */ setAnonymousUserID(anonymousUID: string): void; isDotCom(): boolean; get endpoint(): string; getSiteVersion(): Promise; getRemoteFiles(repositories: string[], query: string): Promise; getRemoteSymbols(repositories: string[], query: string): Promise; getFileContent(repository: string, filePath: string, range?: { startLine?: number; endLine?: number; }): Promise; getSiteIdentification(): Promise<{ siteid: string; hashedLicenseKey: string; } | Error>; getSiteHasIsCodyEnabledField(): Promise; getSiteHasCodyEnabled(): Promise; getCurrentUserId(): Promise; getCurrentUserCodyProEnabled(): Promise<{ codyProEnabled: boolean; } | Error>; getCurrentUserCodySubscription(): Promise; getCurrentUserInfo(): Promise; /** * Fetches the Site Admin enabled/disable Cody config features for the current instance. */ getCodyConfigFeatures(): Promise; getCodyLLMConfiguration(): Promise; getCodyLLMConfigurationSmartContext(): Promise; getPackageList(kind: string, name: string, first: number, after?: string): Promise; /** * Gets a subset of the list of repositories from the Sourcegraph instance. * @param first the number of repositories to retrieve. * @param after the last repository retrieved, if any, to continue enumerating the list. * @returns the list of repositories. If `endCursor` is null, this is the end of the list. */ getRepoList(first: number, after?: string): Promise; /** * Searches for repositories from the Sourcegraph instance. * @param first the number of repositories to retrieve. * @param after the last repository retrieved, if any, to continue enumerating the list. * @param query the query to search the repositories. * @returns the list of repositories. If `endCursor` is null, this is the end of the list. */ searchRepos(first: number, after?: string, query?: string): Promise; searchFileMatches(query?: string): Promise; getFileContents(repoName: string, filePath: string, rev?: string): Promise; getRepoId(repoName: string): Promise; getRepoIds(names: string[], first: number): Promise<{ name: string; id: string; }[] | Error>; getRepoName(cloneURL: string): Promise; /** Experimental API */ chatIntent(interactionID: string, query: string): Promise; /** Experimental API */ recordContext(interactionID: string, used: InputContextItem[], ignored: InputContextItem[]): Promise; /** Experimental API */ rankContext(interactionID: string, query: string, context: InputContextItem[]): Promise; contextSearch(repoIDs: string[], query: string): Promise; contextFilters(): Promise<{ filters: ContextFilters; transient: boolean; }>; queryPrompts(query: string): Promise; /** * Checks if Cody is enabled on the current Sourcegraph instance. * @returns * enabled: Whether Cody is enabled. * version: The Sourcegraph version. * * This method first checks the Sourcegraph version using `getSiteVersion()`. * If the version is before 5.0.0, Cody is disabled. * If the version is 5.0.0 or newer, it checks for the existence of the `isCodyEnabled` field using `getSiteHasIsCodyEnabledField()`. * If the field exists, it calls `getSiteHasCodyEnabled()` to check its value. * If the field does not exist, Cody is assumed to be enabled for versions between 5.0.0 - 5.1.0. */ isCodyEnabled(): Promise<{ enabled: boolean; version: string; }>; /** * recordTelemetryEvents uses the new Telemetry API to record events that * gets exported: https://sourcegraph.com/docs/dev/background-information/telemetry * * Only available on Sourcegraph 5.2.0 and later. * * DO NOT USE THIS DIRECTLY - use an implementation of implementation * TelemetryRecorder from '@sourcegraph/telemetry' instead. */ recordTelemetryEvents(events: TelemetryEventInput[]): Promise; /** * logEvent is the legacy event-logging mechanism. * @deprecated use an implementation of implementation TelemetryRecorder * from '@sourcegraph/telemetry' instead. */ logEvent(event: event, mode: LogEventMode): Promise; private anonymizeTelemetryEventInput; private anonymizeEvent; private sendEventLogRequestToDotComAPI; private sendEventLogRequestToAPI; private sendEventLogRequestToTestingAPI; searchAttribution(snippet: string, timeoutMs: number): Promise; getEvaluatedFeatureFlags(): Promise | Error>; evaluateFeatureFlag(flagName: string): Promise; fetchSourcegraphAPI(query: string, variables?: Record, timeout?: number): Promise; private fetchSourcegraphDotcomAPI; private fetchSourcegraphTestingAPI; fetchHTTP(queryName: string, method: string, urlPath: string, body?: string, timeout?: number): Promise; } /** * Singleton instance of the graphql client. * Should be configured on the extension activation via `graphqlClient.onConfigurationChange(config)`. */ export declare const graphqlClient: SourcegraphGraphQLAPIClient; /** * ClientConfigSingleton is a class that manages the retrieval * and caching of configuration features from GraphQL endpoints. */ export declare class ClientConfigSingleton { private static instance; private cachedClientConfig?; private cachedAt; private isSignedIn; private featuresLegacy; private constructor(); static getInstance(): ClientConfigSingleton; setAuthStatus(authStatus: AuthStatus): Promise; getConfig(): Promise; private shouldFetch; private refreshConfig; private fetchClientConfigLegacy; private fetchConfigFeaturesLegacy; } export declare function verifyResponseCode(response: BrowserOrNodeResponse): Promise; export type LogEventMode = 'dotcom-only' | 'connected-instance-only' | 'all'; export {}; //# sourceMappingURL=client.d.ts.map