Skip to content

Commit

Permalink
send ansible extension version in lightspeed requests (#1111)
Browse files Browse the repository at this point in the history
* send ansible extension version in lightspeed requests

* chore: auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
robinbobbitt and pre-commit-ci[bot] authored Mar 4, 2024
1 parent 0dbebb2 commit 99a6026
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
30 changes: 24 additions & 6 deletions src/features/lightspeed/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,18 @@ export class LightSpeedAPI {
private lightSpeedAuthProvider: LightSpeedAuthenticationProvider;
private _completionRequestInProgress: boolean;
private _inlineSuggestionFeedbackSent: boolean;
private _extensionVersion: string;

constructor(
settingsManager: SettingsManager,
lightSpeedAuthProvider: LightSpeedAuthenticationProvider
lightSpeedAuthProvider: LightSpeedAuthenticationProvider,
context: vscode.ExtensionContext
) {
this.settingsManager = settingsManager;
this.lightSpeedAuthProvider = lightSpeedAuthProvider;
this._completionRequestInProgress = false;
this._inlineSuggestionFeedbackSent = false;
this._extensionVersion = context.extension.packageJSON.version;
}

get completionRequestInProgress(): boolean {
Expand Down Expand Up @@ -101,9 +104,16 @@ export class LightSpeedAPI {
try {
this._completionRequestInProgress = true;
this._inlineSuggestionFeedbackSent = false;
const requestData = {
...inputData,
metadata: {
...inputData.metadata,
ansibleExtensionVersion: this._extensionVersion,
},
};
const response = await axiosInstance.post(
LIGHTSPEED_SUGGESTION_COMPLETION_URL,
inputData,
requestData,
{
timeout: ANSIBLE_LIGHTSPEED_API_TIMEOUT,
}
Expand Down Expand Up @@ -167,15 +177,19 @@ export class LightSpeedAPI {
if (Object.keys(inputData).length === 0) {
return {} as FeedbackResponseParams;
}
const requestData = {
...inputData,
metadata: { ansibleExtensionVersion: this._extensionVersion },
};
console.log(
`[ansible-lightspeed] Feedback request sent to lightspeed: ${JSON.stringify(
inputData
requestData
)}`
);
try {
const response = await axiosInstance.post(
LIGHTSPEED_SUGGESTION_FEEDBACK_URL,
inputData,
requestData,
{
timeout: ANSIBLE_LIGHTSPEED_API_TIMEOUT,
}
Expand Down Expand Up @@ -233,14 +247,18 @@ export class LightSpeedAPI {
return {} as ContentMatchesResponseParams;
}
try {
const requestData = {
...inputData,
metadata: { ansibleExtensionVersion: this._extensionVersion },
};
console.log(
`[ansible-lightspeed] Content Match request sent to lightspeed: ${JSON.stringify(
inputData
requestData
)}`
);
const response = await axiosInstance.post(
LIGHTSPEED_SUGGESTION_CONTENT_MATCHES_URL,
inputData,
requestData,
{
timeout: ANSIBLE_LIGHTSPEED_API_TIMEOUT,
}
Expand Down
3 changes: 2 additions & 1 deletion src/features/lightspeed/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export class LightSpeedManager {
}
this.apiInstance = new LightSpeedAPI(
this.settingsManager,
this.lightSpeedAuthenticationProvider
this.lightSpeedAuthenticationProvider,
this.context
);
this.apiInstance
.getData(`${getBaseUri(this.settingsManager)}${LIGHTSPEED_ME_AUTH_URL}`)
Expand Down

0 comments on commit 99a6026

Please sign in to comment.