From 911f27ad59a9998097236e65057fc74b64b8a1b3 Mon Sep 17 00:00:00 2001 From: peternhale Date: Fri, 15 Nov 2024 06:57:08 -0700 Subject: [PATCH 1/7] feat: add service provider for api client @W-17228055@ --- src/index.ts | 1 + src/services/serviceProvider.ts | 4 +- src/types/aiApiClient/aiApiClientTypes.ts | 149 ++++++++++++++++++++++ src/types/index.ts | 34 +++-- 4 files changed, 179 insertions(+), 9 deletions(-) create mode 100644 src/types/aiApiClient/aiApiClientTypes.ts diff --git a/src/index.ts b/src/index.ts index cf50a65..d03551b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -10,3 +10,4 @@ export * from './types'; export const telemetryCommand = 'sf.vscode.core.get.telemetry'; export const loggerCommand = 'sf.vscode.core.logger.get.instance'; +export const aiApiCommand = 'salesforcedx-einstein-gpt.getAiClient'; diff --git a/src/services/serviceProvider.ts b/src/services/serviceProvider.ts index 9902156..0f25564 100644 --- a/src/services/serviceProvider.ts +++ b/src/services/serviceProvider.ts @@ -12,7 +12,7 @@ import { ServiceValidators } from '../types'; import * as vscode from 'vscode'; -import { loggerCommand, telemetryCommand } from '../index'; +import { aiApiCommand, loggerCommand, telemetryCommand } from '../index'; /** * The ServiceProvider class is a utility class that provides services of different types. @@ -195,6 +195,8 @@ export class ServiceProvider { return loggerCommand; case ServiceType.Telemetry: return telemetryCommand; + case ServiceType.AiApiClient: + return aiApiCommand; default: throw new Error(`Unsupported service type: ${type}`); } diff --git a/src/types/aiApiClient/aiApiClientTypes.ts b/src/types/aiApiClient/aiApiClientTypes.ts new file mode 100644 index 0000000..fab325f --- /dev/null +++ b/src/types/aiApiClient/aiApiClientTypes.ts @@ -0,0 +1,149 @@ +/* + * Copyright (c) 2024, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ + +import { CancellationToken, Uri } from 'vscode'; + +export type JaccardSnippet = { + file_path: string; + text: string; + similarity: number; +}; + +export type InlineCompletionRequestContext = { + current_file_path: string; + windows: JaccardSnippet[]; +}; + +export type InlineCompletionRequestInputs = { + prefix: string; + suffix: string; + context: InlineCompletionRequestContext | string; + promptId: string; +}; + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +interface Completion { + completion: string; + responseId?: string; + generationId?: string; + lineCount: number | undefined; + newLineChar: string; + + addTrailingLine(text: string): string; + + getLineCount(): number; + + isMultiline(text: string): boolean; + + isEmpty(): boolean; + + isWhiteSpaceString(text: string): boolean; +} + +export type GenericCompletionType = + | { completion: string } + | { id: string; text: string }; + +export type SFApiCompletion = Extract; +export type CodeGenCompletion = Extract< + GenericCompletionType, + { completion: string } +>; + +// There are two different api's we are currently supporting for the gpt response. +// A new conditional type should me created to include future additions. +export type CompletionType = + T extends SFApiCompletion ? SFApiCompletion : CodeGenCompletion; + +export type AiCompletion = CompletionType; +export enum CommandSource { + NLtoCodeGen = 'NLtoCodeGen', + TestGen = 'TestGen', + InlineAutocomplete = 'InlineAutocomplete', + Chat = 'Chat' +} + +export const ReactionToActionMap = { + GOOD: 'thumbs-up', + BAD: 'thumbs-down' +} as const; + +const EGPT_ACCEPT_COMMAND = 'accept'; + +const EGPT_ACCEPT_TEST_COMMAND = 'test'; +const EGPT_CLEAR_COMMAND = 'clear'; +const EGPT_CLEAR_TEST_COMMAND = 'clear-test'; +const EGPT_TEST_COMMAND = 'command-test'; +const EGPT_POST_COMPLETION = 'post-completion'; +const EGPT_COMMAND = 'command-command'; + +export const CommandToActionMap = { + [EGPT_ACCEPT_COMMAND]: 'accept', + [EGPT_ACCEPT_TEST_COMMAND]: 'acceptTest', + [EGPT_CLEAR_COMMAND]: 'reject', + [EGPT_CLEAR_TEST_COMMAND]: 'rejectTest', + [EGPT_TEST_COMMAND]: 'test', + [EGPT_POST_COMPLETION]: 'generation-edit', + // command below only maps to a feedback action when its a retry. + [EGPT_COMMAND]: 'regeneration' +} as const; + +export type Commands = keyof typeof CommandToActionMap; +export type Actions = + | (typeof ReactionToActionMap)[Reactions] + | (typeof CommandToActionMap)[Commands]; + +export type Reactions = keyof typeof ReactionToActionMap; + +export type SerializedRange = [ + { line: number; character: number }, + { line: number; character: number } +]; + +export type FeedbackCustomContexValues = + | string + | string[] + | Uri + | Date + | SerializedRange + | boolean; + +export type LLMRequestBody = { + id: string; + generation_id: string; + feedback: Reactions | null; + feedback_text: string | null; + source: string; + previous_generation_ids?: string[]; + app_feedback: { + feedback_detail: { + action: Actions | null; + }; + custom_context: Record; + }; +}; + +export type QueryParams = { + prefix: string; + suffix: string; + input: string; + promptId: string; + commandSource: CommandSource; +}; + +export interface AiApiClient { + blockRestEndpoint: string; + inlineRestEndpoint: string; + naturalLanguageQuery( + queryParams: QueryParams + ): Promise[]>; + inlineQuery( + inputs: InlineCompletionRequestInputs, + token: CancellationToken + ): Promise[]>; + sendLLMFeedback?(telemetryData: LLMRequestBody): Promise; +} diff --git a/src/types/index.ts b/src/types/index.ts index 90011d5..7f357d2 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -7,18 +7,28 @@ import { LoggerInterface } from './logger/loggerTypes'; import { TelemetryServiceInterface } from './telemetry/telemetryTypes'; +import { AiApiClient } from './aiApiClient/aiApiClientTypes'; export const SFDX_CORE_EXTENSION_NAME = 'salesforcedx-vscode-core'; export enum ServiceType { Logger = 'Logger', - Telemetry = 'Telemetry' + Telemetry = 'Telemetry', + AiApiClient = 'AiApiClient' } // Define a mapping from service types to their corresponding parameter types interface ServiceParamsMap { [ServiceType.Logger]: [string]; // Logger requires a string parameter [ServiceType.Telemetry]: [string | undefined]; + [ServiceType.AiApiClient]: undefined; +} + +// Define a mapping from service types to their corresponding return types +interface ServiceReturnTypeMap { + [ServiceType.Telemetry]: TelemetryServiceInterface; + [ServiceType.Logger]: LoggerInterface; + [ServiceType.AiApiClient]: AiApiClient; } // Define a type that represents the parameter types for a given service type @@ -27,11 +37,7 @@ export type ServiceParams = // Define a type that represents the return type for a given service type export type ServiceReturnType = - T extends ServiceType.Telemetry - ? TelemetryServiceInterface - : T extends ServiceType.Logger - ? LoggerInterface - : never; + T extends keyof ServiceReturnTypeMap ? ServiceReturnTypeMap[T] : never; // Define a ServiceValidator interface interface ServiceValidator { @@ -55,8 +61,14 @@ export const ServiceValidators: { ): ServiceParams { return params; } + }, + [ServiceType.AiApiClient]: { + validateAndCorrect( + params: ServiceParams + ): ServiceParams { + return params; + } } - // Add more validators as needed }; // Define a ServiceInstanceValidator interface @@ -78,8 +90,14 @@ export const ServiceInstanceValidators: { validateAndCorrect(instanceName: string): string { return instanceName || SFDX_CORE_EXTENSION_NAME; } + }, + [ServiceType.AiApiClient]: { + validateAndCorrect(): string { + return 'singletonAiApiClient'; + } } - // Add more validators as needed }; + export * from './logger/loggerTypes'; export * from './telemetry/telemetryTypes'; +export * from './aiApiClient/aiApiClientTypes'; From e2b6934ffa6e6c4ebd25c99ce06f60a13a5802a5 Mon Sep 17 00:00:00 2001 From: peternhale Date: Fri, 15 Nov 2024 07:47:46 -0700 Subject: [PATCH 2/7] chore: create rc release version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4173871..0a22455 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@salesforce/vscode-service-provider", - "version": "1.2.1", + "version": "1.3.0-rc.0", "description": "Library that provides access to Salesforce VSCode Service Provider", "main": "lib/src/index.js", "author": "Peter Hale ", From 840b93a77713ed772138e3f9acd74ede36fe10dd Mon Sep 17 00:00:00 2001 From: svc-cli-bot Date: Fri, 15 Nov 2024 14:57:52 +0000 Subject: [PATCH 3/7] chore(release): 1.3.0-rc.1 [skip ci] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 0a22455..9f1f4f0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@salesforce/vscode-service-provider", - "version": "1.3.0-rc.0", + "version": "1.3.0-rc.1", "description": "Library that provides access to Salesforce VSCode Service Provider", "main": "lib/src/index.js", "author": "Peter Hale ", From a136ab64d686cd394f4ea98fbf63d24a57fb4203 Mon Sep 17 00:00:00 2001 From: peternhale Date: Fri, 15 Nov 2024 10:33:53 -0700 Subject: [PATCH 4/7] chore: reorg file structure and add jsdoc --- .../aiApiClient/Completions/AiCompletion.ts | 40 +++++ .../Completions/InlineCompletions.ts | 36 +++++ src/types/aiApiClient/aiApiClientTypes.ts | 149 ------------------ src/types/aiApiClient/enums/commandSource.ts | 27 ++++ src/types/aiApiClient/index.ts | 14 ++ src/types/aiApiClient/types/ApiClient.ts | 84 ++++++++++ .../aiApiClient/types/PromptStoreEntry.ts | 10 ++ src/types/aiApiClient/types/TelemetryData.ts | 47 ++++++ .../utils/Completion/Completion.ts | 77 +++++++++ src/types/index.ts | 4 +- 10 files changed, 337 insertions(+), 151 deletions(-) create mode 100644 src/types/aiApiClient/Completions/AiCompletion.ts create mode 100644 src/types/aiApiClient/Completions/InlineCompletions.ts delete mode 100644 src/types/aiApiClient/aiApiClientTypes.ts create mode 100644 src/types/aiApiClient/enums/commandSource.ts create mode 100644 src/types/aiApiClient/index.ts create mode 100644 src/types/aiApiClient/types/ApiClient.ts create mode 100644 src/types/aiApiClient/types/PromptStoreEntry.ts create mode 100644 src/types/aiApiClient/types/TelemetryData.ts create mode 100644 src/types/aiApiClient/utils/Completion/Completion.ts diff --git a/src/types/aiApiClient/Completions/AiCompletion.ts b/src/types/aiApiClient/Completions/AiCompletion.ts new file mode 100644 index 0000000..8063580 --- /dev/null +++ b/src/types/aiApiClient/Completions/AiCompletion.ts @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2024, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +export type GenericCompletionType = + | { completion: string } + | { id: string; text: string }; + +/** + * Represents a Salesforce API completion type. + * @property {string} id - The unique identifier for the completion. + * @property {string} text - The text of the completion. + */ +export type SFApiCompletion = Extract; + +/** + * Represents a code generation completion type. + * @property {string} completion - The completion text. + */ +export type CodeGenCompletion = Extract< + GenericCompletionType, + { completion: string } +>; + +// There are two different APIs we are currently supporting for the GPT response. +// A new conditional type should be created to include future additions. + +/** + * Represents a completion type based on the provided generic type. + * @template T + */ +export type CompletionType = + T extends SFApiCompletion ? SFApiCompletion : CodeGenCompletion; + +/** + * Represents an AI completion type. + */ +export type AiCompletion = CompletionType; diff --git a/src/types/aiApiClient/Completions/InlineCompletions.ts b/src/types/aiApiClient/Completions/InlineCompletions.ts new file mode 100644 index 0000000..9f89bcc --- /dev/null +++ b/src/types/aiApiClient/Completions/InlineCompletions.ts @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2024, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ + +export type JaccardSnippet = { + file_path: string; + text: string; + similarity: number; +}; + +/** + * Represents the context for an inline completion request. + * @property {string} current_file_path - The current file path. + * @property {JaccardSnippet[]} windows - The array of Jaccard snippets. + */ +export type InlineCompletionRequestContext = { + current_file_path: string; + windows: JaccardSnippet[]; +}; + +/** + * Represents the inputs for an inline completion request. + * @property {string} prefix - The prefix text for the completion. + * @property {string} suffix - The suffix text for the completion. + * @property {InlineCompletionRequestContext | string} context - The context for the completion request. + * @property {string} promptId - The prompt identifier. + */ +export type InlineCompletionRequestInputs = { + prefix: string; + suffix: string; + context: InlineCompletionRequestContext | string; + promptId: string; +}; diff --git a/src/types/aiApiClient/aiApiClientTypes.ts b/src/types/aiApiClient/aiApiClientTypes.ts deleted file mode 100644 index fab325f..0000000 --- a/src/types/aiApiClient/aiApiClientTypes.ts +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (c) 2024, salesforce.com, inc. - * All rights reserved. - * Licensed under the BSD 3-Clause license. - * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause - */ - -import { CancellationToken, Uri } from 'vscode'; - -export type JaccardSnippet = { - file_path: string; - text: string; - similarity: number; -}; - -export type InlineCompletionRequestContext = { - current_file_path: string; - windows: JaccardSnippet[]; -}; - -export type InlineCompletionRequestInputs = { - prefix: string; - suffix: string; - context: InlineCompletionRequestContext | string; - promptId: string; -}; - -// eslint-disable-next-line @typescript-eslint/no-unused-vars -interface Completion { - completion: string; - responseId?: string; - generationId?: string; - lineCount: number | undefined; - newLineChar: string; - - addTrailingLine(text: string): string; - - getLineCount(): number; - - isMultiline(text: string): boolean; - - isEmpty(): boolean; - - isWhiteSpaceString(text: string): boolean; -} - -export type GenericCompletionType = - | { completion: string } - | { id: string; text: string }; - -export type SFApiCompletion = Extract; -export type CodeGenCompletion = Extract< - GenericCompletionType, - { completion: string } ->; - -// There are two different api's we are currently supporting for the gpt response. -// A new conditional type should me created to include future additions. -export type CompletionType = - T extends SFApiCompletion ? SFApiCompletion : CodeGenCompletion; - -export type AiCompletion = CompletionType; -export enum CommandSource { - NLtoCodeGen = 'NLtoCodeGen', - TestGen = 'TestGen', - InlineAutocomplete = 'InlineAutocomplete', - Chat = 'Chat' -} - -export const ReactionToActionMap = { - GOOD: 'thumbs-up', - BAD: 'thumbs-down' -} as const; - -const EGPT_ACCEPT_COMMAND = 'accept'; - -const EGPT_ACCEPT_TEST_COMMAND = 'test'; -const EGPT_CLEAR_COMMAND = 'clear'; -const EGPT_CLEAR_TEST_COMMAND = 'clear-test'; -const EGPT_TEST_COMMAND = 'command-test'; -const EGPT_POST_COMPLETION = 'post-completion'; -const EGPT_COMMAND = 'command-command'; - -export const CommandToActionMap = { - [EGPT_ACCEPT_COMMAND]: 'accept', - [EGPT_ACCEPT_TEST_COMMAND]: 'acceptTest', - [EGPT_CLEAR_COMMAND]: 'reject', - [EGPT_CLEAR_TEST_COMMAND]: 'rejectTest', - [EGPT_TEST_COMMAND]: 'test', - [EGPT_POST_COMPLETION]: 'generation-edit', - // command below only maps to a feedback action when its a retry. - [EGPT_COMMAND]: 'regeneration' -} as const; - -export type Commands = keyof typeof CommandToActionMap; -export type Actions = - | (typeof ReactionToActionMap)[Reactions] - | (typeof CommandToActionMap)[Commands]; - -export type Reactions = keyof typeof ReactionToActionMap; - -export type SerializedRange = [ - { line: number; character: number }, - { line: number; character: number } -]; - -export type FeedbackCustomContexValues = - | string - | string[] - | Uri - | Date - | SerializedRange - | boolean; - -export type LLMRequestBody = { - id: string; - generation_id: string; - feedback: Reactions | null; - feedback_text: string | null; - source: string; - previous_generation_ids?: string[]; - app_feedback: { - feedback_detail: { - action: Actions | null; - }; - custom_context: Record; - }; -}; - -export type QueryParams = { - prefix: string; - suffix: string; - input: string; - promptId: string; - commandSource: CommandSource; -}; - -export interface AiApiClient { - blockRestEndpoint: string; - inlineRestEndpoint: string; - naturalLanguageQuery( - queryParams: QueryParams - ): Promise[]>; - inlineQuery( - inputs: InlineCompletionRequestInputs, - token: CancellationToken - ): Promise[]>; - sendLLMFeedback?(telemetryData: LLMRequestBody): Promise; -} diff --git a/src/types/aiApiClient/enums/commandSource.ts b/src/types/aiApiClient/enums/commandSource.ts new file mode 100644 index 0000000..c62fabc --- /dev/null +++ b/src/types/aiApiClient/enums/commandSource.ts @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2024, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +export enum CommandSource { + /** + * Command source for natural language to code generation. + */ + NLtoCodeGen = 'NLtoCodeGen', + + /** + * Command source for test generation. + */ + TestGen = 'TestGen', + + /** + * Command source for inline autocomplete. + */ + InlineAutocomplete = 'InlineAutocomplete', + + /** + * Command source for chat. + */ + Chat = 'Chat' +} diff --git a/src/types/aiApiClient/index.ts b/src/types/aiApiClient/index.ts new file mode 100644 index 0000000..c4f0221 --- /dev/null +++ b/src/types/aiApiClient/index.ts @@ -0,0 +1,14 @@ +/* + * Copyright (c) 2024, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ + +export * from './types/PromptStoreEntry'; +export * from './types/TelemetryData'; +export * from './types/ApiClient'; +export * from './enums/commandSource'; +export * from './utils/Completion/Completion'; +export * from './Completions/AiCompletion'; +export * from './Completions/InlineCompletions'; diff --git a/src/types/aiApiClient/types/ApiClient.ts b/src/types/aiApiClient/types/ApiClient.ts new file mode 100644 index 0000000..dd9ed41 --- /dev/null +++ b/src/types/aiApiClient/types/ApiClient.ts @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2024, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +import { + Actions, + FeedbackCustomContextValues, + Reactions +} from './TelemetryData'; +import { CommandSource } from '../enums/commandSource'; +import { Completion } from '../utils/Completion/Completion'; +import { AiCompletion } from '../index'; +import { InlineCompletionRequestInputs } from '../Completions/InlineCompletions'; +import { CancellationToken } from 'vscode'; + +export type LLMRequestBody = { + id: string; + generation_id: string; + feedback: Reactions | null; + feedback_text: string | null; + source: string; + previous_generation_ids?: string[]; + app_feedback: { + feedback_detail: { + action: Actions | null; + }; + custom_context: Record; + }; +}; + +/** + * Represents the query parameters for natural language queries. + * @property {string} prefix - The prefix for the query. + * @property {string} suffix - The suffix for the query. + * @property {string} input - The input for the query. + * @property {string} promptId - The prompt identifier. + * @property {CommandSource} commandSource - The source of the command. + */ +export type QueryParams = { + prefix: string; + suffix: string; + input: string; + promptId: string; + commandSource: CommandSource; +}; +/** + * Interface for AI API client. + * @interface AiApiClient + * @property {string} blockRestEndpoint - The endpoint for blocking REST requests. + * @property {string} inlineRestEndpoint - The endpoint for inline REST requests. + */ +export interface AiApiClient { + blockRestEndpoint: string; + inlineRestEndpoint: string; + + /** + * Executes a natural language query. + * @param queryParams - The query parameters. + * @returns A promise that resolves to an array of completions. + */ + naturalLanguageQuery( + queryParams: QueryParams + ): Promise[]>; + + /** + * Executes an inline query. + * @param inputs - The inputs for the inline query. + * @param token - The cancellation token. + * @returns A promise that resolves to an array of completions. + */ + inlineQuery( + inputs: InlineCompletionRequestInputs, + token: CancellationToken + ): Promise[]>; + + /** + * Sends feedback for LLM. + * @param telemetryData - The telemetry data for feedback. + * @returns A promise that resolves when the feedback is sent. + */ + sendLLMFeedback?(telemetryData: LLMRequestBody): Promise; +} diff --git a/src/types/aiApiClient/types/PromptStoreEntry.ts b/src/types/aiApiClient/types/PromptStoreEntry.ts new file mode 100644 index 0000000..c2608e6 --- /dev/null +++ b/src/types/aiApiClient/types/PromptStoreEntry.ts @@ -0,0 +1,10 @@ +/* + * Copyright (c) 2024, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +export type SerializedRange = [ + { line: number; character: number }, + { line: number; character: number } +]; diff --git a/src/types/aiApiClient/types/TelemetryData.ts b/src/types/aiApiClient/types/TelemetryData.ts new file mode 100644 index 0000000..0d5c9dd --- /dev/null +++ b/src/types/aiApiClient/types/TelemetryData.ts @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2024, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +import { Uri } from 'vscode'; +import { SerializedRange } from './PromptStoreEntry'; + +export const ReactionToActionMap = { + GOOD: 'thumbs-up', + BAD: 'thumbs-down' +} as const; + +export type Reactions = keyof typeof ReactionToActionMap; + +const EGPT_ACCEPT_COMMAND = 'accept'; +const EGPT_ACCEPT_TEST_COMMAND = 'test'; +const EGPT_CLEAR_COMMAND = 'clear'; +const EGPT_CLEAR_TEST_COMMAND = 'clear-test'; +const EGPT_TEST_COMMAND = 'command-test'; +const EGPT_POST_COMPLETION = 'post-completion'; +const EGPT_COMMAND = 'command-command'; + +export const CommandToActionMap = { + [EGPT_ACCEPT_COMMAND]: 'accept', + [EGPT_ACCEPT_TEST_COMMAND]: 'acceptTest', + [EGPT_CLEAR_COMMAND]: 'reject', + [EGPT_CLEAR_TEST_COMMAND]: 'rejectTest', + [EGPT_TEST_COMMAND]: 'test', + [EGPT_POST_COMPLETION]: 'generation-edit', + // command below only maps to a feedback action when it's a retry. + [EGPT_COMMAND]: 'regeneration' +} as const; + +export type Commands = keyof typeof CommandToActionMap; +export type Actions = + | (typeof ReactionToActionMap)[Reactions] + | (typeof CommandToActionMap)[Commands]; + +export type FeedbackCustomContextValues = + | string + | string[] + | Uri + | Date + | SerializedRange + | boolean; diff --git a/src/types/aiApiClient/utils/Completion/Completion.ts b/src/types/aiApiClient/utils/Completion/Completion.ts new file mode 100644 index 0000000..a1c9bc3 --- /dev/null +++ b/src/types/aiApiClient/utils/Completion/Completion.ts @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2024, salesforce.com, inc. + * All rights reserved. + * Licensed under the BSD 3-Clause license. + * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause + */ +import { AiCompletion, CompletionType } from '../../index'; + +/** + * Interface representing a completion. + * @template T - The type of AI completion. + */ +export type Completion = { + new (completion: CompletionType, id?: string): Completion; + /** + * The completion text. + * @type {string} + */ + completion: string; + + /** + * The response identifier. + * @type {string | undefined} + */ + responseId?: string; + + /** + * The generation identifier. + * @type {string | undefined} + */ + generationId?: string; + + /** + * The number of lines in the completion. + * @type {number | undefined} + */ + lineCount: number | undefined; + + /** + * The newline character. + * @type {string} + */ + newLineChar: string; + + /** + * Adds a trailing newline character to the text. + * @param text - The text to which the newline character is added. + * @returns The text with the trailing newline character. + */ + addTrailingLine(text: string): string; + + /** + * Gets the number of lines in the completion. + * @returns The number of lines in the completion. + */ + getLineCount(): number; + + /** + * Checks if the text is multiline. + * @param text - The text to check. + * @returns True if the text is multiline, false otherwise. + */ + isMultiline(text: string): boolean; + + /** + * Checks if the completion is empty. + * @returns True if the completion is empty, false otherwise. + */ + isEmpty(): boolean; + + /** + * Checks if the text is a whitespace string. + * @param text - The text to check. + * @returns True if the text is a whitespace string, false otherwise. + */ + isWhiteSpaceString(text: string): boolean; +}; diff --git a/src/types/index.ts b/src/types/index.ts index 7f357d2..79eabd1 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -7,7 +7,7 @@ import { LoggerInterface } from './logger/loggerTypes'; import { TelemetryServiceInterface } from './telemetry/telemetryTypes'; -import { AiApiClient } from './aiApiClient/aiApiClientTypes'; +import { AiApiClient } from './aiApiClient'; export const SFDX_CORE_EXTENSION_NAME = 'salesforcedx-vscode-core'; @@ -100,4 +100,4 @@ export const ServiceInstanceValidators: { export * from './logger/loggerTypes'; export * from './telemetry/telemetryTypes'; -export * from './aiApiClient/aiApiClientTypes'; +export * from './aiApiClient'; From 03af92b79964694996df38fcc9dc15745ff1f2c8 Mon Sep 17 00:00:00 2001 From: svc-cli-bot Date: Fri, 15 Nov 2024 17:41:23 +0000 Subject: [PATCH 5/7] chore(release): 1.3.0-1.3.0-rc.2.0 [skip ci] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9f1f4f0..c7f5b23 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@salesforce/vscode-service-provider", - "version": "1.3.0-rc.1", + "version": "1.3.0-1.3.0-rc.2.0", "description": "Library that provides access to Salesforce VSCode Service Provider", "main": "lib/src/index.js", "author": "Peter Hale ", From a9628212849b2fe5d6c702ef578796fc71426ac7 Mon Sep 17 00:00:00 2001 From: peternhale Date: Fri, 15 Nov 2024 10:44:11 -0700 Subject: [PATCH 6/7] chore: bump rc version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index c7f5b23..80201b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@salesforce/vscode-service-provider", - "version": "1.3.0-1.3.0-rc.2.0", + "version": "1.3.0-rc.2", "description": "Library that provides access to Salesforce VSCode Service Provider", "main": "lib/src/index.js", "author": "Peter Hale ", From eea7b59dcf9e3f9f519794fb5d4d313fd586bf9e Mon Sep 17 00:00:00 2001 From: svc-cli-bot Date: Fri, 15 Nov 2024 17:48:49 +0000 Subject: [PATCH 7/7] chore(release): 1.3.0-rc.3 [skip ci] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 80201b3..8434d02 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@salesforce/vscode-service-provider", - "version": "1.3.0-rc.2", + "version": "1.3.0-rc.3", "description": "Library that provides access to Salesforce VSCode Service Provider", "main": "lib/src/index.js", "author": "Peter Hale ",