Skip to content

Commit

Permalink
chore: reorg file structure and add jsdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
peternhale committed Nov 15, 2024
1 parent 840b93a commit a136ab6
Show file tree
Hide file tree
Showing 10 changed files with 337 additions and 151 deletions.
40 changes: 40 additions & 0 deletions src/types/aiApiClient/Completions/AiCompletion.ts
Original file line number Diff line number Diff line change
@@ -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<GenericCompletionType, { id: string }>;

/**
* 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 | CodeGenCompletion> =
T extends SFApiCompletion ? SFApiCompletion : CodeGenCompletion;

/**
* Represents an AI completion type.
*/
export type AiCompletion = CompletionType<SFApiCompletion | CodeGenCompletion>;
36 changes: 36 additions & 0 deletions src/types/aiApiClient/Completions/InlineCompletions.ts
Original file line number Diff line number Diff line change
@@ -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;
};
149 changes: 0 additions & 149 deletions src/types/aiApiClient/aiApiClientTypes.ts

This file was deleted.

27 changes: 27 additions & 0 deletions src/types/aiApiClient/enums/commandSource.ts
Original file line number Diff line number Diff line change
@@ -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'
}
14 changes: 14 additions & 0 deletions src/types/aiApiClient/index.ts
Original file line number Diff line number Diff line change
@@ -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';
84 changes: 84 additions & 0 deletions src/types/aiApiClient/types/ApiClient.ts
Original file line number Diff line number Diff line change
@@ -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<string, FeedbackCustomContextValues>;
};
};

/**
* 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<Completion<AiCompletion>[]>;

/**
* 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<Completion<AiCompletion>[]>;

/**
* 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<void>;
}
10 changes: 10 additions & 0 deletions src/types/aiApiClient/types/PromptStoreEntry.ts
Original file line number Diff line number Diff line change
@@ -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 }
];
Loading

0 comments on commit a136ab6

Please sign in to comment.