diff --git a/package-lock.json b/package-lock.json index 400cd6a630..db0634746e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7395,9 +7395,9 @@ "integrity": "sha512-FjI8Zf+MAPwWu+ViXurGk2Ka3H7QDzLUqGulu22ONzmiidz63Lp3N2uzDQ/p7RAsIpC27ZLxomRlje4WhOjuXg==" }, "node_modules/@salesforce/vscode-service-provider": { - "version": "1.3.0-rc.3", - "resolved": "https://registry.npmjs.org/@salesforce/vscode-service-provider/-/vscode-service-provider-1.3.0-rc.3.tgz", - "integrity": "sha512-E0RbJaoF6HaLn9ing8eNIiKhlPxW/o5zW1P2FSg5v7lwizj2QaQinrolR5DsmGXEqefVfuoiYHb3Uy6dbGNKUg==", + "version": "1.3.0-rc.6.3", + "resolved": "https://registry.npmjs.org/@salesforce/vscode-service-provider/-/vscode-service-provider-1.3.0-rc.6.3.tgz", + "integrity": "sha512-4It/mYoCqTWbhQC5YDTGGdNF9PbCR09HY+7jSKkUgYdFoSgoyTQUoueeSLs/3DNudF1kai0rHbs/PLrf/X00iQ==", "engines": { "node": ">=18.18.2" } @@ -32885,7 +32885,7 @@ "@salesforce/core-bundle": "8.6.1", "@salesforce/source-deploy-retrieve-bundle": "12.7.4", "@salesforce/source-tracking-bundle": "7.1.17", - "@salesforce/vscode-service-provider": "1.3.0-rc.3", + "@salesforce/vscode-service-provider": "1.3.0-rc.6.3", "applicationinsights": "1.0.7", "cross-spawn": "7.0.6", "rxjs": "^5.4.1", @@ -33028,7 +33028,7 @@ "@salesforce/apex-tmlanguage": "1.8.0", "@salesforce/core-bundle": "8.6.1", "@salesforce/salesforcedx-utils-vscode": "62.13.0", - "@salesforce/vscode-service-provider": "1.3.0-rc.3", + "@salesforce/vscode-service-provider": "1.3.0-rc.6.3", "expand-home-dir": "0.0.3", "find-java-home": "0.2.0", "shelljs": "0.8.5", @@ -33425,7 +33425,7 @@ "@salesforce/source-deploy-retrieve-bundle": "12.7.4", "@salesforce/templates": "62.0.1", "@salesforce/ts-types": "2.0.12", - "@salesforce/vscode-service-provider": "1.3.0-rc.3", + "@salesforce/vscode-service-provider": "1.3.0-rc.6.3", "adm-zip": "0.5.10", "applicationinsights": "1.0.7", "glob": "^7.1.2", diff --git a/packages/salesforcedx-utils-vscode/package.json b/packages/salesforcedx-utils-vscode/package.json index 5366c5890d..8e91bf4118 100644 --- a/packages/salesforcedx-utils-vscode/package.json +++ b/packages/salesforcedx-utils-vscode/package.json @@ -13,7 +13,7 @@ "@salesforce/core-bundle": "8.6.1", "@salesforce/source-deploy-retrieve-bundle": "12.7.4", "@salesforce/source-tracking-bundle": "7.1.17", - "@salesforce/vscode-service-provider": "1.3.0-rc.3", + "@salesforce/vscode-service-provider": "1.3.0-rc.6.3", "applicationinsights": "1.0.7", "cross-spawn": "7.0.6", "rxjs": "^5.4.1", diff --git a/packages/salesforcedx-vscode-apex/package.json b/packages/salesforcedx-vscode-apex/package.json index fb2f4ecc1c..edce913f11 100644 --- a/packages/salesforcedx-vscode-apex/package.json +++ b/packages/salesforcedx-vscode-apex/package.json @@ -28,7 +28,7 @@ "@salesforce/apex-tmlanguage": "1.8.0", "@salesforce/core-bundle": "8.6.1", "@salesforce/salesforcedx-utils-vscode": "62.13.0", - "@salesforce/vscode-service-provider": "1.3.0-rc.3", + "@salesforce/vscode-service-provider": "1.3.0-rc.6.3", "expand-home-dir": "0.0.3", "find-java-home": "0.2.0", "shelljs": "0.8.5", diff --git a/packages/salesforcedx-vscode-apex/src/commands/apexActionController.ts b/packages/salesforcedx-vscode-apex/src/commands/apexActionController.ts index 4a91561b97..5d3a465f27 100644 --- a/packages/salesforcedx-vscode-apex/src/commands/apexActionController.ts +++ b/packages/salesforcedx-vscode-apex/src/commands/apexActionController.ts @@ -11,7 +11,6 @@ import * as fs from 'fs'; import * as path from 'path'; import { URL } from 'url'; import * as vscode from 'vscode'; -import { parse, stringify } from 'yaml'; import { workspaceContext } from '../context'; import { nls } from '../messages'; import { ApexClassOASEligibleResponse, ApexClassOASGatherContextResponse } from '../openApiUtilities/schemas'; @@ -115,12 +114,16 @@ export class ApexActionController { if (openApiIndex === -1) { throw new Error('Could not find openapi line in document:\n' + doc); } - const theDoc = doc + // const theDoc = doc + // .substring(openApiIndex) + // .split('\n') + // .filter(line => !/^```$/.test(line)) + // .join('\n'); + return doc .substring(openApiIndex) .split('\n') - .filter((line: string) => !line.includes('{AUTHOR_PLACEHOLDER}')) + .filter(line => !/^```$/.test(line)) .join('\n'); - return stringify(parse(theDoc)); } private saveOasAsErsMetadata = async (oasSpec: string, fullPath: string): Promise => { @@ -239,7 +242,7 @@ export class ApexActionController { oasSpec: string ) => { const baseName = path.basename(fullPath).split('.')[0]; - const safeOasSpec = oasSpec.replaceAll('"', '''); + const safeOasSpec = oasSpec.replaceAll('"', ''').replaceAll('type: Id', 'type: string'); const parser = new XMLParser({ ignoreAttributes: false }); let jsonObj; @@ -255,6 +258,7 @@ export class ApexActionController { } else { // Create a new XML structure jsonObj = { + '?xml': { '@_version': '1.0', '@_encoding': 'UTF-8' }, ExternalServiceRegistration: { '@_xmlns': 'http://soap.sforce.com/2006/04/metadata', description: `${baseName} External Service`, diff --git a/packages/salesforcedx-vscode-apex/src/commands/metadataOrchestrator.ts b/packages/salesforcedx-vscode-apex/src/commands/metadataOrchestrator.ts index a9b463a457..f6f09ecb42 100644 --- a/packages/salesforcedx-vscode-apex/src/commands/metadataOrchestrator.ts +++ b/packages/salesforcedx-vscode-apex/src/commands/metadataOrchestrator.ts @@ -4,7 +4,7 @@ * 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 { AiApiClient, CommandSource, ServiceProvider, ServiceType } from '@salesforce/vscode-service-provider'; +import { LLMServiceInterface, ServiceProvider, ServiceType } from '@salesforce/vscode-service-provider'; import * as path from 'path'; import * as vscode from 'vscode'; import { languageClientUtils } from '../languageUtils'; @@ -198,28 +198,16 @@ export class MetadataOrchestrator { const input = `${systemTag}\n${systemPrompt}\n\n${endOfPromptTag}\n${userTag}\n` + userPrompt + - '\n\n***Code Context***\n```\n' + + '\nThis is the Apex class the OpenAPI v3 specification should be generated for:\n```\n' + editorText + `\nClass name: ${context.classDetail.name}, methods: ${context.methods.map(method => method.name).join(', ')}\n` + `\n\`\`\`\n${endOfPromptTag}\n${assistantTag}`; + console.log('input = ' + input); - let result; let documentContents = ''; - let tries = 0; try { - const apiClient = await this.getAiApiClient(); - while (!documentContents.startsWith('yaml') && tries < 10) { - result = await apiClient.naturalLanguageQuery({ - prefix: '', - suffix: '', - input, - commandSource: CommandSource.NLtoCodeGen, - promptId: 'generateOpenAPIv3Specifications' - }); - documentContents = result[0].completion; - if (documentContents.includes('try again')) tries++; - } - if (tries === 10) throw new Error(documentContents); + const llmService = await this.getLLMServiceInterface(); + documentContents = await llmService.callLLM(input); } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); throw new Error(errorMessage); @@ -228,7 +216,7 @@ export class MetadataOrchestrator { return documentContents; }; - getAiApiClient = async (): Promise => { - return ServiceProvider.getService(ServiceType.AiApiClient); + getLLMServiceInterface = async (): Promise => { + return ServiceProvider.getService(ServiceType.LLMService, 'salesforcedx-vscode'); }; } diff --git a/packages/salesforcedx-vscode-core/package.json b/packages/salesforcedx-vscode-core/package.json index 317bc8d5e4..30a7ae740d 100644 --- a/packages/salesforcedx-vscode-core/package.json +++ b/packages/salesforcedx-vscode-core/package.json @@ -32,7 +32,7 @@ "@salesforce/source-deploy-retrieve-bundle": "12.7.4", "@salesforce/templates": "62.0.1", "@salesforce/ts-types": "2.0.12", - "@salesforce/vscode-service-provider": "1.3.0-rc.3", + "@salesforce/vscode-service-provider": "1.3.0-rc.6.3", "adm-zip": "0.5.10", "applicationinsights": "1.0.7", "glob": "^7.1.2",