-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate VSCode Cody with server-side Context API (#4840)
This PR adds the Client-side integration of https://github.com/sourcegraph/sourcegraph/pull/63789 for VSCode: - GraphQL queries, types and client methods - ContextAPIClient class mapping VSCode objects to GraphQL - wiring of ContextAPIClient to existing code Currently, for all added backend calls: - all remote RPC are guarded by a feature flag - results of RPCs are not used by integrating call - calls are not awaited (to avoid slowing down interactions) Related to AI-128. ## Test plan - tested locally -> works with local and sourcegraph.com backend
- Loading branch information
Showing
8 changed files
with
206 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { | ||
type ContextItem, | ||
FeatureFlag, | ||
type FeatureFlagProvider, | ||
type SourcegraphGraphQLAPIClient, | ||
isError, | ||
logError, | ||
} from '@sourcegraph/cody-shared' | ||
import type { InputContextItem } from '@sourcegraph/cody-shared/src/sourcegraph-api/graphql/client' | ||
|
||
function toInput(input: ContextItem[]): InputContextItem[] { | ||
return input | ||
.map(i => | ||
!i || !i.content | ||
? null | ||
: { | ||
content: i.content, | ||
retriever: i.source || '', | ||
} | ||
) | ||
.filter(i => i !== null) as InputContextItem[] | ||
} | ||
|
||
export class ContextAPIClient { | ||
constructor( | ||
private readonly apiClient: SourcegraphGraphQLAPIClient, | ||
private readonly featureFlagProvider: FeatureFlagProvider | ||
) {} | ||
|
||
public async detectChatIntent(interactionID: string, query: string) { | ||
if (!(await this.isServerSideContextAPIEnabled())) { | ||
return | ||
} | ||
return this.apiClient.chatIntent(interactionID, query) | ||
} | ||
|
||
public async rankContext(interactionID: string, query: string, context: ContextItem[]) { | ||
if (!(await this.isServerSideContextAPIEnabled())) { | ||
return | ||
} | ||
const res = await this.apiClient.rankContext(interactionID, query, toInput(context)) | ||
if (isError(res)) { | ||
logError('rankContext', 'ranking result', res) | ||
return res | ||
} | ||
return { used: res.rankContext.used, ignored: res.rankContext.ignored } | ||
} | ||
|
||
public async recordContext(interactionID: string, used: ContextItem[], ignored: ContextItem[]) { | ||
if (!(await this.isServerSideContextAPIEnabled())) { | ||
return | ||
} | ||
await this.apiClient.recordContext(interactionID, toInput(used), toInput(ignored)) | ||
} | ||
|
||
private async isServerSideContextAPIEnabled() { | ||
return await this.featureFlagProvider.evaluateFeatureFlag(FeatureFlag.CodyServerSideContextAPI) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.