@salesforce/agents 0.14.13 → 0.14.14-dev.0

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.
package/lib/agent.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Connection, SfProject } from '@salesforce/core';
2
- import { type AgentCreateConfig, type AgentCreateResponse, type AgentJobSpec, type AgentJobSpecCreateConfig, type AgentOptions } from './types.js';
2
+ import { type AgentCreateConfig, type AgentCreateResponse, type AgentJobSpec, type AgentJobSpecCreateConfig, type AgentOptions, type BotMetadata } from './types.js';
3
3
  /**
4
4
  * Events emitted during Agent.create() for consumers to listen to and keep track of progress
5
5
  *
@@ -31,9 +31,11 @@ export declare const AgentCreateLifecycleStages: {
31
31
  export declare class Agent {
32
32
  private options;
33
33
  private id?;
34
+ private name?;
35
+ private botMetadata?;
34
36
  /**
35
37
  * Create an instance of an agent in an org. Must provide a connection to an org
36
- * and the agent (Bot) API name as part of `AgentOptions`.
38
+ * and the agent (Bot) API name or ID as part of `AgentOptions`.
37
39
  *
38
40
  * @param {options} AgentOptions
39
41
  */
@@ -67,4 +69,11 @@ export declare class Agent {
67
69
  * @returns The ID of the agent (The `Bot` ID).
68
70
  */
69
71
  getId(): Promise<string>;
72
+ /**
73
+ * Queries BotDefinition for the bot metadata and assigns:
74
+ * 1. this.id
75
+ * 2. this.name
76
+ * 3. this.botMetadata
77
+ */
78
+ getBotMetadata(): Promise<BotMetadata>;
70
79
  }
package/lib/agent.js CHANGED
@@ -49,7 +49,7 @@ const kit_1 = require("@salesforce/kit");
49
49
  const maybe_mock_1 = require("./maybe-mock");
50
50
  const utils_1 = require("./utils");
51
51
  ;
52
- 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."]]));
52
+ 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."]]));
53
53
  let logger;
54
54
  const getLogger = () => {
55
55
  if (!logger) {
@@ -87,15 +87,29 @@ exports.AgentCreateLifecycleStages = {
87
87
  */
88
88
  class Agent {
89
89
  options;
90
+ // The ID of the agent (Bot)
90
91
  id;
92
+ // The name of the agent (Bot)
93
+ name;
94
+ // The metadata fields for the agent (Bot)
95
+ botMetadata;
91
96
  /**
92
97
  * Create an instance of an agent in an org. Must provide a connection to an org
93
- * and the agent (Bot) API name as part of `AgentOptions`.
98
+ * and the agent (Bot) API name or ID as part of `AgentOptions`.
94
99
  *
95
100
  * @param {options} AgentOptions
96
101
  */
97
102
  constructor(options) {
98
103
  this.options = options;
104
+ if (!options.nameOrId) {
105
+ throw messages.createError('missingAgentNameOrId');
106
+ }
107
+ if (options.nameOrId.startsWith('0Xx') && [15, 18].includes(options.nameOrId.length)) {
108
+ this.id = options.nameOrId;
109
+ }
110
+ else {
111
+ this.name = options.nameOrId;
112
+ }
99
113
  }
100
114
  /**
101
115
  * List all agents in the current project.
@@ -252,10 +266,25 @@ class Agent {
252
266
  */
253
267
  async getId() {
254
268
  if (!this.id) {
255
- const query = `SELECT Id FROM BotDefinition WHERE DeveloperName = '${this.options.name}'`;
256
- this.id = (await this.options.connection.singleRecordQuery(query)).Id;
269
+ await this.getBotMetadata();
270
+ }
271
+ return this.id; // getBotMetadata() ensures this.id is not undefined
272
+ }
273
+ /**
274
+ * Queries BotDefinition for the bot metadata and assigns:
275
+ * 1. this.id
276
+ * 2. this.name
277
+ * 3. this.botMetadata
278
+ */
279
+ async getBotMetadata() {
280
+ if (!this.botMetadata) {
281
+ const whereClause = this.id ? `Id = '${this.id}'` : `DeveloperName = '${this.name}'`;
282
+ const query = `SELECT FIELDS(ALL) FROM BotDefinition WHERE ${whereClause} LIMIT 1`;
283
+ this.botMetadata = await this.options.connection.singleRecordQuery(query);
284
+ this.id = this.botMetadata.Id;
285
+ this.name = this.botMetadata.DeveloperName;
257
286
  }
258
- return this.id;
287
+ return this.botMetadata;
259
288
  }
260
289
  }
261
290
  exports.Agent = Agent;
package/lib/agent.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,yCAAoC;AACpC,gDAAkC;AAClC,+CAAiD;AACjD,2CAAgH;AAChH,+EAAyE;AACzE,yCAA2C;AAU3C,6CAAyC;AACzC,mCAA6C;;AAG7C,MAAM,QAAQ,OAAG,eAAQ,CAAc,oBAAoB,EAAE,QAAQ,0bAAC,CAAC;AAEvE,IAAI,MAAc,CAAC;AACnB,MAAM,SAAS,GAAG,GAAW,EAAE;IAC7B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,GAAG,aAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IACzC,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAEF;;;;GAIG;AACU,QAAA,0BAA0B,GAAG;IACxC,QAAQ,EAAE,eAAe;IACzB,UAAU,EAAE,iBAAiB;IAC7B,UAAU,EAAE,iBAAiB;CAC9B,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAa,KAAK;IASW;IARnB,EAAE,CAAU;IAEpB;;;;;OAKG;IACH,YAA2B,OAAqB;QAArB,YAAO,GAAP,OAAO,CAAc;IAAG,CAAC;IAEpD;;;;OAIG;IACI,MA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,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,oBAAoB,IAAI,CAAC,IAAc,GAAG,CAAC;YAC/F,MAAM,KAAK,GAAG,+CAA+C,WAAW,UAAU,CAAC;YACnF,IAAI,CAAC,WAAW,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,iBAAiB,CAAc,KAAK,CAAC,CAAC;YACvF,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,WAAW,CAAC,EAAE,CAAC;YAC9B,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC;QAC7C,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF;AA5ND,sBA4NC;AAED,8CAA8C;AAC9C,MAAM,qBAAqB,GAAG,CAAC,MAAgC,EAAQ,EAAE;IACvE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,WAAW,EAAE,kBAAkB,EAAE,GAAG,MAAM,CAAC;IACpE,IAAI,CAAC,SAAS,IAAI,CAAC,IAAI,IAAI,CAAC,WAAW,IAAI,CAAC,kBAAkB,EAAE,CAAC;QAC/D,MAAM,QAAQ,CAAC,WAAW,CAAC,wBAAwB,CAAC,CAAC;IACvD,CAAC;AACH,CAAC,CAAC;AAEF,wDAAwD;AACxD,MAAM,cAAc,GAAG,CAAmB,QAAW,EAAK,EAAE,CAC1D,IAAI,CAAC,KAAK,CAAC,IAAA,0BAAkB,EAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAM,CAAC"}
@@ -8,11 +8,11 @@ import { type AgentPreviewEndResponse, type AgentPreviewStartResponse, type Agen
8
8
  *
9
9
  * Create an instance of the service:
10
10
  *
11
- * `const agentPreview = new AgentPreview(connection);`
11
+ * `const agentPreview = new AgentPreview(connection, botId);`
12
12
  *
13
13
  * Start an interactive session:
14
14
  *
15
- * `const { sessionId } = await agentPreview.start(botId);`
15
+ * `const { sessionId } = await agentPreview.start();`
16
16
  *
17
17
  * Send a message to the agent using the session ID from the startResponse:
18
18
  *
@@ -21,19 +21,32 @@ import { type AgentPreviewEndResponse, type AgentPreviewStartResponse, type Agen
21
21
  * End an interactive session:
22
22
  *
23
23
  * `await agentPreview.end(sessionId, 'UserRequest');`
24
+ *
25
+ * Enable Apex Debug Mode:
26
+ *
27
+ * `agentPreview.toggleApexDebugMode(true);`
24
28
  */
25
29
  export declare class AgentPreview {
26
- private apiBase;
27
- private instanceUrl;
30
+ private readonly apiBase;
31
+ private connection;
32
+ private logger;
28
33
  private maybeMock;
29
- constructor(connection: Connection);
34
+ private apexDebugMode?;
35
+ private apexTraceFlag?;
36
+ private botId;
30
37
  /**
31
- * Start an interactive session with the provided agent.
38
+ * Create an instance of the service.
32
39
  *
40
+ * @param connection The connection to use to make requests.
33
41
  * @param botId The ID of the agent (`Bot` ID).
42
+ */
43
+ constructor(connection: Connection, botId: string);
44
+ /**
45
+ * Start an interactive session with the agent.
46
+ *
34
47
  * @returns `AgentPreviewStartResponse`, which includes a session ID needed for other actions.
35
48
  */
36
- start(botId: string): Promise<AgentPreviewStartResponse>;
49
+ start(): Promise<AgentPreviewStartResponse>;
37
50
  /**
38
51
  * Send a message to the agent using the session ID obtained by calling `start()`.
39
52
  *
@@ -56,4 +69,13 @@ export declare class AgentPreview {
56
69
  * @returns `ApiStatus`
57
70
  */
58
71
  status(): Promise<ApiStatus>;
72
+ /**
73
+ * Enable or disable Apex Debug Mode, which will enable trace flags for the Bot user
74
+ * and create apex debug logs for use within VS Code's Apex Replay Debugger.
75
+ *
76
+ * @param enable Whether to enable or disable Apex Debug Mode.
77
+ */
78
+ toggleApexDebugMode(enable: boolean): void;
79
+ private getBotUserId;
80
+ private ensureTraceFlag;
59
81
  }
@@ -9,7 +9,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.AgentPreview = void 0;
10
10
  const node_crypto_1 = require("node:crypto");
11
11
  const core_1 = require("@salesforce/core");
12
+ const agent_1 = require("./agent");
12
13
  const maybe_mock_1 = require("./maybe-mock");
14
+ const apexUtils_1 = require("./apexUtils");
15
+ ;
16
+ const messages = new core_1.Messages('@salesforce/agents', 'agentPreview', new Map([["invalidBotId", "The Bot ID provided must begin with \"0Xx\" and be either 15 or 18 characters. Found: %s"], ["agentApexDebuggingError", "Agent must have a user assigned to enable apex debug mode."]]));
13
17
  /**
14
18
  * A service to interact with an agent. Start an interactive session,
15
19
  * send messages to the agent, and end the session.
@@ -18,11 +22,11 @@ const maybe_mock_1 = require("./maybe-mock");
18
22
  *
19
23
  * Create an instance of the service:
20
24
  *
21
- * `const agentPreview = new AgentPreview(connection);`
25
+ * `const agentPreview = new AgentPreview(connection, botId);`
22
26
  *
23
27
  * Start an interactive session:
24
28
  *
25
- * `const { sessionId } = await agentPreview.start(botId);`
29
+ * `const { sessionId } = await agentPreview.start();`
26
30
  *
27
31
  * Send a message to the agent using the session ID from the startResponse:
28
32
  *
@@ -31,28 +35,46 @@ const maybe_mock_1 = require("./maybe-mock");
31
35
  * End an interactive session:
32
36
  *
33
37
  * `await agentPreview.end(sessionId, 'UserRequest');`
38
+ *
39
+ * Enable Apex Debug Mode:
40
+ *
41
+ * `agentPreview.toggleApexDebugMode(true);`
34
42
  */
35
43
  class AgentPreview {
36
- apiBase;
37
- instanceUrl;
44
+ apiBase = 'https://api.salesforce.com/einstein/ai-agent/v1';
45
+ connection;
46
+ logger;
38
47
  maybeMock;
39
- constructor(connection) {
40
- this.apiBase = 'https://api.salesforce.com/einstein/ai-agent/v1';
41
- this.instanceUrl = connection.instanceUrl;
48
+ apexDebugMode;
49
+ apexTraceFlag;
50
+ botId;
51
+ /**
52
+ * Create an instance of the service.
53
+ *
54
+ * @param connection The connection to use to make requests.
55
+ * @param botId The ID of the agent (`Bot` ID).
56
+ */
57
+ constructor(connection, botId) {
58
+ this.connection = connection;
59
+ this.logger = core_1.Logger.childFromRoot(this.constructor.name);
42
60
  this.maybeMock = new maybe_mock_1.MaybeMock(connection);
61
+ if (!botId.startsWith('0Xx') || ![15, 18].includes(botId.length)) {
62
+ throw messages.createError('invalidBotId', [botId]);
63
+ }
64
+ this.botId = botId;
43
65
  }
44
66
  /**
45
- * Start an interactive session with the provided agent.
67
+ * Start an interactive session with the agent.
46
68
  *
47
- * @param botId The ID of the agent (`Bot` ID).
48
69
  * @returns `AgentPreviewStartResponse`, which includes a session ID needed for other actions.
49
70
  */
50
- async start(botId) {
51
- const url = `${this.apiBase}/agents/${botId}/sessions`;
71
+ async start() {
72
+ const url = `${this.apiBase}/agents/${this.botId}/sessions`;
73
+ this.logger.debug(`Starting agent preview session for botId: ${this.botId}`);
52
74
  const body = {
53
75
  externalSessionKey: (0, node_crypto_1.randomUUID)(),
54
76
  instanceConfig: {
55
- endpoint: this.instanceUrl,
77
+ endpoint: this.connection.instanceUrl,
56
78
  },
57
79
  streamingCapabilities: {
58
80
  chunkTypes: ['Text'],
@@ -85,8 +107,28 @@ class AgentPreview {
85
107
  },
86
108
  variables: [],
87
109
  };
110
+ this.logger.debug(`Sending message to botId: ${this.botId} with apexDebugMode ${this.apexDebugMode ? 'enabled' : 'disabled'}`);
88
111
  try {
89
- return await this.maybeMock.request('POST', url, body);
112
+ // If apex debug mode is enabled, ensure we have a trace flag for the bot user and
113
+ // if there isn't one, create one.
114
+ const start = Date.now();
115
+ if (this.apexDebugMode) {
116
+ await this.ensureTraceFlag();
117
+ }
118
+ const response = await this.maybeMock.request('POST', url, body);
119
+ if (this.apexDebugMode) {
120
+ // get apex debug logs and look for a log within the start and end time
121
+ const apexLog = await (0, apexUtils_1.getDebugLog)(this.connection, start, Date.now());
122
+ if (apexLog) {
123
+ if (apexLog.Id)
124
+ this.logger.debug(`Apex debug log ID for message is ${apexLog.Id}`);
125
+ response.apexDebugLog = apexLog;
126
+ }
127
+ else {
128
+ this.logger.debug('No apex debug log found for this message');
129
+ }
130
+ }
131
+ return response;
90
132
  }
91
133
  catch (err) {
92
134
  throw core_1.SfError.wrap(err);
@@ -101,6 +143,7 @@ class AgentPreview {
101
143
  */
102
144
  async end(sessionId, reason) {
103
145
  const url = `${this.apiBase}/sessions/${sessionId}`;
146
+ this.logger.debug(`Ending agent preview session for botId: ${this.botId} with sessionId: ${sessionId}`);
104
147
  try {
105
148
  // https://developer.salesforce.com/docs/einstein/genai/guide/agent-api-examples.html#end-session
106
149
  return await this.maybeMock.request('DELETE', url, undefined, {
@@ -126,6 +169,46 @@ class AgentPreview {
126
169
  throw core_1.SfError.wrap(err);
127
170
  }
128
171
  }
172
+ /**
173
+ * Enable or disable Apex Debug Mode, which will enable trace flags for the Bot user
174
+ * and create apex debug logs for use within VS Code's Apex Replay Debugger.
175
+ *
176
+ * @param enable Whether to enable or disable Apex Debug Mode.
177
+ */
178
+ toggleApexDebugMode(enable) {
179
+ this.apexDebugMode = enable;
180
+ this.logger.debug(`Apex Debug Mode is now ${enable ? 'enabled' : 'disabled'}`);
181
+ }
182
+ async getBotUserId() {
183
+ const agent = new agent_1.Agent({ connection: this.connection, nameOrId: this.botId });
184
+ const botMetadata = await agent.getBotMetadata();
185
+ return botMetadata.BotUserId;
186
+ }
187
+ // If apex debug mode is enabled, ensure we have a trace flag for the bot user
188
+ // that is not expired checking in this order:
189
+ // 1. instance var (this.apexTraceFlag)
190
+ // 2. query the org
191
+ // 3. create a new trace flag
192
+ async ensureTraceFlag() {
193
+ if (this.apexTraceFlag) {
194
+ const expDate = this.apexTraceFlag.ExpirationDate;
195
+ if (expDate && new Date(expDate) > new Date()) {
196
+ this.logger.debug(`Using cached apexTraceFlag with ExpirationDate of ${expDate}`);
197
+ return;
198
+ }
199
+ else {
200
+ this.logger.debug('Cached apex trace flag is expired');
201
+ }
202
+ }
203
+ const userId = await this.getBotUserId();
204
+ if (!userId) {
205
+ throw messages.createError('agentApexDebuggingError');
206
+ }
207
+ this.apexTraceFlag = await (0, apexUtils_1.findTraceFlag)(this.connection, userId);
208
+ if (!this.apexTraceFlag) {
209
+ await (0, apexUtils_1.createTraceFlag)(this.connection, userId);
210
+ }
211
+ }
129
212
  }
130
213
  exports.AgentPreview = AgentPreview;
131
214
  //# sourceMappingURL=agentPreview.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"agentPreview.js","sourceRoot":"","sources":["../src/agentPreview.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,6CAAyC;AACzC,2CAA2C;AAE3C,6CAAyC;AASzC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAa,YAAY;IACf,OAAO,CAAS;IAChB,WAAW,CAAS;IACpB,SAAS,CAAY;IAE7B,YAAmB,UAAsB;QACvC,IAAI,CAAC,OAAO,GAAG,iDAAiD,CAAC;QACjE,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;QAC1C,IAAI,CAAC,SAAS,GAAG,IAAI,sBAAS,CAAC,UAAU,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;OAKG;IACI,KAAK,CAAC,KAAK,CAAC,KAAa;QAC9B,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,WAAW,KAAK,WAAW,CAAC;QAEvD,MAAM,IAAI,GAAG;YACX,kBAAkB,EAAE,IAAA,wBAAU,GAAE;YAChC,cAAc,EAAE;gBACd,QAAQ,EAAE,IAAI,CAAC,WAAW;aAC3B;YACD,qBAAqB,EAAE;gBACrB,UAAU,EAAE,CAAC,MAAM,CAAC;aACrB;YACD,UAAU,EAAE,IAAI;SACjB,CAAC;QAEF,IAAI,CAAC;YACH,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAA4B,MAAM,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;QACpF,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,cAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,IAAI,CAAC,SAAiB,EAAE,OAAe;QAClD,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,aAAa,SAAS,W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CAAC,KAAK,CAAC,mCAAmC,CAAC,CAAC;YACzD,CAAC;QACH,CAAC;QAED,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC;QACzC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,QAAQ,CAAC,WAAW,CAAC,yBAAyB,CAAC,CAAC;QACxD,CAAC;QACD,IAAI,CAAC,aAAa,GAAG,MAAM,IAAA,yBAAa,EAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QAClE,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC;YACxB,MAAM,IAAA,2BAAe,EAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;QACjD,CAAC;IACH,CAAC;CACF;AAlLD,oCAkLC"}
@@ -0,0 +1,39 @@
1
+ import { Connection } from '@salesforce/core';
2
+ import { type ApexLog, type TraceFlag } from '@salesforce/types/tooling';
3
+ export type ApexTraceFlag = TraceFlag & {
4
+ ExpirationDate: string;
5
+ StartDate: string;
6
+ Id: string;
7
+ };
8
+ /**
9
+ * Get the apex debug log with a start time that falls in between the provided start and end times.
10
+ *
11
+ * @param connection The connection to use to make requests.
12
+ * @param start The start time of the apex debug log.
13
+ * @param end The end time of the apex debug log.
14
+ * @returns The apex debug log.
15
+ */
16
+ export declare const getDebugLog: (connection: Connection, start: number, end: number) => Promise<ApexLog | undefined>;
17
+ export declare const writeDebugLog: (connection: Connection, log: ApexLog, outputDir: string) => Promise<void>;
18
+ /**
19
+ * Get the debug level id for `SFDC_DevConsole`.
20
+ *
21
+ * @param connection The connection to use to make requests.
22
+ * @returns The debug level id.
23
+ */
24
+ export declare const getDebugLevelId: (connection: Connection) => Promise<string>;
25
+ /**
26
+ * Create a trace flag for the given user id.
27
+ *
28
+ * @param connection The connection to use to make requests.
29
+ * @param userId The user id to create the trace flag for.
30
+ */
31
+ export declare const createTraceFlag: (connection: Connection, userId: string) => Promise<void>;
32
+ /**
33
+ * Find a trace flag for the given user id.
34
+ *
35
+ * @param connection The connection to use to make requests.
36
+ * @param userId The user id to find the trace flag for.
37
+ * @returns The trace flag.
38
+ */
39
+ export declare const findTraceFlag: (connection: Connection, userId: string) => Promise<ApexTraceFlag | undefined>;
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025, salesforce.com, inc.
4
+ * All rights reserved.
5
+ * Licensed under the BSD 3-Clause license.
6
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.findTraceFlag = exports.createTraceFlag = exports.getDebugLevelId = exports.writeDebugLog = exports.getDebugLog = void 0;
10
+ const node_path_1 = require("node:path");
11
+ const promises_1 = require("node:fs/promises");
12
+ const core_1 = require("@salesforce/core");
13
+ ;
14
+ const messages = new core_1.Messages('@salesforce/agents', 'apexUtils', new Map([["traceFlagCreationError", "Failed to create the trace flag for user %s."], ["apexLogIdNotFound", "No Apex debug log ID found."]]));
15
+ let logger;
16
+ const getLogger = () => {
17
+ if (!logger) {
18
+ logger = core_1.Logger.childFromRoot('AgentApexDebug');
19
+ }
20
+ return logger;
21
+ };
22
+ /**
23
+ * Get the apex debug log with a start time that falls in between the provided start and end times.
24
+ *
25
+ * @param connection The connection to use to make requests.
26
+ * @param start The start time of the apex debug log.
27
+ * @param end The end time of the apex debug log.
28
+ * @returns The apex debug log.
29
+ */
30
+ const getDebugLog = async (connection, start, end) => {
31
+ const query = 'SELECT Id, Application, DurationMilliseconds, Location, LogLength, LogUserId, LogUser.Name, Operation, Request, StartTime, Status FROM ApexLog ORDER BY StartTime DESC';
32
+ const queryResult = await connection.tooling.query(query);
33
+ if (queryResult.records.length) {
34
+ getLogger().debug(`Found ${queryResult.records.length} apex debug logs.`);
35
+ for (const apexLog of queryResult.records) {
36
+ const startTime = new Date(apexLog.StartTime).getTime();
37
+ if (startTime >= start && startTime <= end) {
38
+ return apexLog;
39
+ }
40
+ }
41
+ }
42
+ else {
43
+ getLogger().debug(`No debug logs found between ${new Date(start).toDateString()} and ${new Date(end).toDateString()}`);
44
+ }
45
+ };
46
+ exports.getDebugLog = getDebugLog;
47
+ const writeDebugLog = async (connection, log, outputDir) => {
48
+ const logId = log.Id;
49
+ if (!logId) {
50
+ throw messages.createError('apexLogIdNotFound');
51
+ }
52
+ const logFile = (0, node_path_1.join)(outputDir, `${logId}.log`);
53
+ // eslint-disable-next-line no-underscore-dangle
54
+ const url = `${connection.tooling._baseUrl()}/sobjects/ApexLog/${logId}/Body`;
55
+ const logContent = await connection.tooling.request(url);
56
+ getLogger().debug(`Writing apex debug log to file: ${logFile}`);
57
+ return (0, promises_1.writeFile)(logFile, logContent);
58
+ };
59
+ exports.writeDebugLog = writeDebugLog;
60
+ /**
61
+ * Get the debug level id for `SFDC_DevConsole`.
62
+ *
63
+ * @param connection The connection to use to make requests.
64
+ * @returns The debug level id.
65
+ */
66
+ const getDebugLevelId = async (connection) => {
67
+ const query = "SELECT Id FROM DebugLevel WHERE DeveloperName = 'SFDC_DevConsole'";
68
+ return (await connection.singleRecordQuery(query, { tooling: true })).Id;
69
+ };
70
+ exports.getDebugLevelId = getDebugLevelId;
71
+ /**
72
+ * Create a trace flag for the given user id.
73
+ *
74
+ * @param connection The connection to use to make requests.
75
+ * @param userId The user id to create the trace flag for.
76
+ */
77
+ const createTraceFlag = async (connection, userId) => {
78
+ const now = Date.now();
79
+ const debuglevelid = await (0, exports.getDebugLevelId)(connection);
80
+ const expirationDate = new Date(now + 30 * 60_000).toUTCString(); // 30 minute expiration
81
+ const result = await connection.tooling.create('TraceFlag', {
82
+ tracedentityid: userId,
83
+ logtype: 'DEVELOPER_LOG',
84
+ debuglevelid,
85
+ StartDate: now,
86
+ ExpirationDate: expirationDate,
87
+ });
88
+ if (!result.success) {
89
+ throw messages.createError('traceFlagCreationError', [userId]);
90
+ }
91
+ else {
92
+ getLogger().debug(`Created new apexTraceFlag for userId: ${userId} with ExpirationDate of ${expirationDate}`);
93
+ }
94
+ };
95
+ exports.createTraceFlag = createTraceFlag;
96
+ /**
97
+ * Find a trace flag for the given user id.
98
+ *
99
+ * @param connection The connection to use to make requests.
100
+ * @param userId The user id to find the trace flag for.
101
+ * @returns The trace flag.
102
+ */
103
+ const findTraceFlag = async (connection, userId) => {
104
+ const traceFlagQuery = `
105
+ SELECT Id, logtype, startdate, expirationdate, debuglevelid, debuglevel.apexcode, debuglevel.visualforce
106
+ FROM TraceFlag
107
+ WHERE logtype='DEVELOPER_LOG' AND TracedEntityId='${userId}'
108
+ ORDER BY CreatedDate DESC
109
+ LIMIT 1
110
+ `;
111
+ const traceFlagResult = await connection.tooling.query(traceFlagQuery);
112
+ if (traceFlagResult.totalSize > 0) {
113
+ const traceFlag = traceFlagResult.records[0];
114
+ if (traceFlag.ExpirationDate && new Date(traceFlag.ExpirationDate) > new Date()) {
115
+ getLogger().debug(`Using apexTraceFlag in the org with ExpirationDate of ${traceFlag.ExpirationDate}`);
116
+ return traceFlag;
117
+ }
118
+ }
119
+ };
120
+ exports.findTraceFlag = findTraceFlag;
121
+ //# sourceMappingURL=apexUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apexUtils.js","sourceRoot":"","sources":["../src/apexUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,yCAAiC;AACjC,+CAA6C;AAC7C,2CAAgE;;AAIhE,MAAM,QAAQ,OAAG,eAAQ,CAAc,oBAAoB,EAAE,WAAW,8IAAC,CAAC;AAE1E,IAAI,MAAc,CAAC;AACnB,MAAM,SAAS,GAAG,GAAW,EAAE;IAC7B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,GAAG,aAAM,CAAC,aAAa,CAAC,gBAAgB,CAAC,CAAC;IAClD,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AASF;;;;;;;GAOG;AACI,MAAM,WAAW,GAAG,KAAK,EAAE,UAAsB,EAAE,KAAa,EAAE,GAAW,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AE,CAAC,KAAK,CAAC,yCAAyC,MAAM,2BAA2B,cAAc,EAAE,CAAC,CAAC;IAChH,CAAC;AACH,CAAC,CAAC;AAhBW,QAAA,eAAe,mBAgB1B;AAEF;;;;;;GAMG;AACI,MAAM,aAAa,GAAG,KAAK,EAAE,UAAsB,EAAE,MAAc,EAAsC,EAAE;IAChH,MAAM,cAAc,GAAG;;;wDAG+B,MAAM;;;GAG3D,CAAC;IACF,MAAM,eAAe,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,KAAK,CAAgC,cAAc,CAAC,CAAC;IACtG,IAAI,eAAe,CAAC,SAAS,GAAG,CAAC,EAAE,CAAC;QAClC,MAAM,SAAS,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC,CAA6B,CAAC;QACzE,IAAI,SAAS,CAAC,cAAc,IAAI,IAAI,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,GAAG,IAAI,IAAI,EAAE,EAAE,CAAC;YAChF,SAAS,EAAE,CAAC,KAAK,CAAC,yDAAyD,SAAS,CAAC,cAAc,EAAE,CAAC,CAAC;YACvG,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAhBW,QAAA,aAAa,iBAgBxB"}
package/lib/index.d.ts CHANGED
@@ -5,3 +5,4 @@ export { AgentTester } from './agentTester';
5
5
  export { AgentTest, AgentTestCreateLifecycleStages } from './agentTest';
6
6
  export { convertTestResultsToFormat, humanFriendlyName } from './agentTestResults';
7
7
  export { AgentPreview } from './agentPreview';
8
+ export { writeDebugLog } from './apexUtils';
package/lib/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.AgentPreview = exports.humanFriendlyName = exports.convertTestResultsToFormat = exports.AgentTestCreateLifecycleStages = exports.AgentTest = exports.AgentTester = exports.AgentCreateLifecycleStages = exports.Agent = exports.metric = void 0;
9
+ exports.writeDebugLog = exports.AgentPreview = exports.humanFriendlyName = exports.convertTestResultsToFormat = exports.AgentTestCreateLifecycleStages = exports.AgentTest = exports.AgentTester = exports.AgentCreateLifecycleStages = exports.Agent = exports.metric = void 0;
10
10
  var utils_1 = require("./utils");
11
11
  Object.defineProperty(exports, "metric", { enumerable: true, get: function () { return utils_1.metric; } });
12
12
  var agent_1 = require("./agent");
@@ -22,4 +22,6 @@ Object.defineProperty(exports, "convertTestResultsToFormat", { enumerable: true,
22
22
  Object.defineProperty(exports, "humanFriendlyName", { enumerable: true, get: function () { return agentTestResults_1.humanFriendlyName; } });
23
23
  var agentPreview_1 = require("./agentPreview");
24
24
  Object.defineProperty(exports, "AgentPreview", { enumerable: true, get: function () { return agentPreview_1.AgentPreview; } });
25
+ var apexUtils_1 = require("./apexUtils");
26
+ Object.defineProperty(exports, "writeDebugLog", { enumerable: true, get: function () { return apexUtils_1.writeDebugLog; } });
25
27
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAyBH,iCAAiC;AAAxB,+FAAA,MAAM,OAAA;AACf,iCAA4D;AAAnD,8FAAA,KAAK,OAAA;AAAE,mHAAA,0BAA0B,OAAA;AAC1C,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,yCAAwE;AAA/D,sGAAA,SAAS,OAAA;AAAE,2HAAA,8BAA8B,OAAA;AAClD,uDAAmF;AAA1E,8HAAA,0BAA0B,OAAA;AAAE,qHAAA,iBAAiB,OAAA;AACtD,+CAA8C;AAArC,4GAAA,YAAY,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAyBH,iCAAiC;AAAxB,+FAAA,MAAM,OAAA;AACf,iCAA4D;AAAnD,8FAAA,KAAK,OAAA;AAAE,mHAAA,0BAA0B,OAAA;AAC1C,6CAA4C;AAAnC,0GAAA,WAAW,OAAA;AACpB,yCAAwE;AAA/D,sGAAA,SAAS,OAAA;AAAE,2HAAA,8BAA8B,OAAA;AAClD,uDAAmF;AAA1E,8HAAA,0BAA0B,OAAA;AAAE,qHAAA,iBAAiB,OAAA;AACtD,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,yCAA4C;AAAnC,0GAAA,aAAa,OAAA"}
package/lib/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { Connection, SfProject } from '@salesforce/core';
2
2
  import { FileProperties } from '@salesforce/source-deploy-retrieve';
3
+ import { type ApexLog } from '@salesforce/types/tooling';
3
4
  import { metric } from './utils';
4
5
  /**
5
6
  * Options for creating instances of agents from an org.
@@ -7,7 +8,26 @@ import { metric } from './utils';
7
8
  export type AgentOptions = {
8
9
  connection: Connection;
9
10
  project?: SfProject;
10
- name: string;
11
+ /**
12
+ * The API name or ID of the agent (Bot) that exists in the org.
13
+ */
14
+ nameOrId: string;
15
+ };
16
+ export type BotMetadata = {
17
+ Id: string;
18
+ IsDeleted: false;
19
+ DeveloperName: string;
20
+ MasterLabel: string;
21
+ CreatedDate: string;
22
+ CreatedById: string;
23
+ LastModifiedDate: string;
24
+ LastModifiedById: string;
25
+ SystemModstamp: string;
26
+ BotUserId: string;
27
+ Description: string;
28
+ Type: string;
29
+ AgentType: string;
30
+ AgentTemplate: null | string;
11
31
  };
12
32
  /**
13
33
  * An agent job spec is a list of job titles and descriptions
@@ -379,6 +399,7 @@ export type AgentPreviewStartResponse = {
379
399
  export type AgentPreviewSendResponse = {
380
400
  messages: AgentPreviewMessage[];
381
401
  _links: AgentPreviewMessageLinks;
402
+ apexDebugLog?: ApexLog;
382
403
  };
383
404
  export type AgentPreviewEndMessage = {
384
405
  type: string;
@@ -0,0 +1,7 @@
1
+ # invalidBotId
2
+
3
+ The Bot ID provided must begin with "0Xx" and be either 15 or 18 characters. Found: %s
4
+
5
+ # agentApexDebuggingError
6
+
7
+ Agent must have a user assigned to enable apex debug mode.
@@ -13,3 +13,7 @@ Unable to retrieve newly created Agent metadata. Due to: %s
13
13
  # agentRetrievalErrorActions
14
14
 
15
15
  Retrieve the agent metadata using the "project retrieve start" command.
16
+
17
+ # missingAgentNameOrId
18
+
19
+ The "nameOrId" agent option is required when creating an Agent instance.
@@ -0,0 +1,7 @@
1
+ # traceFlagCreationError
2
+
3
+ Failed to create the trace flag for user %s.
4
+
5
+ # apexLogIdNotFound
6
+
7
+ No Apex debug log ID found.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@salesforce/agents",
3
3
  "description": "Client side APIs for working with Salesforce agents",
4
- "version": "0.14.13",
4
+ "version": "0.14.14-dev.0",
5
5
  "license": "BSD-3-Clause",
6
6
  "author": "Salesforce",
7
7
  "main": "lib/index",
@@ -14,6 +14,7 @@
14
14
  "@salesforce/core": "^8.10.3",
15
15
  "@salesforce/kit": "^3.2.3",
16
16
  "@salesforce/source-deploy-retrieve": "^12.19.5",
17
+ "@salesforce/types": "^1.3.0",
17
18
  "fast-xml-parser": "^4.5.3",
18
19
  "nock": "^13.5.6",
19
20
  "yaml": "^2.7.1"
@@ -57,7 +58,7 @@
57
58
  "lint-fix": "yarn sf-lint --fix",
58
59
  "postcompile": "tsc -p test",
59
60
  "test": "wireit",
60
- "test:nuts": "echo 'No tests to run'",
61
+ "test:nuts": "nyc mocha \"**/*.nut.ts\" --slow 4500 --timeout 1200000 --parallel --retries 0 --jobs 10",
61
62
  "test:only": "wireit"
62
63
  },
63
64
  "publishConfig": {