UNPKG

sfdx-hardis

Version:

Swiss-army-knife Toolbox for Salesforce. Allows you to define a complete CD/CD Pipeline. Orchestrate base commands and assist users with interactive wizards

66 lines 2.93 kB
import { AiProviderRoot } from "./aiProviderRoot.js"; import c from "chalk"; import { uxLog } from "../utils/index.js"; import { UtilsAi } from "./utils.js"; export class AgentforceProvider extends AiProviderRoot { conn; constructor() { super(); this.conn = globalThis.jsForceConnTechnical || globalThis.jsForceConn; } getLabel() { return "Agentforce connector"; } async promptAi(promptText, template) { if (!this.checkMaxAiCallsNumber()) { const maxCalls = this.getAiMaxCallsNumber(); uxLog(this, c.yellow(`[Agentforce] Already performed maximum ${maxCalls} calls. Increase it by defining AI_MAXIMUM_CALL_NUMBER env variable`)); return null; } if (process.env?.DEBUG_PROMPTS === "true") { uxLog(this, c.grey(`[Agentforce] Requesting the following prompt${template ? (' using template ' + template) : ''}:\n${promptText}`)); } else { uxLog(this, c.grey(`[Agentforce] Requesting prompt${template ? (' using template ' + template) : ''} (define DEBUG_PROMPTS=true to see details)`)); } this.incrementAiCallsNumber(); const genericPromptTemplate = process.env.GENERIC_AGENTFORCE_PROMPT_TEMPLATE || "SfdxHardisGenericPrompt"; const promptUrl = process.env.GENERIC_AGENTFORCE_PROMPT_URL || `/services/data/v${this.conn.getApiVersion()}/einstein/prompt-templates/${genericPromptTemplate}/generations`; const payload = { "isPreview": "false", "inputParams": { "valueMap": { "Input:PromptText": { "value": promptText } } }, "outputLanguage": UtilsAi.getPromptsLanguage(), "additionalConfig": { /* "numGenerations": 1, "temperature": 0, "frequencyPenalty": 0.0, "presencePenalty": 0.0, "additionalParameters": {},*/ "applicationName": "PromptTemplateGenerationsInvocable" } }; const agentforceResponse = await this.conn.requestPost(promptUrl, payload); if (process.env?.DEBUG_PROMPTS === "true") { uxLog(this, c.grey("[Agentforce] Received prompt response\n" + JSON.stringify(agentforceResponse, null, 2))); } else { uxLog(this, c.grey("[Agentforce] Received prompt response")); } const aiResponse = { success: false, model: "Agentforce", }; if (agentforceResponse?.generations?.length > 0 && agentforceResponse.generations[0]?.text) { aiResponse.success = true; aiResponse.promptResponse = agentforceResponse.generations[0]?.text; } return aiResponse; } } //# sourceMappingURL=agentforceProvider.js.map