|
5 | 5 | import * as Common from '../common/common.js'; |
6 | 6 | import * as Root from '../root/root.js'; |
7 | 7 |
|
| 8 | +import * as DispatchHttpRequestClient from './DispatchHttpRequestClient.js'; |
8 | 9 | import {InspectorFrontendHostInstance} from './InspectorFrontendHost.js'; |
9 | 10 | import type {AidaClientResult, AidaCodeCompleteResult, SyncInformation} from './InspectorFrontendHostAPI.js'; |
10 | 11 | import {bindOutputStream} from './ResourceLoader.js'; |
@@ -213,6 +214,24 @@ export interface CompleteCodeOptions { |
213 | 214 | } |
214 | 215 | /* eslint-enable @typescript-eslint/naming-convention */ |
215 | 216 |
|
| 217 | +/* eslint-disable @typescript-eslint/naming-convention */ |
| 218 | +export interface GenerateCodeOptions { |
| 219 | + temperature?: number; |
| 220 | + model_id?: string; |
| 221 | + inference_language?: AidaInferenceLanguage; |
| 222 | + expect_code_output?: boolean; |
| 223 | +} |
| 224 | +/* eslint-enable @typescript-eslint/naming-convention */ |
| 225 | + |
| 226 | +/* eslint-disable @typescript-eslint/naming-convention */ |
| 227 | +export interface ContextFile { |
| 228 | + path: string; |
| 229 | + full_content: string; |
| 230 | + selected_content?: string; |
| 231 | + programming_language: AidaInferenceLanguage; |
| 232 | +} |
| 233 | +/* eslint-enable @typescript-eslint/naming-convention */ |
| 234 | + |
216 | 235 | export enum EditType { |
217 | 236 | // Unknown edit type |
218 | 237 | EDIT_TYPE_UNSPECIFIED = 0, |
@@ -269,6 +288,27 @@ export interface CompletionRequest { |
269 | 288 | } |
270 | 289 | /* eslint-enable @typescript-eslint/naming-convention */ |
271 | 290 |
|
| 291 | +export enum UseCase { |
| 292 | + // Unspecified usecase. |
| 293 | + USE_CASE_UNSPECIFIED = 0, |
| 294 | + |
| 295 | + // Code generation use case is expected to generate code from scratch |
| 296 | + CODE_GENERATION = 1, |
| 297 | +} |
| 298 | + |
| 299 | +/* eslint-disable @typescript-eslint/naming-convention */ |
| 300 | +export interface GenerateCodeRequest { |
| 301 | + client: string; |
| 302 | + preamble: string; |
| 303 | + current_message: Content; |
| 304 | + options?: GenerateCodeOptions; |
| 305 | + context_files?: ContextFile[]; |
| 306 | + use_case: UseCase; |
| 307 | + metadata: RequestMetadata; |
| 308 | + client_feature?: ClientFeature; |
| 309 | +} |
| 310 | +/* eslint-enable @typescript-eslint/naming-convention */ |
| 311 | + |
272 | 312 | /* eslint-disable @typescript-eslint/naming-convention */ |
273 | 313 | export interface DoConversationClientEvent { |
274 | 314 | user_feedback: { |
@@ -365,6 +405,11 @@ export interface CompletionResponse { |
365 | 405 | metadata: ResponseMetadata; |
366 | 406 | } |
367 | 407 |
|
| 408 | +export interface GenerateCodeResponse { |
| 409 | + samples: GenerationSample[]; |
| 410 | + metadata: ResponseMetadata; |
| 411 | +} |
| 412 | + |
368 | 413 | export interface GenerationSample { |
369 | 414 | generationString: string; |
370 | 415 | score: number; |
@@ -418,6 +463,7 @@ const AidaLanguageToMarkdown: Record<AidaInferenceLanguage, string> = { |
418 | 463 | }; |
419 | 464 |
|
420 | 465 | export const CLIENT_NAME = 'CHROME_DEVTOOLS'; |
| 466 | +export const SERVICE_NAME = 'aidaService'; |
421 | 467 |
|
422 | 468 | const CODE_CHUNK_SEPARATOR = (lang = ''): string => ('\n`````' + lang + '\n'); |
423 | 469 |
|
@@ -659,6 +705,17 @@ export class AidaClient { |
659 | 705 |
|
660 | 706 | return {generatedSamples, metadata}; |
661 | 707 | } |
| 708 | + |
| 709 | + async generateCode(request: GenerateCodeRequest): Promise<GenerateCodeResponse|null> { |
| 710 | + const response = await DispatchHttpRequestClient.makeHttpRequest<GenerateCodeResponse>({ |
| 711 | + service: SERVICE_NAME, |
| 712 | + path: '/v1/aida:generateCode', |
| 713 | + method: 'POST', |
| 714 | + body: JSON.stringify(request), |
| 715 | + }); |
| 716 | + |
| 717 | + return response; |
| 718 | + } |
662 | 719 | } |
663 | 720 |
|
664 | 721 | export function convertToUserTierEnum(userTier: string|undefined): UserTier { |
|
0 commit comments