@salesforce/agents 0.19.7 → 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 +3 -1
  2. package/lib/agent.d.ts +26 -86
  3. package/lib/agent.js +115 -315
  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 +2 -2
  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,16 +1,22 @@
1
1
  import { Connection, SfProject } from '@salesforce/core';
2
- import { type AgentJson, type PublishAgent } from './types.js';
2
+ import { type AgentJson, type PublishAgent } from '../types';
3
3
  /**
4
4
  * Service class responsible for publishing agents to Salesforce orgs
5
5
  */
6
- export declare class AgentPublisher {
6
+ export declare class ScriptAgentPublisher {
7
7
  private readonly maybeMock;
8
- private connection;
8
+ private readonly connection;
9
9
  private project;
10
- private agentJson;
11
- private developerName;
12
- private bundleMetaPath;
10
+ private readonly agentJson;
11
+ private readonly developerName;
12
+ private readonly bundleMetaPath;
13
13
  private bundleDir;
14
+ /**
15
+ * Original connection username, stored to create fresh connections for metadata operations.
16
+ * This ensures metadata operations (retrieve/deploy) use a standard connection that hasn't
17
+ * been upgraded with JWT, which is required for SOAP API operations.
18
+ */
19
+ private readonly originalUsername;
14
20
  private API_URL;
15
21
  private readonly API_HEADERS;
16
22
  /**
@@ -18,6 +24,7 @@ export declare class AgentPublisher {
18
24
  *
19
25
  * @param connection The connection to the Salesforce org
20
26
  * @param project The Salesforce project
27
+ * @param agentJson
21
28
  */
22
29
  constructor(connection: Connection, project: SfProject, agentJson: AgentJson);
23
30
  /**
@@ -26,6 +33,14 @@ export declare class AgentPublisher {
26
33
  * @returns Promise<PublishAgent> The publish response
27
34
  */
28
35
  publishAgentJson(): Promise<PublishAgent>;
36
+ /**
37
+ * Creates a fresh standard connection for metadata operations (retrieve/deploy).
38
+ * This ensures metadata operations use a connection that hasn't been upgraded with JWT,
39
+ * which is required for SOAP API operations.
40
+ *
41
+ * @returns A fresh Connection instance with standard authentication
42
+ */
43
+ private createStandardConnection;
29
44
  /**
30
45
  * Validates and extracts the developer name from the agent configuration,
31
46
  * and locates the corresponding authoring bundle directory and metadata file.
@@ -41,8 +56,8 @@ export declare class AgentPublisher {
41
56
  /**
42
57
  * Retrieve the agent metadata from the org after publishing
43
58
  *
44
- * @param developerName The developer name of the agent
45
- * @param originalConnection The original connection to use for retrieval
59
+ * @param botVersionName The bot version name
60
+ * @param connection
46
61
  */
47
62
  private retrieveAgentMetadata;
48
63
  /**
@@ -53,6 +68,7 @@ export declare class AgentPublisher {
53
68
  * 2. Second deployment with target attribute commits the AAB as the published version
54
69
  *
55
70
  * @param botVersionName The bot version name to use as the target for the final published deployment
71
+ * @param connection
56
72
  * @private
57
73
  */
58
74
  private syncAuthoringBundle;
@@ -61,9 +77,9 @@ export declare class AgentPublisher {
61
77
  * The target attribute is required for deployment but should not remain in the
62
78
  * local source files after deployment.
63
79
  *
64
- * @param botVersionId The bot version ID used to construct the target attribute
65
- *
66
80
  * @throws SfError if the deployment fails or if there are component deployment errors
81
+ * @param botVersionName
82
+ * @param connection
67
83
  */
68
84
  private deployAuthoringBundle;
69
85
  /**
@@ -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.
@@ -48,16 +48,15 @@ var __importStar = (this && this.__importStar) || (function () {
48
48
  };
49
49
  })();
50
50
  Object.defineProperty(exports, "__esModule", { value: true });
51
- exports.AgentPublisher = void 0;
51
+ exports.ScriptAgentPublisher = void 0;
52
52
  const path = __importStar(require("node:path"));
53
53
  const promises_1 = require("node:fs/promises");
54
54
  const node_fs_1 = require("node:fs");
55
- const kit_1 = require("@salesforce/kit");
56
55
  const fast_xml_parser_1 = require("fast-xml-parser");
57
56
  const core_1 = require("@salesforce/core");
58
57
  const source_deploy_retrieve_1 = require("@salesforce/source-deploy-retrieve");
59
- const maybe_mock_1 = require("./maybe-mock");
60
- const utils_1 = require("./utils");
58
+ const maybe_mock_1 = require("../maybe-mock");
59
+ const utils_1 = require("../utils");
61
60
  ;
62
61
  const messages = new core_1.Messages('@salesforce/agents', 'agentPublisher', new Map([["agentRetrievalError", "Unable to retrieve newly created Agent metadata. Due to: %s"], ["agentRetrievalErrorActions", "Retrieve the agent metadata using the \"project retrieve start\" command."], ["authoringBundleDeploymentError", "Unable to deploy AiAuthoringBundle metadata. Due to: %s"], ["authoringBundleDeploymentErrorActions", "Deploy the authoring bundle metadata using the \"project deploy start\" command."], ["findBotVersionError", "Unable to find BotVersion with id %s."]]));
63
62
  let logger;
@@ -70,7 +69,7 @@ const getLogger = () => {
70
69
  /**
71
70
  * Service class responsible for publishing agents to Salesforce orgs
72
71
  */
73
- class AgentPublisher {
72
+ class ScriptAgentPublisher {
74
73
  maybeMock;
75
74
  connection;
76
75
  project;
@@ -78,7 +77,13 @@ class AgentPublisher {
78
77
  developerName;
79
78
  bundleMetaPath;
80
79
  bundleDir;
81
- API_URL = `https://${kit_1.env.getBoolean('SF_TEST_API') ? 'test.' : ''}api.salesforce.com/einstein/ai-agent/v1.1/authoring/agents`;
80
+ /**
81
+ * Original connection username, stored to create fresh connections for metadata operations.
82
+ * This ensures metadata operations (retrieve/deploy) use a standard connection that hasn't
83
+ * been upgraded with JWT, which is required for SOAP API operations.
84
+ */
85
+ originalUsername;
86
+ API_URL = `https://${(0, utils_1.getEndpoint)()}api.salesforce.com/einstein/ai-agent/v1.1/authoring/agents`;
82
87
  API_HEADERS = {
83
88
  'x-client-name': 'afdx',
84
89
  'content-type': 'application/json',
@@ -88,12 +93,15 @@ class AgentPublisher {
88
93
  *
89
94
  * @param connection The connection to the Salesforce org
90
95
  * @param project The Salesforce project
96
+ * @param agentJson
91
97
  */
92
98
  constructor(connection, project, agentJson) {
93
99
  this.maybeMock = new maybe_mock_1.MaybeMock(connection);
94
100
  this.connection = connection;
95
101
  this.project = project;
96
102
  this.agentJson = agentJson;
103
+ // Store the original username to create fresh connections for metadata operations
104
+ this.originalUsername = connection.getUsername();
97
105
  // Validate and get developer name and bundle directory
98
106
  const validationResult = this.validateDeveloperName();
99
107
  this.developerName = validationResult.developerName;
@@ -117,8 +125,9 @@ class AgentPublisher {
117
125
  // before metadata operations that may use SOAP API
118
126
  let response;
119
127
  try {
120
- await (0, utils_1.useNamedUserJwt)(this.connection);
121
128
  const botId = await this.getPublishedBotId(this.developerName);
129
+ // if we've found a botId in the org, then this agent has already been published before => ai-agent/v1.1/authoring/agents/<id>/versions
130
+ // if we didn't find an Id in the org, then we're publishing for the first time => ai-agent/v1.1/authoring/agents
122
131
  const url = botId ? `${this.API_URL}/${botId}/versions` : this.API_URL;
123
132
  response = await this.maybeMock.request('POST', url, body, this.API_HEADERS);
124
133
  }
@@ -132,8 +141,9 @@ class AgentPublisher {
132
141
  // 1. retrieve the new Agent metadata that's in the org
133
142
  // 2. deploy the AuthoringBundle's -meta.xml file with correct target attribute
134
143
  const botVersionName = await this.getVersionDeveloperName(response.botVersionId);
135
- await this.retrieveAgentMetadata(botVersionName);
136
- await this.syncAuthoringBundle(botVersionName);
144
+ const standardConnection = await this.createStandardConnection();
145
+ await this.retrieveAgentMetadata(botVersionName, standardConnection);
146
+ await this.syncAuthoringBundle(botVersionName, standardConnection);
137
147
  return { ...response, developerName: this.developerName };
138
148
  }
139
149
  else {
@@ -144,6 +154,21 @@ class AgentPublisher {
144
154
  });
145
155
  }
146
156
  }
157
+ /**
158
+ * Creates a fresh standard connection for metadata operations (retrieve/deploy).
159
+ * This ensures metadata operations use a connection that hasn't been upgraded with JWT,
160
+ * which is required for SOAP API operations.
161
+ *
162
+ * @returns A fresh Connection instance with standard authentication
163
+ */
164
+ async createStandardConnection() {
165
+ const authInfo = await core_1.AuthInfo.create({
166
+ username: this.originalUsername,
167
+ });
168
+ return core_1.Connection.create({
169
+ authInfo,
170
+ });
171
+ }
147
172
  /**
148
173
  * Validates and extracts the developer name from the agent configuration,
149
174
  * and locates the corresponding authoring bundle directory and metadata file.
@@ -178,10 +203,10 @@ class AgentPublisher {
178
203
  /**
179
204
  * Retrieve the agent metadata from the org after publishing
180
205
  *
181
- * @param developerName The developer name of the agent
182
- * @param originalConnection The original connection to use for retrieval
206
+ * @param botVersionName The bot version name
207
+ * @param connection
183
208
  */
184
- async retrieveAgentMetadata(botVersionName) {
209
+ async retrieveAgentMetadata(botVersionName, connection) {
185
210
  const defaultPackagePath = path.resolve(this.project.getDefaultPackage().path);
186
211
  const cs = await source_deploy_retrieve_1.ComponentSetBuilder.build({
187
212
  metadata: {
@@ -189,12 +214,12 @@ class AgentPublisher {
189
214
  directoryPaths: [defaultPackagePath],
190
215
  },
191
216
  org: {
192
- username: this.connection.getUsername(),
217
+ username: this.originalUsername,
193
218
  exclude: [],
194
219
  },
195
220
  });
196
221
  const retrieve = await cs.retrieve({
197
- usernameOrConnection: this.connection,
222
+ usernameOrConnection: connection,
198
223
  merge: true,
199
224
  format: 'source',
200
225
  output: path.resolve(this.project.getPath(), defaultPackagePath),
@@ -215,22 +240,23 @@ class AgentPublisher {
215
240
  * 2. Second deployment with target attribute commits the AAB as the published version
216
241
  *
217
242
  * @param botVersionName The bot version name to use as the target for the final published deployment
243
+ * @param connection
218
244
  * @private
219
245
  */
220
- async syncAuthoringBundle(botVersionName) {
221
- await this.deployAuthoringBundle();
222
- await this.deployAuthoringBundle(botVersionName);
246
+ async syncAuthoringBundle(botVersionName, connection) {
247
+ await this.deployAuthoringBundle(connection);
248
+ await this.deployAuthoringBundle(connection, botVersionName);
223
249
  }
224
250
  /**
225
251
  * Deploys the authoring bundle to the Salesforce org after setting the correct target attribute if provided.
226
252
  * The target attribute is required for deployment but should not remain in the
227
253
  * local source files after deployment.
228
254
  *
229
- * @param botVersionId The bot version ID used to construct the target attribute
230
- *
231
255
  * @throws SfError if the deployment fails or if there are component deployment errors
256
+ * @param botVersionName
257
+ * @param connection
232
258
  */
233
- async deployAuthoringBundle(botVersionName) {
259
+ async deployAuthoringBundle(connection, botVersionName) {
234
260
  // 1. if botVersionName is provided, add the target to the local authoring bundle meta.xml file
235
261
  // 2. deploy the authoring bundle to the org
236
262
  // 3. remove the target from the localauthoring bundle meta.xml file
@@ -251,7 +277,7 @@ class AgentPublisher {
251
277
  await (0, promises_1.writeFile)(this.bundleMetaPath, xmlBuilder.build(authoringBundle));
252
278
  // 2. attempt to deploy the authoring bundle to the org
253
279
  const deploy = await source_deploy_retrieve_1.ComponentSet.fromSource(this.bundleDir).deploy({
254
- usernameOrConnection: this.connection.getUsername(),
280
+ usernameOrConnection: connection,
255
281
  });
256
282
  const deployResult = await deploy.pollStatus();
257
283
  // 3.remove the target from the local authoring bundle meta.xml file
@@ -305,5 +331,5 @@ class AgentPublisher {
305
331
  }
306
332
  }
307
333
  }
308
- exports.AgentPublisher = AgentPublisher;
309
- //# sourceMappingURL=agentPublisher.js.map
334
+ exports.ScriptAgentPublisher = ScriptAgentPublisher;
335
+ //# sourceMappingURL=scriptAgentPublisher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scriptAgentPublisher.js","sourceRoot":"","sources":["../../src/agents/scriptAgentPublisher.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEH,gDAAkC;AAClC,+CAAuD;AACvD,qCAAqC;AACrC,qDAAwD;AACxD,2CAA8F;AAC9F,+EAAuF;AACvF,8CAA0C;AAE1C,oCAA4D;;AAG5D,MAAM,QAAQ,OAAG,eAAQ,CAAc,oBAAoB,EAAE,gBAAgB,ifAAC,CAAC;AAE/E,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;AAEF;;GAEG;AACH,MAAa,oBAAoB;IACd,SAAS,CAAY;IACrB,UAAU,CAAa;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,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IAED;;;;;OAKG;IACK,KAAK,CAAC,uBAAuB,CAAC,YAAoB;QACxD,IAAI,CAAC;YACH,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,iBAAiB,CACzD,kDAAkD,YAAY,GAAG,CAClE,CAAC;YACF,SAAS,EAAE,CAAC,KAAK,CAAC,uBAAuB,YAAY,OAAO,WAAW,CAAC,aAAa,GAAG,CAAC,CAAC;YAC1F,OAAO,WAAW,CAAC,aAAa,CAAC;QACnC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,GAAG,GAAG,QAAQ,CAAC,WAAW,CAAC,qBAAqB,EAAE,CAAC,YAAY,CAAC,CAAC,CAAC;YACxE,GAAG,CAAC,OAAO,GAAG,CAAC,QAAQ,CAAC,UAAU,CAAC,uCAAuC,CAAC,CAAC,CAAC;YAC7E,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC;CACF;AAhSD,oDAgSC"}
@@ -29,6 +29,7 @@ export declare const getDebugLevelId: (connection: Connection) => Promise<string
29
29
  * @param userId The user id to create the trace flag for.
30
30
  */
31
31
  export declare const createTraceFlag: (connection: Connection, userId: string) => Promise<void>;
32
+ export declare function ensureTraceFlag(username: string, connection: Connection): Promise<ApexTraceFlag | undefined>;
32
33
  /**
33
34
  * Find a trace flag for the given user id.
34
35
  *
package/lib/apexUtils.js CHANGED
@@ -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.
@@ -16,6 +16,7 @@
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.findTraceFlag = exports.createTraceFlag = exports.getDebugLevelId = exports.writeDebugLog = exports.getDebugLog = void 0;
19
+ exports.ensureTraceFlag = ensureTraceFlag;
19
20
  const node_path_1 = require("node:path");
20
21
  const promises_1 = require("node:fs/promises");
21
22
  const core_1 = require("@salesforce/core");
@@ -103,6 +104,15 @@ const createTraceFlag = async (connection, userId) => {
103
104
  }
104
105
  };
105
106
  exports.createTraceFlag = createTraceFlag;
107
+ // once we're previewing agents in the org, with mockActions = false, we'll have to figure out how to get the correct user that was simulated for apex invocattion
108
+ async function ensureTraceFlag(username, connection) {
109
+ const userId = (await connection.singleRecordQuery(`SELECT Id FROM User WHERE Username = '${username}'`)).Id;
110
+ const apexTraceFlag = await (0, exports.findTraceFlag)(connection, userId);
111
+ if (!apexTraceFlag) {
112
+ await (0, exports.createTraceFlag)(connection, userId);
113
+ }
114
+ return apexTraceFlag;
115
+ }
106
116
  /**
107
117
  * Find a trace flag for the given user id.
108
118
  *
@@ -1 +1 @@
1
- {"version":3,"file":"apexUtils.js","sourceRoot":"","sources":["../src/apexUtils.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,yCAAiC;AACjC,+CAA6C;AAC7C,2CAAgE;AAEhE,mCAA2C;;AAG3C,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,EAAgC,EAAE;IACpH,MAAM,KAAK,GACT,wKAAwK,CAAC;IAC3K,MAAM,WAAW,GAAG,MAAM,UAAU,CAAC,OAAO,CAAC,KAAK,CAA0B,KAAK,CAAC,CAAC;IACnF,IAAI,WAAW,CAAC,OAAO,CAAC,MAAM,EA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Ac,EAAE,CAAC,CAAC;IAChH,CAAC;AACH,CAAC,CAAC;AAhBW,QAAA,eAAe,mBAgB1B;AAEF,kKAAkK;AAC3J,KAAK,UAAU,eAAe,CAAC,QAAgB,EAAE,UAAsB;IAC5E,MAAM,MAAM,GAAG,CACb,MAAM,UAAU,CAAC,iBAAiB,CAAiB,yCAAyC,QAAQ,GAAG,CAAC,CACzG,CAAC,EAAE,CAAC;IAEL,MAAM,aAAa,GAAG,MAAM,IAAA,qBAAa,EAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC9D,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,MAAM,IAAA,uBAAe,EAAC,UAAU,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC;AAED;;;;;;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
@@ -1,11 +1,10 @@
1
- export { type AgentInteractionBase, type BaseAgentConfig, type AgentPreviewStartResponse, type AgentPreviewSendResponse, type AgentPreviewEndResponse, type EndReason, type ApiStatus, type AgentJson, type AgentCompilationSuccess, type AgentScriptContent, type AgentCreateConfig, type AgentCreateResponse, type AgentJobSpec, type AgentJobSpecCreateConfig, type AgentOptions, type AgentTone, type AgentType, type BotMetadata, type BotVersionMetadata, type CompilationError, type DraftAgentTopics, type DraftAgentTopicsBody, type DraftAgentTopicsResponse, type AvailableDefinition, type AgentPreviewMessageLinks, type AgentPreviewMessage, type AgentPreviewError, AgentSource, type ScriptAgent, type PublishedAgent, type AgentTestResultsResponse, type AgentTestStartResponse, type AgentTestStatusResponse, type TestCaseResult, type TestStatus, type AgentTestConfig, type TestCase, type TestSpec, type MetadataMetric, type MetadataExpectation, type MetadataCustomEvaluation, type AiEvaluationDefinition, type AgentTraceResponse, type AgentTraceStep, type UserInputStep, type LLMExecutionStep, type UpdateTopicStep, type EventStep, type ReasoningStep, type PlannerResponseStep, } from './types';
1
+ export { type BaseAgentConfig, type AgentPreviewStartResponse, type AgentPreviewSendResponse, type AgentPreviewEndResponse, type EndReason, type ApiStatus, type AgentJson, type AgentCompilationSuccess, type AgentScriptContent, type AgentCreateConfig, type AgentCreateResponse, type AgentJobSpec, type AgentJobSpecCreateConfig, type AgentOptions, type AgentTone, type AgentType, type BotMetadata, type BotVersionMetadata, type PreviewableAgent, type CompilationError, type DraftAgentTopics, type DraftAgentTopicsBody, type DraftAgentTopicsResponse, type AvailableDefinition, type AgentPreviewMessageLinks, type AgentPreviewMessage, type AgentPreviewError, AgentSource, type ScriptAgentType, type ProductionAgentType, type AgentTestResultsResponse, type AgentTestStartResponse, type AgentTestStatusResponse, type TestCaseResult, type TestStatus, type AgentTestConfig, type TestCase, type TestSpec, type MetadataMetric, type MetadataExpectation, type MetadataCustomEvaluation, type AiEvaluationDefinition, type AgentTraceResponse, type AgentTraceStep, type UserInputStep, type LLMExecutionStep, type UpdateTopicStep, type EventStep, type ReasoningStep, type PlannerResponseStep, } from './types';
2
2
  export { metric, findAuthoringBundle, readTranscriptEntries } from './utils';
3
3
  export { Agent, AgentCreateLifecycleStages } from './agent';
4
4
  export { AgentTester } from './agentTester';
5
5
  export { AgentTest, AgentTestCreateLifecycleStages } from './agentTest';
6
- export { AgentTrace } from './agentTrace';
6
+ export { ProductionAgent } from './agents/productionAgent';
7
+ export { ScriptAgent } from './agents/scriptAgent';
8
+ export { AgentBase, type AgentPreviewInterface } from './agents/agentBase';
7
9
  export { convertTestResultsToFormat, humanFriendlyName } from './agentTestResults';
8
- export { AgentPreview } from './agentPreview';
9
- export { AgentSimulate } from './agentSimulate';
10
10
  export { writeDebugLog } from './apexUtils';
11
- export { AgentPreviewBase } from './agentPreviewBase';
package/lib/index.js CHANGED
@@ -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.
@@ -15,7 +15,7 @@
15
15
  * limitations under the License.
16
16
  */
17
17
  Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.AgentPreviewBase = exports.writeDebugLog = exports.AgentSimulate = exports.AgentPreview = exports.humanFriendlyName = exports.convertTestResultsToFormat = exports.AgentTrace = exports.AgentTestCreateLifecycleStages = exports.AgentTest = exports.AgentTester = exports.AgentCreateLifecycleStages = exports.Agent = exports.readTranscriptEntries = exports.findAuthoringBundle = exports.metric = exports.AgentSource = void 0;
18
+ exports.writeDebugLog = exports.humanFriendlyName = exports.convertTestResultsToFormat = exports.AgentBase = exports.ScriptAgent = exports.ProductionAgent = exports.AgentTestCreateLifecycleStages = exports.AgentTest = exports.AgentTester = exports.AgentCreateLifecycleStages = exports.Agent = exports.readTranscriptEntries = exports.findAuthoringBundle = exports.metric = exports.AgentSource = void 0;
19
19
  var types_1 = require("./types");
20
20
  Object.defineProperty(exports, "AgentSource", { enumerable: true, get: function () { return types_1.AgentSource; } });
21
21
  var utils_1 = require("./utils");
@@ -30,17 +30,15 @@ Object.defineProperty(exports, "AgentTester", { enumerable: true, get: function
30
30
  var agentTest_1 = require("./agentTest");
31
31
  Object.defineProperty(exports, "AgentTest", { enumerable: true, get: function () { return agentTest_1.AgentTest; } });
32
32
  Object.defineProperty(exports, "AgentTestCreateLifecycleStages", { enumerable: true, get: function () { return agentTest_1.AgentTestCreateLifecycleStages; } });
33
- var agentTrace_1 = require("./agentTrace");
34
- Object.defineProperty(exports, "AgentTrace", { enumerable: true, get: function () { return agentTrace_1.AgentTrace; } });
33
+ var productionAgent_1 = require("./agents/productionAgent");
34
+ Object.defineProperty(exports, "ProductionAgent", { enumerable: true, get: function () { return productionAgent_1.ProductionAgent; } });
35
+ var scriptAgent_1 = require("./agents/scriptAgent");
36
+ Object.defineProperty(exports, "ScriptAgent", { enumerable: true, get: function () { return scriptAgent_1.ScriptAgent; } });
37
+ var agentBase_1 = require("./agents/agentBase");
38
+ Object.defineProperty(exports, "AgentBase", { enumerable: true, get: function () { return agentBase_1.AgentBase; } });
35
39
  var agentTestResults_1 = require("./agentTestResults");
36
40
  Object.defineProperty(exports, "convertTestResultsToFormat", { enumerable: true, get: function () { return agentTestResults_1.convertTestResultsToFormat; } });
37
41
  Object.defineProperty(exports, "humanFriendlyName", { enumerable: true, get: function () { return agentTestResults_1.humanFriendlyName; } });
38
- var agentPreview_1 = require("./agentPreview");
39
- Object.defineProperty(exports, "AgentPreview", { enumerable: true, get: function () { return agentPreview_1.AgentPreview; } });
40
- var agentSimulate_1 = require("./agentSimulate");
41
- Object.defineProperty(exports, "AgentSimulate", { enumerable: true, get: function () { return agentSimulate_1.AgentSimulate; } });
42
42
  var apexUtils_1 = require("./apexUtils");
43
43
  Object.defineProperty(exports, "writeDebugLog", { enumerable: true, get: function () { return apexUtils_1.writeDebugLog; } });
44
- var agentPreviewBase_1 = require("./agentPreviewBase");
45
- Object.defineProperty(exports, "AgentPreviewBase", { enumerable: true, get: function () { return agentPreviewBase_1.AgentPreviewBase; } });
46
44
  //# 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;;;;;;;;;;;;;;GAcG;;;AAEH,iCA4DiB;AA3Bf,oGAAA,WAAW,OAAA;AA6Bb,iCAA6E;AAApE,+FAAA,MAAM,OAAA;AAAE,4GAAA,mBAAmB,OAAA;AAAE,8GAAA,qBAAqB,OAAA;AAC3D,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,2CAA0C;AAAjC,wGAAA,UAAU,OAAA;AACnB,uDAAmF;AAA1E,8HAAA,0BAA0B,OAAA;AAAE,qHAAA,iBAAiB,OAAA;AACtD,+CAA8C;AAArC,4GAAA,YAAY,OAAA;AACrB,iDAAgD;AAAvC,8GAAA,aAAa,OAAA;AACtB,yCAA4C;AAAnC,0GAAA,aAAa,OAAA;AACtB,uDAAsD;AAA7C,oHAAA,gBAAgB,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,iCA4DiB;AA3Bf,oGAAA,WAAW,OAAA;AA6Bb,iCAA6E;AAApE,+FAAA,MAAM,OAAA;AAAE,4GAAA,mBAAmB,OAAA;AAAE,8GAAA,qBAAqB,OAAA;AAC3D,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,4DAA2D;AAAlD,kHAAA,eAAe,OAAA;AACxB,oDAAmD;AAA1C,0GAAA,WAAW,OAAA;AACpB,gDAA2E;AAAlE,sGAAA,SAAS,OAAA;AAClB,uDAAmF;AAA1E,8HAAA,0BAA0B,OAAA;AAAE,qHAAA,iBAAiB,OAAA;AACtD,yCAA4C;AAAnC,0GAAA,aAAa,OAAA"}
package/lib/maybe-mock.js CHANGED
@@ -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.
package/lib/types.d.ts CHANGED
@@ -15,13 +15,27 @@ export type BaseAgentConfig = {
15
15
  /**
16
16
  * Options for creating instances of agents from an org.
17
17
  */
18
- export type AgentOptions = {
18
+ export type AgentOptions = ScriptAgentOptions | ProductionAgentOptions;
19
+ export type ScriptAgentOptions = {
19
20
  connection: Connection;
20
- project?: SfProject;
21
- /**
22
- * The API name or ID of the agent (Bot) that exists in the org.
23
- */
24
- nameOrId: string;
21
+ project: SfProject;
22
+ aabDirectory: string;
23
+ };
24
+ export type ProductionAgentOptions = {
25
+ connection: Connection;
26
+ project: SfProject;
27
+ apiNameOrId: string;
28
+ };
29
+ /**
30
+ * Represents an agent available for preview, either from the org or from a local script file
31
+ */
32
+ export type PreviewableAgent = {
33
+ name: string;
34
+ source: AgentSource;
35
+ id?: string;
36
+ developerName?: string;
37
+ aabDirectory?: string;
38
+ label?: string;
25
39
  };
26
40
  export type BotMetadata = {
27
41
  Id: string;
@@ -675,12 +689,12 @@ export declare enum AgentSource {
675
689
  PUBLISHED = "published",
676
690
  SCRIPT = "script"
677
691
  }
678
- export type ScriptAgent = {
692
+ export type ScriptAgentType = {
679
693
  DeveloperName: string;
680
694
  source: AgentSource.SCRIPT;
681
695
  path: string;
682
696
  };
683
- export type PublishedAgent = {
697
+ export type ProductionAgentType = {
684
698
  Id: string;
685
699
  DeveloperName: string;
686
700
  source: AgentSource.PUBLISHED;
package/lib/types.js CHANGED
@@ -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.
package/lib/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAivBH,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,sCAAuB,CAAA;IACvB,gCAAiB,CAAA;AACnB,CAAC,EAHW,WAAW,2BAAX,WAAW,QAGtB"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAkwBH,IAAY,WAGX;AAHD,WAAY,WAAW;IACrB,sCAAuB,CAAA;IACvB,gCAAiB,CAAA;AACnB,CAAC,EAHW,WAAW,2BAAX,WAAW,QAGtB"}
package/lib/utils.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { Connection } from '@salesforce/core';
2
+ import { type PlannerResponse } from './types';
2
3
  export declare const metric: readonly ["completeness", "coherence", "conciseness", "output_latency_milliseconds"];
3
4
  /**
4
5
  * Sanitize a filename by removing or replacing illegal characters.
@@ -42,11 +43,42 @@ export type TranscriptEntry = {
42
43
  reason?: string;
43
44
  };
44
45
  /**
45
- * Append a transcript entry to the last conversation JSON file under the project local .sfdx folder.
46
- * If the entry has event: 'start', this will clear the previous conversation and start fresh.
47
- * Path: <project>/.sfdx/agents/conversations/<agentId>/history.json
46
+ * Get the session directory path for a specific session
47
+ */
48
+ export declare const getSessionDir: (agentId: string, sessionId: string) => Promise<string>;
49
+ /**
50
+ * Copy a directory recursively
51
+ */
52
+ export declare const copyDirectory: (src: string, dest: string) => Promise<void>;
53
+ /**
54
+ * Append a transcript entry to the session transcript file
55
+ */
56
+ export declare const appendTranscriptEntryToSession: (entry: TranscriptEntry, sessionDir: string) => Promise<void>;
57
+ /**
58
+ * Write a trace to the session traces directory
59
+ */
60
+ export declare const writeTraceToSession: (planId: string, trace: PlannerResponse | undefined, sessionDir: string) => Promise<void>;
61
+ export declare function getEndpoint(): string;
62
+ /**
63
+ * Session metadata type
64
+ */
65
+ export type SessionMetadata = {
66
+ sessionId: string;
67
+ agentId: string;
68
+ startTime: string;
69
+ endTime?: string;
70
+ apexDebugging?: boolean;
71
+ mockMode?: 'Mock' | 'Live Test';
72
+ planIds: string[];
73
+ };
74
+ /**
75
+ * Write session metadata to the session directory
76
+ */
77
+ export declare const writeMetadataToSession: (sessionDir: string, metadata: SessionMetadata) => Promise<void>;
78
+ /**
79
+ * Update session metadata with end time and plan IDs
48
80
  */
49
- export declare const appendTranscriptEntry: (entry: TranscriptEntry, newSession?: boolean) => Promise<void>;
81
+ export declare const updateMetadataEndTime: (sessionDir: string, endTime: string, planIds: Set<string>) => Promise<void>;
50
82
  /**
51
83
  * Read and parse the last conversation's transcript entries from JSON.
52
84
  * Path: <project>/.sfdx/agents/conversations/<agentId>/history.json