@salesforce/agents 0.19.8 → 0.20.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +2 -0
  2. package/lib/agent.d.ts +25 -86
  3. package/lib/agent.js +85 -310
  4. package/lib/agent.js.map +1 -1
  5. package/lib/agentTest.js +1 -1
  6. package/lib/agentTestResults.js +1 -1
  7. package/lib/agentTester.js +1 -1
  8. package/lib/agents/agentBase.d.ts +82 -0
  9. package/lib/agents/agentBase.js +106 -0
  10. package/lib/agents/agentBase.js.map +1 -0
  11. package/lib/agents/productionAgent.d.ts +51 -0
  12. package/lib/agents/productionAgent.js +336 -0
  13. package/lib/agents/productionAgent.js.map +1 -0
  14. package/lib/agents/scriptAgent.d.ts +61 -0
  15. package/lib/agents/scriptAgent.js +502 -0
  16. package/lib/agents/scriptAgent.js.map +1 -0
  17. package/lib/{agentPublisher.d.ts → agents/scriptAgentPublisher.d.ts} +26 -10
  18. package/lib/{agentPublisher.js → agents/scriptAgentPublisher.js} +50 -24
  19. package/lib/agents/scriptAgentPublisher.js.map +1 -0
  20. package/lib/apexUtils.d.ts +1 -0
  21. package/lib/apexUtils.js +11 -1
  22. package/lib/apexUtils.js.map +1 -1
  23. package/lib/index.d.ts +4 -5
  24. package/lib/index.js +8 -10
  25. package/lib/index.js.map +1 -1
  26. package/lib/maybe-mock.js +1 -1
  27. package/lib/types.d.ts +22 -8
  28. package/lib/types.js +1 -1
  29. package/lib/types.js.map +1 -1
  30. package/lib/utils.d.ts +36 -4
  31. package/lib/utils.js +69 -13
  32. package/lib/utils.js.map +1 -1
  33. package/package.json +1 -1
  34. package/lib/agentPreview.d.ts +0 -70
  35. package/lib/agentPreview.js +0 -247
  36. package/lib/agentPreview.js.map +0 -1
  37. package/lib/agentPreviewBase.d.ts +0 -51
  38. package/lib/agentPreviewBase.js +0 -55
  39. package/lib/agentPreviewBase.js.map +0 -1
  40. package/lib/agentPublisher.js.map +0 -1
  41. package/lib/agentSimulate.d.ts +0 -78
  42. package/lib/agentSimulate.js +0 -286
  43. package/lib/agentSimulate.js.map +0 -1
  44. package/lib/agentTrace.d.ts +0 -23
  45. package/lib/agentTrace.js +0 -47
  46. package/lib/agentTrace.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  /*
3
- * Copyright 2025, Salesforce, Inc.
3
+ * Copyright 2026, Salesforce, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -0,0 +1,82 @@
1
+ import { Connection } from '@salesforce/core';
2
+ import { type AgentPreviewEndResponse, type AgentPreviewSendResponse, type AgentPreviewStartResponse, type PlannerResponse } from '../types';
3
+ /**
4
+ * Common preview interface that both ScriptAgent and ProductionAgent implement
5
+ */
6
+ export type AgentPreviewInterface = {
7
+ start: (...args: unknown[]) => Promise<AgentPreviewStartResponse>;
8
+ send: (message: string) => Promise<AgentPreviewSendResponse>;
9
+ getAllTraces: () => Promise<PlannerResponse[]>;
10
+ end: (...args: unknown[]) => Promise<AgentPreviewEndResponse>;
11
+ saveSession: (outputDir?: string) => Promise<string>;
12
+ setApexDebugging: (apexDebugging: boolean) => void;
13
+ };
14
+ /**
15
+ * Abstract base class for agent preview functionality.
16
+ * Contains shared properties and methods between ScriptAgent and ProductionAgent.
17
+ */
18
+ export declare abstract class AgentBase {
19
+ protected readonly connection: Connection;
20
+ /**
21
+ * The display name of the agent (user-friendly name, not API name)
22
+ */
23
+ name: string | undefined;
24
+ protected sessionId: string | undefined;
25
+ protected sessionDir: string | undefined;
26
+ protected apexDebugging: boolean | undefined;
27
+ protected planIds: Set<string>;
28
+ abstract preview: AgentPreviewInterface;
29
+ protected constructor(connection: Connection);
30
+ restoreConnection(): Promise<void>;
31
+ /**
32
+ * Get all traces from the current session
33
+ * Reads traces from the session directory if available, otherwise fetches from API
34
+ */
35
+ protected getAllTracesFromDisc(): Promise<PlannerResponse[]>;
36
+ /**
37
+ * Save the complete session data to disk by copying the session directory.
38
+ * The session directory is already populated during the session with:
39
+ * - Transcript entries (transcript.jsonl)
40
+ * - Traces (traces/*.json)
41
+ * - Session metadata (metadata.json)
42
+ *
43
+ * Session directory structure:
44
+ * .sfdx/agents/<agentId>/sessions/<sessionId>/
45
+ * ├── transcript.jsonl # All transcript entries (one per line)
46
+ * ├── traces/ # Individual trace files
47
+ * │ ├── <planId1>.json
48
+ * │ └── <planId2>.json
49
+ * └── metadata.json # Session metadata (start time, end time, planIds, etc.)
50
+ *
51
+ * @param outputDir Optional output directory. If not provided, uses default location.
52
+ * @returns The path to the copied session directory
53
+ */
54
+ protected saveSessionToDisc(outputDir: string): Promise<string>;
55
+ /**
56
+ * Set the Apex debugging mode for the agent preview.
57
+ * This can be called before starting a session.
58
+ *
59
+ * @param apexDebugging true to enable Apex debugging, false to disable
60
+ */
61
+ protected setApexDebugging(apexDebugging: boolean): void;
62
+ /**
63
+ * Send a message to the agent using the session ID obtained by calling `start()`.
64
+ *
65
+ * @param message A message to send to the agent.
66
+ * @returns `AgentPreviewSendResponse`
67
+ */
68
+ protected abstract sendMessage(message: string): Promise<AgentPreviewSendResponse>;
69
+ /**
70
+ * Get the agent ID to use for storage/transcript purposes
71
+ */
72
+ protected abstract getAgentIdForStorage(): string | Promise<string>;
73
+ /**
74
+ * Check if Apex debugging should be enabled for this agent type
75
+ */
76
+ protected abstract canApexDebug(): boolean;
77
+ /**
78
+ * Handle Apex debugging setup before sending a message
79
+ */
80
+ protected abstract handleApexDebuggingSetup(): Promise<void>;
81
+ protected abstract getTrace(planId: string): Promise<PlannerResponse | undefined>;
82
+ }
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AgentBase = void 0;
4
+ /*
5
+ * Copyright 2026, Salesforce, Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ const promises_1 = require("node:fs/promises");
20
+ const node_path_1 = require("node:path");
21
+ const core_1 = require("@salesforce/core");
22
+ const utils_1 = require("../utils");
23
+ /**
24
+ * Abstract base class for agent preview functionality.
25
+ * Contains shared properties and methods between ScriptAgent and ProductionAgent.
26
+ */
27
+ class AgentBase {
28
+ connection;
29
+ /**
30
+ * The display name of the agent (user-friendly name, not API name)
31
+ */
32
+ name;
33
+ sessionId;
34
+ sessionDir;
35
+ apexDebugging;
36
+ planIds = new Set();
37
+ constructor(connection) {
38
+ this.connection = connection;
39
+ }
40
+ async restoreConnection() {
41
+ delete this.connection.accessToken;
42
+ await this.connection.refreshAuth();
43
+ }
44
+ /**
45
+ * Get all traces from the current session
46
+ * Reads traces from the session directory if available, otherwise fetches from API
47
+ */
48
+ async getAllTracesFromDisc() {
49
+ if (!this.sessionDir) {
50
+ throw core_1.SfError.create({ message: 'history never created' });
51
+ }
52
+ const traces = [];
53
+ // If we have a session directory, try reading traces from disk first
54
+ const tracesDir = (0, node_path_1.join)(this.sessionDir, 'traces');
55
+ const files = await (0, promises_1.readdir)(tracesDir);
56
+ const tracePromises = files
57
+ .filter((file) => file.endsWith('.json'))
58
+ .map(async (file) => {
59
+ const traceData = await (0, promises_1.readFile)((0, node_path_1.join)(tracesDir, file), 'utf-8');
60
+ return JSON.parse(traceData);
61
+ });
62
+ traces.push(...(await Promise.all(tracePromises)));
63
+ return traces;
64
+ }
65
+ /**
66
+ * Save the complete session data to disk by copying the session directory.
67
+ * The session directory is already populated during the session with:
68
+ * - Transcript entries (transcript.jsonl)
69
+ * - Traces (traces/*.json)
70
+ * - Session metadata (metadata.json)
71
+ *
72
+ * Session directory structure:
73
+ * .sfdx/agents/<agentId>/sessions/<sessionId>/
74
+ * ├── transcript.jsonl # All transcript entries (one per line)
75
+ * ├── traces/ # Individual trace files
76
+ * │ ├── <planId1>.json
77
+ * │ └── <planId2>.json
78
+ * └── metadata.json # Session metadata (start time, end time, planIds, etc.)
79
+ *
80
+ * @param outputDir Optional output directory. If not provided, uses default location.
81
+ * @returns The path to the copied session directory
82
+ */
83
+ async saveSessionToDisc(outputDir) {
84
+ if (!this.sessionId || !this.sessionDir) {
85
+ throw core_1.SfError.create({ name: 'noSessionId', message: 'No active session. Call .start() first.' });
86
+ }
87
+ const agentId = await this.getAgentIdForStorage();
88
+ // Determine output directory
89
+ const destDir = (0, node_path_1.join)(outputDir, agentId, `session_${this.sessionId}`);
90
+ // Copy the entire session directory from .sfdx to the output directory
91
+ // This includes transcript.jsonl, traces/, and metadata.json
92
+ await (0, utils_1.copyDirectory)(this.sessionDir, destDir);
93
+ return destDir;
94
+ }
95
+ /**
96
+ * Set the Apex debugging mode for the agent preview.
97
+ * This can be called before starting a session.
98
+ *
99
+ * @param apexDebugging true to enable Apex debugging, false to disable
100
+ */
101
+ setApexDebugging(apexDebugging) {
102
+ this.apexDebugging = apexDebugging;
103
+ }
104
+ }
105
+ exports.AgentBase = AgentBase;
106
+ //# sourceMappingURL=agentBase.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agentBase.js","sourceRoot":"","sources":["../../src/agents/agentBase.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,+CAAqD;AACrD,yCAAiC;AACjC,2CAAuD;AAOvD,oCAAyC;AAczC;;;GAGG;AACH,MAAsB,SAAS;IAWY;IAVzC;;OAEG;IACI,IAAI,CAAqB;IACtB,SAAS,CAAqB;IAC9B,UAAU,CAAqB;IAC/B,aAAa,CAAsB;IACnC,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;IAGtC,YAAyC,UAAsB;QAAtB,eAAU,GAAV,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M,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,OAAO,EAAE,yCAAyC,EAAE,CAAC,CAAC;QACpG,CAAC;QAED,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAElD,6BAA6B;QAC7B,MAAM,OAAO,GAAG,IAAA,gBAAI,EAAC,SAAS,EAAE,OAAO,EAAE,WAAW,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC;QAEtE,uEAAuE;QACvE,6DAA6D;QAC7D,MAAM,IAAA,qBAAa,EAAC,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;QAE9C,OAAO,OAAO,CAAC;IACjB,CAAC;IAED;;;;;OAKG;IACO,gBAAgB,CAAC,aAAsB;QAC/C,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC;IACrC,CAAC;CAyBF;AA7GD,8BA6GC"}
@@ -0,0 +1,51 @@
1
+ import { type AgentPreviewSendResponse, type BotMetadata, type BotVersionMetadata, PlannerResponse, ProductionAgentOptions } from '../types';
2
+ import { AgentBase, type AgentPreviewInterface } from './agentBase';
3
+ export declare class ProductionAgent extends AgentBase {
4
+ private options;
5
+ preview: AgentPreviewInterface;
6
+ private botMetadata;
7
+ private id;
8
+ private apiName;
9
+ private apiBase;
10
+ constructor(options: ProductionAgentOptions);
11
+ getBotMetadata(): Promise<BotMetadata>;
12
+ /**
13
+ * Returns the latest bot version metadata.
14
+ *
15
+ * @returns the latest bot version metadata
16
+ */
17
+ getLatestBotVersionMetadata(): Promise<BotVersionMetadata>;
18
+ getTrace(planId: string): Promise<PlannerResponse | undefined>;
19
+ /**
20
+ * Returns the ID for this agent.
21
+ *
22
+ * @returns The ID of the agent (The `Bot` ID).
23
+ */
24
+ getId(): Promise<string>;
25
+ /**
26
+ * Activates the agent.
27
+ *
28
+ * @returns void
29
+ */
30
+ activate(): Promise<void>;
31
+ /**
32
+ * Deactivates the agent.
33
+ *
34
+ * @returns void
35
+ */
36
+ deactivate(): Promise<void>;
37
+ protected getAgentIdForStorage(): string;
38
+ protected canApexDebug(): boolean;
39
+ protected handleApexDebuggingSetup(): Promise<void>;
40
+ protected sendMessage(message: string): Promise<AgentPreviewSendResponse>;
41
+ private setAgentStatus;
42
+ private startPreview;
43
+ /**
44
+ * Ends an interactive session with the agent.
45
+ *
46
+ * @param sessionId A session ID provided by first calling `agentPreview.start()`.
47
+ * @param reason A reason why the interactive session was ended.
48
+ * @returns `AgentPreviewEndResponse`
49
+ */
50
+ private endSession;
51
+ }
@@ -0,0 +1,336 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProductionAgent = void 0;
4
+ /*
5
+ * Copyright 2026, Salesforce, Inc.
6
+ *
7
+ * Licensed under the Apache License, Version 2.0 (the "License");
8
+ * you may not use this file except in compliance with the License.
9
+ * You may obtain a copy of the License at
10
+ *
11
+ * http://www.apache.org/licenses/LICENSE-2.0
12
+ *
13
+ * Unless required by applicable law or agreed to in writing, software
14
+ * distributed under the License is distributed on an "AS IS" BASIS,
15
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
+ * See the License for the specific language governing permissions and
17
+ * limitations under the License.
18
+ */
19
+ const node_crypto_1 = require("node:crypto");
20
+ const core_1 = require("@salesforce/core");
21
+ const maybe_mock_1 = require("../maybe-mock");
22
+ const utils_1 = require("../utils");
23
+ const apexUtils_1 = require("../apexUtils");
24
+ const agentBase_1 = require("./agentBase");
25
+ ;
26
+ const messages = new core_1.Messages('@salesforce/agents', 'agents', new Map([["invalidAgentSpecConfig", "Missing one or more of the required agent spec arguments: type, role, companyName, companyDescription"], ["missingAgentName", "The \"agentName\" configuration property is required when saving an agent."], ["agentRetrievalError", "Unable to retrieve newly created Agent metadata. Due to: %s"], ["agentRetrievalErrorActions", "Retrieve the agent metadata using the \"project retrieve start\" command."], ["missingAgentNameOrId", "The \"nameOrId\" agent option is required when creating an Agent instance."], ["agentIsDeleted", "The %s agent has been deleted and its activation state can't be changed."], ["agentActivationError", "Changing the agent's activation status was unsuccessful due to %s."]]));
27
+ class ProductionAgent extends agentBase_1.AgentBase {
28
+ options;
29
+ preview;
30
+ botMetadata;
31
+ id;
32
+ apiName;
33
+ apiBase = `https://${(0, utils_1.getEndpoint)()}api.salesforce.com/einstein/ai-agent/v1`;
34
+ constructor(options) {
35
+ super(options.connection);
36
+ this.options = options;
37
+ if (!options.apiNameOrId) {
38
+ throw messages.createError('missingAgentNameOrId');
39
+ }
40
+ this.preview = {
41
+ start: (apexDebugging) => this.startPreview(apexDebugging),
42
+ send: (message) => this.sendMessage(message),
43
+ getAllTraces: () => this.getAllTracesFromDisc(),
44
+ end: (reason) => this.endSession(reason),
45
+ saveSession: (outputDir) => this.saveSessionToDisc(outputDir),
46
+ setApexDebugging: (apexDebugging) => this.setApexDebugging(apexDebugging),
47
+ };
48
+ if (options.apiNameOrId.startsWith('0Xx') && [15, 18].includes(options.apiNameOrId.length)) {
49
+ this.id = options.apiNameOrId;
50
+ }
51
+ else {
52
+ this.apiName = options.apiNameOrId;
53
+ }
54
+ }
55
+ async getBotMetadata() {
56
+ if (!this.botMetadata) {
57
+ const whereClause = this.id ? `Id = '${this.id}'` : `DeveloperName = '${this.apiName}'`;
58
+ this.botMetadata = await this.connection.singleRecordQuery(`SELECT FIELDS(ALL), (SELECT FIELDS(ALL) FROM BotVersions LIMIT 10) FROM BotDefinition WHERE ${whereClause} LIMIT 1`);
59
+ this.id = this.botMetadata.Id;
60
+ this.apiName = this.botMetadata.DeveloperName;
61
+ // Set the display name from MasterLabel
62
+ this.name = this.botMetadata.MasterLabel;
63
+ }
64
+ return this.botMetadata;
65
+ }
66
+ /**
67
+ * Returns the latest bot version metadata.
68
+ *
69
+ * @returns the latest bot version metadata
70
+ */
71
+ async getLatestBotVersionMetadata() {
72
+ if (!this.botMetadata) {
73
+ this.botMetadata = await this.getBotMetadata();
74
+ }
75
+ const botVersions = this.botMetadata.BotVersions.records;
76
+ return botVersions[botVersions.length - 1];
77
+ }
78
+ // eslint-disable-next-line @typescript-eslint/require-await,class-methods-use-this,@typescript-eslint/no-unused-vars
79
+ async getTrace(planId) {
80
+ // return this.connection.request<PlannerResponse>({
81
+ // method: 'GET',
82
+ // url: `${this.connection.getConnectionOptions().instanceUrl!}:9443/proxy/worker/internal/sessions/${this
83
+ // .sessionId!}/plans/${planId}`,
84
+ // headers: {
85
+ // 'x-client-name': 'afdx',
86
+ // },
87
+ // });
88
+ return undefined;
89
+ }
90
+ /**
91
+ * Returns the ID for this agent.
92
+ *
93
+ * @returns The ID of the agent (The `Bot` ID).
94
+ */
95
+ async getId() {
96
+ if (!this.id) {
97
+ await this.getBotMetadata();
98
+ }
99
+ return this.id; // getBotMetadata() ensures this.id is not undefined
100
+ }
101
+ /**
102
+ * Activates the agent.
103
+ *
104
+ * @returns void
105
+ */
106
+ async activate() {
107
+ return this.setAgentStatus('Active');
108
+ }
109
+ /**
110
+ * Deactivates the agent.
111
+ *
112
+ * @returns void
113
+ */
114
+ async deactivate() {
115
+ return this.setAgentStatus('Inactive');
116
+ }
117
+ getAgentIdForStorage() {
118
+ if (!this.id) {
119
+ throw core_1.SfError.create({ name: 'noId', message: 'Agent ID not found. Call .getBotMetadata() first.' });
120
+ }
121
+ return this.id;
122
+ }
123
+ // eslint-disable-next-line class-methods-use-this
124
+ canApexDebug() {
125
+ return true;
126
+ }
127
+ async handleApexDebuggingSetup() {
128
+ const botMetadata = await this.getBotMetadata();
129
+ if (botMetadata.BotUserId) {
130
+ const traceFlag = await (0, apexUtils_1.findTraceFlag)(this.connection, botMetadata.BotUserId);
131
+ if (!traceFlag) {
132
+ await (0, apexUtils_1.createTraceFlag)(this.connection, botMetadata.BotUserId);
133
+ }
134
+ }
135
+ }
136
+ async sendMessage(message) {
137
+ if (!this.sessionId) {
138
+ throw core_1.SfError.create({ name: 'noSessionId', message: 'Agent not started, please call .start() first' });
139
+ }
140
+ const url = `${this.apiBase}/sessions/${this.sessionId}/messages`;
141
+ const body = {
142
+ message: {
143
+ sequenceId: Date.now(),
144
+ type: 'Text',
145
+ text: message,
146
+ },
147
+ variables: [],
148
+ };
149
+ try {
150
+ const start = Date.now();
151
+ // Handle Apex debugging setup if needed
152
+ if (this.apexDebugging && this.canApexDebug()) {
153
+ await this.handleApexDebuggingSetup();
154
+ }
155
+ const agentId = this.getAgentIdForStorage();
156
+ // Ensure session directory exists
157
+ if (!this.sessionDir) {
158
+ this.sessionDir = await (0, utils_1.getSessionDir)(agentId, this.sessionId);
159
+ }
160
+ void (0, utils_1.appendTranscriptEntryToSession)({
161
+ timestamp: new Date().toISOString(),
162
+ agentId,
163
+ sessionId: this.sessionId,
164
+ role: 'user',
165
+ text: message,
166
+ }, this.sessionDir);
167
+ const response = await this.connection.request({
168
+ method: 'POST',
169
+ url,
170
+ body: JSON.stringify(body),
171
+ headers: {
172
+ 'x-client-name': 'afdx',
173
+ },
174
+ });
175
+ const planId = response.messages.at(0).planId;
176
+ this.planIds.add(planId);
177
+ await (0, utils_1.appendTranscriptEntryToSession)({
178
+ timestamp: new Date().toISOString(),
179
+ agentId,
180
+ sessionId: this.sessionId,
181
+ role: 'agent',
182
+ text: response.messages.at(0)?.message,
183
+ raw: response.messages,
184
+ }, this.sessionDir);
185
+ // Fetch and write trace immediately if available
186
+ if (planId) {
187
+ try {
188
+ const trace = await this.getTrace(planId);
189
+ await (0, utils_1.writeTraceToSession)(planId, trace, this.sessionDir);
190
+ }
191
+ catch (error) {
192
+ throw core_1.SfError.wrap(error);
193
+ }
194
+ }
195
+ if (this.apexDebugging && this.canApexDebug()) {
196
+ const apexLog = await (0, apexUtils_1.getDebugLog)(this.connection, start, Date.now());
197
+ if (apexLog) {
198
+ response.apexDebugLog = apexLog;
199
+ }
200
+ }
201
+ return response;
202
+ }
203
+ catch (err) {
204
+ throw core_1.SfError.wrap(err);
205
+ }
206
+ }
207
+ async setAgentStatus(desiredState) {
208
+ const botMetadata = await this.getBotMetadata();
209
+ const botVersionMetadata = await this.getLatestBotVersionMetadata();
210
+ if (botMetadata.IsDeleted) {
211
+ throw messages.createError('agentIsDeleted', [botMetadata.DeveloperName]);
212
+ }
213
+ if (botVersionMetadata.Status === desiredState) {
214
+ return;
215
+ }
216
+ const url = `/connect/bot-versions/${botVersionMetadata.Id}/activation`;
217
+ const maybeMock = new maybe_mock_1.MaybeMock(this.connection);
218
+ const response = await maybeMock.request('POST', url, { status: desiredState });
219
+ if (response.success) {
220
+ this.botMetadata.BotVersions.records[0].Status = response.isActivated ? 'Active' : 'Inactive';
221
+ }
222
+ else {
223
+ throw messages.createError('agentActivationError', [response.messages?.toString() ?? 'unknown']);
224
+ }
225
+ }
226
+ async startPreview(apexDebugging) {
227
+ if (!this.id) {
228
+ await this.getId();
229
+ }
230
+ const url = `${this.apiBase}/agents/${this.id}/sessions`;
231
+ // Use the provided apexDebugging parameter if given, otherwise keep the previously set one
232
+ if (apexDebugging !== undefined) {
233
+ this.apexDebugging = apexDebugging;
234
+ }
235
+ const body = {
236
+ externalSessionKey: (0, node_crypto_1.randomUUID)(),
237
+ instanceConfig: {
238
+ endpoint: this.options.connection.instanceUrl,
239
+ },
240
+ streamingCapabilities: {
241
+ chunkTypes: ['Text'],
242
+ },
243
+ bypassUser: true,
244
+ };
245
+ try {
246
+ const response = await this.connection.request({
247
+ method: 'POST',
248
+ url,
249
+ body: JSON.stringify(body),
250
+ headers: {
251
+ 'x-client-name': 'afdx',
252
+ },
253
+ });
254
+ this.sessionId = response.sessionId;
255
+ // Initialize session directory and write initial data
256
+ // Session directory structure:
257
+ // .sfdx/agents/<agentId>/sessions/<sessionId>/
258
+ // ├── transcript.jsonl # All transcript entries (one per line)
259
+ // ├── traces/ # Individual trace files
260
+ // │ ├── <planId1>.json
261
+ // │ └── <planId2>.json
262
+ // └── metadata.json # Session metadata (start time, end time, planIds, etc.)
263
+ const agentId = this.id;
264
+ this.sessionDir = await (0, utils_1.getSessionDir)(agentId, response.sessionId);
265
+ await (0, utils_1.appendTranscriptEntryToSession)({
266
+ timestamp: new Date().toISOString(),
267
+ agentId,
268
+ sessionId: response.sessionId,
269
+ role: 'agent',
270
+ text: response.messages.map((m) => m.message).join('\n'),
271
+ raw: response.messages,
272
+ }, this.sessionDir);
273
+ // Write initial metadata
274
+ await (0, utils_1.writeMetadataToSession)(this.sessionDir, {
275
+ sessionId: response.sessionId,
276
+ agentId,
277
+ startTime: new Date().toISOString(),
278
+ apexDebugging: this.apexDebugging,
279
+ planIds: [],
280
+ });
281
+ return response;
282
+ }
283
+ catch (err) {
284
+ throw core_1.SfError.wrap(err);
285
+ }
286
+ }
287
+ /**
288
+ * Ends an interactive session with the agent.
289
+ *
290
+ * @param sessionId A session ID provided by first calling `agentPreview.start()`.
291
+ * @param reason A reason why the interactive session was ended.
292
+ * @returns `AgentPreviewEndResponse`
293
+ */
294
+ async endSession(reason) {
295
+ if (!this.sessionId) {
296
+ throw core_1.SfError.create({ name: 'noSessionId', message: 'please call .start() first' });
297
+ }
298
+ if (!this.id) {
299
+ throw core_1.SfError.create({ name: 'noId', message: 'please call .getId() first' });
300
+ }
301
+ const url = `${this.apiBase}/v1.1/sessions/${this.sessionId}`;
302
+ try {
303
+ // https://developer.salesforce.com/docs/einstein/genai/guide/agent-api-examples.html#end-session
304
+ const response = await this.connection.request({
305
+ method: 'DELETE',
306
+ url,
307
+ headers: {
308
+ 'x-session-end-reason': reason,
309
+ },
310
+ });
311
+ // Write end entry immediately
312
+ if (this.sessionDir) {
313
+ await (0, utils_1.appendTranscriptEntryToSession)({
314
+ timestamp: new Date().toISOString(),
315
+ agentId: this.id,
316
+ sessionId: this.sessionId,
317
+ role: 'agent',
318
+ reason,
319
+ raw: response.messages,
320
+ }, this.sessionDir);
321
+ // Update metadata with end time
322
+ await (0, utils_1.updateMetadataEndTime)(this.sessionDir, new Date().toISOString(), this.planIds);
323
+ }
324
+ // Clear session data for next session
325
+ this.sessionId = undefined;
326
+ this.sessionDir = undefined;
327
+ this.planIds = new Set();
328
+ return response;
329
+ }
330
+ catch (err) {
331
+ throw core_1.SfError.wrap(err);
332
+ }
333
+ }
334
+ }
335
+ exports.ProductionAgent = ProductionAgent;
336
+ //# sourceMappingURL=productionAgent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"productionAgent.js","sourceRoot":"","sources":["../../src/agents/productionAgent.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,6CAAyC;AACzC,2CAAqD;AAYrD,8CAA0C;AAC1C,oCAOkB;AAClB,4CAA2E;AAC3E,2CAAoE;;AAEpE,MAAM,QAAQ,OAAG,eAAQ,CAAc,oBAAoB,EAAE,QAAQ,kuBAAC,CAAC;AAEvE,MAAa,eAAgB,SAAQ,qBAAS;IAOjB;IANpB,OAAO,CAAwB;IAC9B,WAAW,CAA0B;IACrC,EAAE,CAAqB;IACvB,OAAO,CAAqB;IAC5B,OAAO,GAAG,WAAW,IAAA,mBAAW,GAAE,yCAAyC,CAAC;IAEpF,YAA2B,OAA+B;QACxD,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QADD,YAAO,GAAP,OAAO,CAAwB;QAExD,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;YACzB,MAAM,QAAQ,CAAC,WAAW,CAAC,sBAAsB,CAAC,CAAC;QACrD,CAAC;QAED,IAAI,CAAC,OAAO,GAAG;YACb,KAAK,EAAE,CAAC,aAAuB,EAAsC,EAAE,CAAC,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC;YACxG,IAAI,EAAE,CAAC,OAAe,EAAqC,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC;YACvF,YAAY,EAAE,GAA+B,EAAE,CAAC,IAAI,CAAC,oBAAoB,EAAE;YAC3E,GAAG,EAAE,CAAC,MAAiB,EAAoC,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;YACrF,WAAW,EAAE,CAAC,SAAiB,EAAmB,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC;YACtF,g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OAAO,kBAAkB,IAAI,CAAC,SAAS,EAAE,CAAC;QAC9D,IAAI,CAAC;YACH,iGAAiG;YACjG,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,OAAO,CAA0B;gBACtE,MAAM,EAAE,QAAQ;gBAChB,GAAG;gBACH,OAAO,EAAE;oBACP,sBAAsB,EAAE,MAAM;iBAC/B;aACF,CAAC,CAAC;YAEH,8BAA8B;YAC9B,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;gBACpB,MAAM,IAAA,sCAA8B,EAClC;oBACE,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;oBACnC,OAAO,EAAE,IAAI,CAAC,EAAE;oBAChB,SAAS,EAAE,IAAI,CAAC,SAAS;oBACzB,IAAI,EAAE,OAAO;oBACb,MAAM;oBACN,GAAG,EAAE,QAAQ,CAAC,QAAQ;iBACvB,EACD,IAAI,CAAC,UAAU,CAChB,CAAC;gBACF,gCAAgC;gBAChC,MAAM,IAAA,6BAAqB,EAAC,IAAI,CAAC,UAAU,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YACvF,CAAC;YAED,sCAAsC;YACtC,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;YAC3B,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;YAC5B,IAAI,CAAC,OAAO,GAAG,IAAI,GAAG,EAAU,CAAC;YAEjC,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,cAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;CACF;AAjWD,0CAiWC"}
@@ -0,0 +1,61 @@
1
+ import { SfProject } from '@salesforce/core';
2
+ import { type AgentPreviewEndResponse, type AgentPreviewSendResponse, type CompileAgentScriptResponse, ExtendedAgentJobSpec, PlannerResponse, PublishAgent, ScriptAgentOptions } from '../types';
3
+ import { AgentBase, type AgentPreviewInterface } from './agentBase';
4
+ export declare class ScriptAgent extends AgentBase {
5
+ private options;
6
+ preview: AgentPreviewInterface & {
7
+ setMockMode: (mockMode: 'Mock' | 'Live Test') => void;
8
+ };
9
+ private mockMode;
10
+ private agentScriptContent;
11
+ private agentJson;
12
+ private apiBase;
13
+ constructor(options: ScriptAgentOptions);
14
+ /**
15
+ * Creates an AiAuthoringBundle directory, .script file, and -meta.xml file
16
+ *
17
+ * @returns Promise<void>
18
+ * @beta
19
+ * @param options {
20
+ * project: SfProject;
21
+ * bundleApiName: string;
22
+ * outputDir?: string;
23
+ * agentSpec?: ExtendedAgentJobSpec;
24
+ *}
25
+ */
26
+ static createAuthoringBundle(options: {
27
+ project: SfProject;
28
+ bundleApiName: string;
29
+ outputDir?: string;
30
+ agentSpec?: ExtendedAgentJobSpec;
31
+ }): Promise<void>;
32
+ refreshContent(): Promise<void>;
33
+ getTrace(planId: string): Promise<PlannerResponse>;
34
+ /**
35
+ * Compiles AgentScript returning agent JSON when successful, otherwise the compile errors are returned.
36
+ *
37
+ * @returns Promise<CompileAgentScriptResponse> The raw API response
38
+ * @beta
39
+ */
40
+ compile(): Promise<CompileAgentScriptResponse>;
41
+ /**
42
+ * Publish an AgentJson representation to the org
43
+ *
44
+ * @beta
45
+ * @returns {Promise<PublishAgentJsonResponse>} The publish response
46
+ */
47
+ publish(): Promise<PublishAgent>;
48
+ /**
49
+ * Ending is not required
50
+ * this will save all the transcripts to disc
51
+ *
52
+ * @returns `AgentPreviewEndResponse`
53
+ */
54
+ endSession(): Promise<AgentPreviewEndResponse>;
55
+ protected getAgentIdForStorage(): string;
56
+ protected canApexDebug(): boolean;
57
+ protected handleApexDebuggingSetup(): Promise<void>;
58
+ protected sendMessage(message: string): Promise<AgentPreviewSendResponse>;
59
+ private setMockMode;
60
+ private startPreview;
61
+ }