@salesforce/plugin-agent 1.32.13 → 1.32.15

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 (49) hide show
  1. package/README.md +30 -30
  2. package/lib/commands/agent/activate.d.ts +2 -0
  3. package/lib/commands/agent/activate.js +33 -4
  4. package/lib/commands/agent/activate.js.map +1 -1
  5. package/lib/commands/agent/deactivate.d.ts +2 -0
  6. package/lib/commands/agent/deactivate.js +33 -4
  7. package/lib/commands/agent/deactivate.js.map +1 -1
  8. package/lib/commands/agent/preview/end.d.ts +2 -0
  9. package/lib/commands/agent/preview/end.js +49 -12
  10. package/lib/commands/agent/preview/end.js.map +1 -1
  11. package/lib/commands/agent/preview/send.d.ts +2 -0
  12. package/lib/commands/agent/preview/send.js +47 -9
  13. package/lib/commands/agent/preview/send.js.map +1 -1
  14. package/lib/commands/agent/preview/sessions.d.ts +1 -0
  15. package/lib/commands/agent/preview/sessions.js +4 -1
  16. package/lib/commands/agent/preview/sessions.js.map +1 -1
  17. package/lib/commands/agent/preview/start.d.ts +2 -0
  18. package/lib/commands/agent/preview/start.js +55 -6
  19. package/lib/commands/agent/preview/start.js.map +1 -1
  20. package/lib/commands/agent/test/create.d.ts +2 -0
  21. package/lib/commands/agent/test/create.js +34 -6
  22. package/lib/commands/agent/test/create.js.map +1 -1
  23. package/lib/commands/agent/test/list.d.ts +2 -0
  24. package/lib/commands/agent/test/list.js +15 -3
  25. package/lib/commands/agent/test/list.js.map +1 -1
  26. package/lib/commands/agent/test/results.d.ts +2 -0
  27. package/lib/commands/agent/test/results.js +23 -3
  28. package/lib/commands/agent/test/results.js.map +1 -1
  29. package/lib/commands/agent/test/resume.d.ts +6 -0
  30. package/lib/commands/agent/test/resume.js +55 -7
  31. package/lib/commands/agent/test/resume.js.map +1 -1
  32. package/lib/commands/agent/test/run-eval.d.ts +2 -0
  33. package/lib/commands/agent/test/run-eval.js +38 -7
  34. package/lib/commands/agent/test/run-eval.js.map +1 -1
  35. package/lib/commands/agent/test/run.d.ts +2 -0
  36. package/lib/commands/agent/test/run.js +32 -8
  37. package/lib/commands/agent/test/run.js.map +1 -1
  38. package/lib/commands/agent/validate/authoring-bundle.d.ts +2 -0
  39. package/lib/commands/agent/validate/authoring-bundle.js +9 -2
  40. package/lib/commands/agent/validate/authoring-bundle.js.map +1 -1
  41. package/lib/previewSessionStore.js +0 -6
  42. package/lib/previewSessionStore.js.map +1 -1
  43. package/messages/agent.activate.md +8 -0
  44. package/messages/agent.deactivate.md +8 -0
  45. package/messages/agent.preview.end.md +18 -6
  46. package/messages/agent.preview.send.md +16 -4
  47. package/messages/agent.preview.start.md +19 -7
  48. package/oclif.manifest.json +447 -94
  49. package/package.json +3 -3
package/README.md CHANGED
@@ -126,7 +126,7 @@ EXAMPLES
126
126
  $ sf agent activate --api-name Resort_Manager --version 2 --target-org my-org
127
127
  ```
128
128
 
129
- _See code: [src/commands/agent/activate.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.13/src/commands/agent/activate.ts)_
129
+ _See code: [src/commands/agent/activate.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.15/src/commands/agent/activate.ts)_
130
130
 
131
131
  ## `sf agent create`
132
132
 
@@ -193,7 +193,7 @@ EXAMPLES
193
193
  $ sf agent create --name "Resort Manager" --spec specs/resortManagerAgent.yaml --preview
194
194
  ```
195
195
 
196
- _See code: [src/commands/agent/create.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.13/src/commands/agent/create.ts)_
196
+ _See code: [src/commands/agent/create.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.15/src/commands/agent/create.ts)_
197
197
 
198
198
  ## `sf agent deactivate`
199
199
 
@@ -234,7 +234,7 @@ EXAMPLES
234
234
  $ sf agent deactivate --api-name Resort_Manager --target-org my-org
235
235
  ```
236
236
 
237
- _See code: [src/commands/agent/deactivate.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.13/src/commands/agent/deactivate.ts)_
237
+ _See code: [src/commands/agent/deactivate.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.15/src/commands/agent/deactivate.ts)_
238
238
 
239
239
  ## `sf agent generate agent-spec`
240
240
 
@@ -341,7 +341,7 @@ EXAMPLES
341
341
  $ sf agent generate agent-spec --tone formal --agent-user resortmanager@myorg.com
342
342
  ```
343
343
 
344
- _See code: [src/commands/agent/generate/agent-spec.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.13/src/commands/agent/generate/agent-spec.ts)_
344
+ _See code: [src/commands/agent/generate/agent-spec.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.15/src/commands/agent/generate/agent-spec.ts)_
345
345
 
346
346
  ## `sf agent generate authoring-bundle`
347
347
 
@@ -418,7 +418,7 @@ EXAMPLES
418
418
  other-package-dir/main/default --target-org my-dev-org
419
419
  ```
420
420
 
421
- _See code: [src/commands/agent/generate/authoring-bundle.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.13/src/commands/agent/generate/authoring-bundle.ts)_
421
+ _See code: [src/commands/agent/generate/authoring-bundle.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.15/src/commands/agent/generate/authoring-bundle.ts)_
422
422
 
423
423
  ## `sf agent generate template`
424
424
 
@@ -480,7 +480,7 @@ EXAMPLES
480
480
  my-package --source-org my-scratch-org
481
481
  ```
482
482
 
483
- _See code: [src/commands/agent/generate/template.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.13/src/commands/agent/generate/template.ts)_
483
+ _See code: [src/commands/agent/generate/template.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.15/src/commands/agent/generate/template.ts)_
484
484
 
485
485
  ## `sf agent generate test-spec`
486
486
 
@@ -545,7 +545,7 @@ EXAMPLES
545
545
  force-app//main/default/aiEvaluationDefinitions/Resort_Manager_Tests.aiEvaluationDefinition-meta.xml
546
546
  ```
547
547
 
548
- _See code: [src/commands/agent/generate/test-spec.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.13/src/commands/agent/generate/test-spec.ts)_
548
+ _See code: [src/commands/agent/generate/test-spec.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.15/src/commands/agent/generate/test-spec.ts)_
549
549
 
550
550
  ## `sf agent preview`
551
551
 
@@ -618,7 +618,7 @@ EXAMPLES
618
618
  $ sf agent preview --use-live-actions --apex-debug --output-dir transcripts/my-preview
619
619
  ```
620
620
 
621
- _See code: [src/commands/agent/preview.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.13/src/commands/agent/preview.ts)_
621
+ _See code: [src/commands/agent/preview.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.15/src/commands/agent/preview.ts)_
622
622
 
623
623
  ## `sf agent preview end`
624
624
 
@@ -650,11 +650,11 @@ DESCRIPTION
650
650
  use this command to end it. This command also displays the local directory where the session trace files are stored.
651
651
 
652
652
  The original "agent preview start" command outputs a session ID which you then use with the --session-id flag of this
653
- command to end the session. You don't have to specify the --session-id flag if an agent has only one active preview
653
+ command to end the session. You don't have to specify the --session-id flag if an agent has only one active preview
654
654
  session. You must also use either the --authoring-bundle or --api-name flag to specify the API name of the authoring
655
- bundle or the published agent, respecitvely. To find either API name, navigate to your package directory in your DX
655
+ bundle or the published agent, respecitvely. To find either API name, navigate to your package directory in your DX
656
656
  project. The API name of an authoring bundle is the same as its directory name under the "aiAuthoringBundles" metadata
657
- directory. Similarly, the published agent's API name is the same as its directory name under the "Bots" metadata
657
+ directory. Similarly, the published agent's API name is the same as its directory name under the "Bots" metadata
658
658
  directory.
659
659
 
660
660
  EXAMPLES
@@ -673,7 +673,7 @@ EXAMPLES
673
673
  $ sf agent preview end --authoring-bundle My_Local_Agent
674
674
  ```
675
675
 
676
- _See code: [src/commands/agent/preview/end.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.13/src/commands/agent/preview/end.ts)_
676
+ _See code: [src/commands/agent/preview/end.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.15/src/commands/agent/preview/end.ts)_
677
677
 
678
678
  ## `sf agent preview send`
679
679
 
@@ -706,11 +706,11 @@ DESCRIPTION
706
706
  use this command to send the agent a message (utterance). This command then displays the agent's response.
707
707
 
708
708
  The original "agent preview start" command outputs a session ID which you then use with the --session-id flag of this
709
- command to send a message. You don't have to specify the --session-id flag if an agent has only one active preview
709
+ command to send a message. You don't have to specify the --session-id flag if an agent has only one active preview
710
710
  session. You must also use either the --authoring-bundle or --api-name flag to specify the API name of the authoring
711
- bundle or the published agent, respecitvely. To find either API name, navigate to your package directory in your DX
711
+ bundle or the published agent, respecitvely. To find either API name, navigate to your package directory in your DX
712
712
  project. The API name of an authoring bundle is the same as its directory name under the "aiAuthoringBundles" metadata
713
- directory. Similarly, the published agent's API name is the same as its directory name under the "Bots" metadata
713
+ directory. Similarly, the published agent's API name is the same as its directory name under the "Bots" metadata
714
714
  directory.
715
715
 
716
716
  EXAMPLES
@@ -731,7 +731,7 @@ EXAMPLES
731
731
  $ sf agent preview send --utterance "what can you help me with?" --authoring-bundle My_Local_Agent
732
732
  ```
733
733
 
734
- _See code: [src/commands/agent/preview/send.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.13/src/commands/agent/preview/send.ts)_
734
+ _See code: [src/commands/agent/preview/send.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.15/src/commands/agent/preview/send.ts)_
735
735
 
736
736
  ## `sf agent preview sessions`
737
737
 
@@ -764,7 +764,7 @@ EXAMPLES
764
764
  $ sf agent preview sessions
765
765
  ```
766
766
 
767
- _See code: [src/commands/agent/preview/sessions.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.13/src/commands/agent/preview/sessions.ts)_
767
+ _See code: [src/commands/agent/preview/sessions.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.15/src/commands/agent/preview/sessions.ts)_
768
768
 
769
769
  ## `sf agent preview start`
770
770
 
@@ -793,17 +793,17 @@ DESCRIPTION
793
793
  Start a programmatic agent preview session.
794
794
 
795
795
  This command outputs a session ID that you then use with the "agent preview send" command to send an utterance to the
796
- agent. Use the "agent preview sessions" command to list all active sessions and the "agent preview end" command to
797
- end a specific session.
796
+ agent. Use the "agent preview sessions" command to list all active sessions and the "agent preview end" command to end
797
+ a specific session.
798
798
 
799
799
  Identify the agent you want to start previewing with either the --authoring-bundle flag to specify a local authoring
800
- bundle's API name or --api-name to specify an activated published agent's API name. To find either API name, navigate
800
+ bundle's API name or --api-name to specify an activated published agent's API name. To find either API name, navigate
801
801
  to your package directory in your DX project. The API name of an authoring bundle is the same as its directory name
802
- under the "aiAuthoringBundles" metadata directory. Similarly, the published agent's API name is the same as its
802
+ under the "aiAuthoringBundles" metadata directory. Similarly, the published agent's API name is the same as its
803
803
  directory name under the "Bots" metadata directory.
804
804
 
805
805
  When starting a preview session using the authoring bundle, which contains the agent's Agent Script file, the preview
806
- uses mocked actions by default. Specify --use-live-actions for live mode, which uses the real Apex classes, flows,
806
+ uses mocked actions by default. Specify --use-live-actions for live mode, which uses the real Apex classes, flows,
807
807
  etc, in the org for the actions.
808
808
 
809
809
  EXAMPLES
@@ -821,7 +821,7 @@ EXAMPLES
821
821
  $ sf agent preview start --api-name My_Published_Agent
822
822
  ```
823
823
 
824
- _See code: [src/commands/agent/preview/start.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.13/src/commands/agent/preview/start.ts)_
824
+ _See code: [src/commands/agent/preview/start.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.15/src/commands/agent/preview/start.ts)_
825
825
 
826
826
  ## `sf agent publish authoring-bundle`
827
827
 
@@ -870,7 +870,7 @@ EXAMPLES
870
870
  $ sf agent publish authoring-bundle --api-name MyAuthoringbundle --target-org my-dev-org
871
871
  ```
872
872
 
873
- _See code: [src/commands/agent/publish/authoring-bundle.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.13/src/commands/agent/publish/authoring-bundle.ts)_
873
+ _See code: [src/commands/agent/publish/authoring-bundle.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.15/src/commands/agent/publish/authoring-bundle.ts)_
874
874
 
875
875
  ## `sf agent test create`
876
876
 
@@ -925,7 +925,7 @@ EXAMPLES
925
925
  $ sf agent test create --spec specs/Resort_Manager-testSpec.yaml --api-name Resort_Manager_Test --preview
926
926
  ```
927
927
 
928
- _See code: [src/commands/agent/test/create.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.13/src/commands/agent/test/create.ts)_
928
+ _See code: [src/commands/agent/test/create.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.15/src/commands/agent/test/create.ts)_
929
929
 
930
930
  ## `sf agent test list`
931
931
 
@@ -960,7 +960,7 @@ EXAMPLES
960
960
  $ sf agent test list --target-org my-org
961
961
  ```
962
962
 
963
- _See code: [src/commands/agent/test/list.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.13/src/commands/agent/test/list.ts)_
963
+ _See code: [src/commands/agent/test/list.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.15/src/commands/agent/test/list.ts)_
964
964
 
965
965
  ## `sf agent test results`
966
966
 
@@ -1026,7 +1026,7 @@ FLAG DESCRIPTIONS
1026
1026
  expression when using custom evaluations.
1027
1027
  ```
1028
1028
 
1029
- _See code: [src/commands/agent/test/results.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.13/src/commands/agent/test/results.ts)_
1029
+ _See code: [src/commands/agent/test/results.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.15/src/commands/agent/test/results.ts)_
1030
1030
 
1031
1031
  ## `sf agent test resume`
1032
1032
 
@@ -1099,7 +1099,7 @@ FLAG DESCRIPTIONS
1099
1099
  expression when using custom evaluations.
1100
1100
  ```
1101
1101
 
1102
- _See code: [src/commands/agent/test/resume.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.13/src/commands/agent/test/resume.ts)_
1102
+ _See code: [src/commands/agent/test/resume.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.15/src/commands/agent/test/resume.ts)_
1103
1103
 
1104
1104
  ## `sf agent test run`
1105
1105
 
@@ -1173,7 +1173,7 @@ FLAG DESCRIPTIONS
1173
1173
  expression when using custom evaluations.
1174
1174
  ```
1175
1175
 
1176
- _See code: [src/commands/agent/test/run.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.13/src/commands/agent/test/run.ts)_
1176
+ _See code: [src/commands/agent/test/run.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.15/src/commands/agent/test/run.ts)_
1177
1177
 
1178
1178
  ## `sf agent validate authoring-bundle`
1179
1179
 
@@ -1220,6 +1220,6 @@ EXAMPLES
1220
1220
  $ sf agent validate authoring-bundle --api-name MyAuthoringBundle --target-org my-dev-org
1221
1221
  ```
1222
1222
 
1223
- _See code: [src/commands/agent/validate/authoring-bundle.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.13/src/commands/agent/validate/authoring-bundle.ts)_
1223
+ _See code: [src/commands/agent/validate/authoring-bundle.ts](https://github.com/salesforcecli/plugin-agent/blob/1.32.15/src/commands/agent/validate/authoring-bundle.ts)_
1224
1224
 
1225
1225
  <!-- commandsstop -->
@@ -8,6 +8,8 @@ export default class AgentActivate extends SfCommand<AgentActivateResult> {
8
8
  static readonly description: string;
9
9
  static readonly examples: string[];
10
10
  static readonly enableJsonFlag = true;
11
+ static readonly envVariablesSection: import("@oclif/core").HelpSection;
12
+ static readonly errorCodes: import("@oclif/core").HelpSection;
11
13
  static readonly flags: {
12
14
  'target-org': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
13
15
  'api-version': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -13,8 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
17
- import { Messages } from '@salesforce/core';
16
+ import { SfCommand, Flags, toHelpSection } from '@salesforce/sf-plugins-core';
17
+ import { Messages, SfError, Lifecycle, EnvironmentVariable } from '@salesforce/core';
18
18
  import { getAgentForActivation, getVersionForActivation } from '../../agentActivation.js';
19
19
  Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
20
20
  const messages = Messages.loadMessages('@salesforce/plugin-agent', 'agent.activate');
@@ -23,6 +23,12 @@ export default class AgentActivate extends SfCommand {
23
23
  static description = messages.getMessage('description');
24
24
  static examples = messages.getMessages('examples');
25
25
  static enableJsonFlag = true;
26
+ static envVariablesSection = toHelpSection('ENVIRONMENT VARIABLES', EnvironmentVariable.SF_TARGET_ORG);
27
+ static errorCodes = toHelpSection('ERROR CODES', {
28
+ 'Succeeded (0)': 'Agent activated successfully.',
29
+ 'NotFound (2)': 'Agent not found in the org.',
30
+ 'ActivationFailed (4)': 'Failed to activate the agent due to API or network errors.',
31
+ });
26
32
  static flags = {
27
33
  'target-org': Flags.requiredOrg(),
28
34
  'api-version': Flags.orgApiVersion(),
@@ -39,15 +45,38 @@ export default class AgentActivate extends SfCommand {
39
45
  if (!apiNameFlag && this.jsonEnabled()) {
40
46
  throw messages.createError('error.missingRequiredFlags', ['api-name']);
41
47
  }
42
- const agent = await getAgentForActivation({ targetOrg, status: 'Active', apiNameFlag });
48
+ // Get agent with error tracking
49
+ let agent;
50
+ try {
51
+ agent = await getAgentForActivation({ targetOrg, status: 'Active', apiNameFlag });
52
+ }
53
+ catch (error) {
54
+ const wrapped = SfError.wrap(error);
55
+ if (wrapped.message.toLowerCase().includes('not found') || wrapped.message.toLowerCase().includes('no agent')) {
56
+ await Lifecycle.getInstance().emitTelemetry({ eventName: 'agent_activate_agent_not_found' });
57
+ throw new SfError(messages.getMessage('error.agentNotFound', [apiNameFlag ?? 'unknown']), 'AgentNotFound', [], 2, wrapped);
58
+ }
59
+ await Lifecycle.getInstance().emitTelemetry({ eventName: 'agent_activate_get_agent_failed' });
60
+ throw wrapped;
61
+ }
43
62
  const { version, warning } = await getVersionForActivation({
44
63
  agent,
45
64
  status: 'Active',
46
65
  versionFlag: flags.version,
47
66
  jsonEnabled: this.jsonEnabled(),
48
67
  });
49
- const result = await agent.activate(version);
68
+ // Activate with error tracking
69
+ let result;
70
+ try {
71
+ result = await agent.activate(version);
72
+ }
73
+ catch (error) {
74
+ const wrapped = SfError.wrap(error);
75
+ await Lifecycle.getInstance().emitTelemetry({ eventName: 'agent_activate_failed' });
76
+ throw new SfError(messages.getMessage('error.activationFailed', [wrapped.message]), 'ActivationFailed', [wrapped.message], 4, wrapped);
77
+ }
50
78
  const metadata = await agent.getBotMetadata();
79
+ await Lifecycle.getInstance().emitTelemetry({ eventName: 'agent_activate_success' });
51
80
  this.log(`${metadata.DeveloperName} v${result.VersionNumber} activated.`);
52
81
  if (warning) {
53
82
  this.warn(warning);
@@ -1 +1 @@
1
- {"version":3,"file":"activate.js","sourceRoot":"","sources":["../../../src/commands/agent/activate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAC;AAI1F,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,0BAA0B,EAAE,gBAAgB,CAAC,CAAC;AAErF,MAAM,CAAC,OAAO,OAAO,aAAc,SAAQ,SAA8B;IAChE,MAAM,CAAU,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACzD,MAAM,CAAU,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IACjE,MAAM,CAAU,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAC5D,MAAM,CAAU,cAAc,GAAG,IAAI,CAAC;IAEtC,MAAM,CAAU,KAAK,GAAG;QAC7B,YAAY,EAAE,KAAK,C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AAE,SAAS,EAAE,wBAAwB,EAAE,CAAC,CAAC;QAErF,IAAI,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,aAAa,KAAK,MAAM,CAAC,aAAa,aAAa,CAAC,CAAC;QAC1E,IAAI,OAAO,EAAE,CAAC;YACZ,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACrB,CAAC;QACD,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,aAAa,EAAE,CAAC;IAC1D,CAAC"}
@@ -5,6 +5,8 @@ export default class AgentDeactivate extends SfCommand<AgentActivateResult> {
5
5
  static readonly description: string;
6
6
  static readonly examples: string[];
7
7
  static enableJsonFlag: boolean;
8
+ static readonly envVariablesSection: import("@oclif/core").HelpSection;
9
+ static readonly errorCodes: import("@oclif/core").HelpSection;
8
10
  static readonly flags: {
9
11
  'target-org': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
10
12
  'api-version': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -13,8 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { SfCommand, Flags } from '@salesforce/sf-plugins-core';
17
- import { Messages } from '@salesforce/core';
16
+ import { SfCommand, Flags, toHelpSection } from '@salesforce/sf-plugins-core';
17
+ import { Messages, SfError, Lifecycle, EnvironmentVariable } from '@salesforce/core';
18
18
  import { getAgentForActivation } from '../../agentActivation.js';
19
19
  Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
20
20
  const messages = Messages.loadMessages('@salesforce/plugin-agent', 'agent.deactivate');
@@ -23,6 +23,12 @@ export default class AgentDeactivate extends SfCommand {
23
23
  static description = messages.getMessage('description');
24
24
  static examples = messages.getMessages('examples');
25
25
  static enableJsonFlag = true;
26
+ static envVariablesSection = toHelpSection('ENVIRONMENT VARIABLES', EnvironmentVariable.SF_TARGET_ORG);
27
+ static errorCodes = toHelpSection('ERROR CODES', {
28
+ 'Succeeded (0)': 'Agent deactivated successfully.',
29
+ 'NotFound (2)': 'Agent not found in the org.',
30
+ 'DeactivationFailed (4)': 'Failed to deactivate the agent due to API or network errors.',
31
+ });
26
32
  static flags = {
27
33
  'target-org': Flags.requiredOrg(),
28
34
  'api-version': Flags.orgApiVersion(),
@@ -38,9 +44,32 @@ export default class AgentDeactivate extends SfCommand {
38
44
  if (!apiNameFlag && this.jsonEnabled()) {
39
45
  throw messages.createError('error.missingRequiredFlags', ['api-name']);
40
46
  }
41
- const agent = await getAgentForActivation({ targetOrg, status: 'Inactive', apiNameFlag });
42
- const result = await agent.deactivate();
47
+ // Get agent with error tracking
48
+ let agent;
49
+ try {
50
+ agent = await getAgentForActivation({ targetOrg, status: 'Inactive', apiNameFlag });
51
+ }
52
+ catch (error) {
53
+ const wrapped = SfError.wrap(error);
54
+ if (wrapped.message.toLowerCase().includes('not found') || wrapped.message.toLowerCase().includes('no agent')) {
55
+ await Lifecycle.getInstance().emitTelemetry({ eventName: 'agent_deactivate_agent_not_found' });
56
+ throw new SfError(messages.getMessage('error.agentNotFound', [apiNameFlag ?? 'unknown']), 'AgentNotFound', [], 2, wrapped);
57
+ }
58
+ await Lifecycle.getInstance().emitTelemetry({ eventName: 'agent_deactivate_get_agent_failed' });
59
+ throw wrapped;
60
+ }
61
+ // Deactivate with error tracking
62
+ let result;
63
+ try {
64
+ result = await agent.deactivate();
65
+ }
66
+ catch (error) {
67
+ const wrapped = SfError.wrap(error);
68
+ await Lifecycle.getInstance().emitTelemetry({ eventName: 'agent_deactivate_failed' });
69
+ throw new SfError(messages.getMessage('error.deactivationFailed', [wrapped.message]), 'DeactivationFailed', [wrapped.message], 4, wrapped);
70
+ }
43
71
  const metadata = await agent.getBotMetadata();
72
+ await Lifecycle.getInstance().emitTelemetry({ eventName: 'agent_deactivate_success' });
44
73
  this.log(`${metadata.DeveloperName} v${result.VersionNumber} deactivated.`);
45
74
  return { success: true, version: result.VersionNumber };
46
75
  }
@@ -1 +1 @@
1
- {"version":3,"file":"deactivate.js","sourceRoot":"","sources":["../../../src/commands/agent/deactivate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAGjE,QAAQ,CAAC,kCAAkC,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7D,MAAM,QAAQ,GAAG,QAAQ,CAAC,YAAY,CAAC,0BAA0B,EAAE,kBAAkB,CAAC,CAAC;AAEvF,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,SAA8B;IAClE,MAAM,CAAU,OAAO,GAAG,QAAQ,CAAC,UAAU,CAAC,SAAS,CAAC,CAAC;IACzD,MAAM,CAAU,WAAW,GAAG,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;IACjE,MAAM,CAAU,QAAQ,GAAG,QAAQ,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;IAC5D,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC;IAE7B,MAAM,CAAU,KAAK,GAAG;QAC7B,YAAY,EAAE,KAAK,CAAC,WAAW,EAAE;QACjC,aAAa,EAAE,KAAK,CAAC,aAAa,EAAE;QACpC,UAAU,EAAE,KAAK,CAAC,MAAM,CAAC;YACvB,OAAO,EAAE,QAAQ,CAAC,UAAU,CAAC,wBAAwB,CAAC;YACtD,IAAI,EAAE,GAAG;SACV,CAAC;KACH,CAAC;IAEK,KAAK,CAAC,GAAG;QACd,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;QAEpD,MAAM,WAAW,GAAG,KAAK,CAAC,UAAU,CAAC,CAAC;QACtC,M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QAAQ,GAAG,MAAM,KAAK,CAAC,cAAc,EAAE,CAAC;QAC9C,MAAM,SAAS,CAAC,WAAW,EAAE,CAAC,aAAa,CAAC,EAAE,SAAS,EAAE,0BAA0B,EAAE,CAAC,CAAC;QAEvF,IAAI,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC,aAAa,KAAK,MAAM,CAAC,aAAa,eAAe,CAAC,CAAC;QAC5E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,CAAC,aAAa,EAAE,CAAC;IAC1D,CAAC"}
@@ -8,6 +8,8 @@ export default class AgentPreviewEnd extends SfCommand<AgentPreviewEndResult> {
8
8
  static readonly description: string;
9
9
  static readonly examples: string[];
10
10
  static readonly requiresProject = true;
11
+ static readonly envVariablesSection: import("@oclif/core").HelpSection;
12
+ static readonly errorCodes: import("@oclif/core").HelpSection;
11
13
  static readonly flags: {
12
14
  'target-org': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
13
15
  'api-version': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -13,8 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
17
- import { Messages, SfError } from '@salesforce/core';
16
+ import { Flags, SfCommand, toHelpSection } from '@salesforce/sf-plugins-core';
17
+ import { Messages, SfError, Lifecycle, EnvironmentVariable } from '@salesforce/core';
18
18
  import { Agent, ProductionAgent, ScriptAgent } from '@salesforce/agents';
19
19
  import { getCachedSessionIds, removeCache, validatePreviewSession } from '../../../previewSessionStore.js';
20
20
  Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
@@ -24,6 +24,13 @@ export default class AgentPreviewEnd extends SfCommand {
24
24
  static description = messages.getMessage('description');
25
25
  static examples = messages.getMessages('examples');
26
26
  static requiresProject = true;
27
+ static envVariablesSection = toHelpSection('ENVIRONMENT VARIABLES', EnvironmentVariable.SF_TARGET_ORG);
28
+ static errorCodes = toHelpSection('ERROR CODES', {
29
+ 'Succeeded (0)': 'Preview session ended successfully and traces saved.',
30
+ 'NotFound (2)': 'Agent not found, or no preview session exists for this agent.',
31
+ 'PreviewEndFailed (4)': 'Failed to end the preview session.',
32
+ 'SessionAmbiguous (5)': 'Multiple preview sessions found; specify --session-id to choose one.',
33
+ });
27
34
  static flags = {
28
35
  'target-org': Flags.requiredOrg(),
29
36
  'api-version': Flags.orgApiVersion(),
@@ -44,30 +51,60 @@ export default class AgentPreviewEnd extends SfCommand {
44
51
  async run() {
45
52
  const { flags } = await this.parse(AgentPreviewEnd);
46
53
  const conn = flags['target-org'].getConnection(flags['api-version']);
47
- const agent = flags['authoring-bundle']
48
- ? await Agent.init({ connection: conn, project: this.project, aabName: flags['authoring-bundle'] })
49
- : await Agent.init({ connection: conn, project: this.project, apiNameOrId: flags['api-name'] });
54
+ const agentIdentifier = flags['authoring-bundle'] ?? flags['api-name'];
55
+ // Initialize agent with error tracking
56
+ let agent;
57
+ try {
58
+ agent = flags['authoring-bundle']
59
+ ? await Agent.init({ connection: conn, project: this.project, aabName: flags['authoring-bundle'] })
60
+ : await Agent.init({ connection: conn, project: this.project, apiNameOrId: flags['api-name'] });
61
+ }
62
+ catch (error) {
63
+ const wrapped = SfError.wrap(error);
64
+ await Lifecycle.getInstance().emitTelemetry({ eventName: 'agent_preview_end_agent_not_found' });
65
+ throw new SfError(messages.getMessage('error.agentNotFound', [agentIdentifier]), 'AgentNotFound', [], 2, wrapped);
66
+ }
67
+ // Get or validate session ID
50
68
  let sessionId = flags['session-id'];
51
69
  if (sessionId === undefined) {
52
70
  const cached = await getCachedSessionIds(this.project, agent);
53
71
  if (cached.length === 0) {
54
- throw new SfError(messages.getMessage('error.noSession'), 'PreviewSessionNotFound');
72
+ await Lifecycle.getInstance().emitTelemetry({ eventName: 'agent_preview_end_no_session' });
73
+ throw new SfError(messages.getMessage('error.noSession'), 'PreviewSessionNotFound', [], 2);
55
74
  }
56
75
  if (cached.length > 1) {
57
- throw new SfError(messages.getMessage('error.multipleSessions', [cached.join(', ')]), 'PreviewSessionAmbiguous');
76
+ await Lifecycle.getInstance().emitTelemetry({ eventName: 'agent_preview_end_multiple_sessions' });
77
+ throw new SfError(messages.getMessage('error.multipleSessions', [cached.join(', ')]), 'PreviewSessionAmbiguous', [], 5);
58
78
  }
59
79
  sessionId = cached[0];
60
80
  }
61
81
  agent.setSessionId(sessionId);
62
- await validatePreviewSession(agent);
82
+ // Validate session
83
+ try {
84
+ await validatePreviewSession(agent);
85
+ }
86
+ catch (error) {
87
+ const wrapped = SfError.wrap(error);
88
+ await Lifecycle.getInstance().emitTelemetry({ eventName: 'agent_preview_end_session_invalid' });
89
+ throw new SfError(messages.getMessage('error.sessionInvalid', [sessionId]), 'PreviewSessionInvalid', [], 2, wrapped);
90
+ }
63
91
  const tracesPath = await agent.getHistoryDir();
64
92
  await removeCache(agent);
65
- if (agent instanceof ScriptAgent) {
66
- await agent.preview.end();
93
+ // End preview with error tracking
94
+ try {
95
+ if (agent instanceof ScriptAgent) {
96
+ await agent.preview.end();
97
+ }
98
+ else if (agent instanceof ProductionAgent) {
99
+ await agent.preview.end('UserRequest');
100
+ }
67
101
  }
68
- else if (agent instanceof ProductionAgent) {
69
- await agent.preview.end('UserRequest');
102
+ catch (error) {
103
+ const wrapped = SfError.wrap(error);
104
+ await Lifecycle.getInstance().emitTelemetry({ eventName: 'agent_preview_end_failed' });
105
+ throw new SfError(messages.getMessage('error.endFailed', [wrapped.message]), 'PreviewEndFailed', [wrapped.message], 4, wrapped);
70
106
  }
107
+ await Lifecycle.getInstance().emitTelemetry({ eventName: 'agent_preview_end_success' });
71
108
  const result = { sessionId, tracesPath };
72
109
  this.log(messages.getMessage('output.tracesPath', [tracesPath]));
73
110
  return result;
@@ -1 +1 @@
1
- {"version":3,"file":"end.js","sourceRoot":"","sources":["../../../../src/commands/agent/preview/end.ts"],"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;IAChB,CAAC"}
@@ -10,6 +10,8 @@ export default class AgentPreviewSend extends SfCommand<AgentPreviewSendResult>
10
10
  static readonly description: string;
11
11
  static readonly examples: string[];
12
12
  static readonly requiresProject = true;
13
+ static readonly envVariablesSection: import("@oclif/core").HelpSection;
14
+ static readonly errorCodes: import("@oclif/core").HelpSection;
13
15
  static readonly flags: {
14
16
  'target-org': import("@oclif/core/interfaces").OptionFlag<import("@salesforce/core").Org, import("@oclif/core/interfaces").CustomOptions>;
15
17
  'api-version': import("@oclif/core/interfaces").OptionFlag<string | undefined, import("@oclif/core/interfaces").CustomOptions>;
@@ -13,8 +13,8 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
- import { Flags, SfCommand } from '@salesforce/sf-plugins-core';
17
- import { Messages, SfError } from '@salesforce/core';
16
+ import { Flags, SfCommand, toHelpSection } from '@salesforce/sf-plugins-core';
17
+ import { Messages, SfError, Lifecycle, EnvironmentVariable } from '@salesforce/core';
18
18
  import { Agent } from '@salesforce/agents';
19
19
  import { getCachedSessionIds, validatePreviewSession } from '../../../previewSessionStore.js';
20
20
  Messages.importMessagesDirectoryFromMetaUrl(import.meta.url);
@@ -24,6 +24,13 @@ export default class AgentPreviewSend extends SfCommand {
24
24
  static description = messages.getMessage('description');
25
25
  static examples = messages.getMessages('examples');
26
26
  static requiresProject = true;
27
+ static envVariablesSection = toHelpSection('ENVIRONMENT VARIABLES', EnvironmentVariable.SF_TARGET_ORG);
28
+ static errorCodes = toHelpSection('ERROR CODES', {
29
+ 'Succeeded (0)': 'Message sent successfully and agent response received.',
30
+ 'NotFound (2)': 'Agent not found, or no preview session exists for this agent.',
31
+ 'PreviewSendFailed (4)': 'Failed to send message or receive response from the preview session.',
32
+ 'SessionAmbiguous (5)': 'Multiple preview sessions found; specify --session-id to choose one.',
33
+ });
27
34
  static flags = {
28
35
  'target-org': Flags.requiredOrg(),
29
36
  'api-version': Flags.orgApiVersion(),
@@ -49,23 +56,54 @@ export default class AgentPreviewSend extends SfCommand {
49
56
  async run() {
50
57
  const { flags } = await this.parse(AgentPreviewSend);
51
58
  const conn = flags['target-org'].getConnection(flags['api-version']);
52
- const agent = flags['authoring-bundle']
53
- ? await Agent.init({ connection: conn, project: this.project, aabName: flags['authoring-bundle'] })
54
- : await Agent.init({ connection: conn, project: this.project, apiNameOrId: flags['api-name'] });
59
+ const agentIdentifier = flags['authoring-bundle'] ?? flags['api-name'];
60
+ // Initialize agent with error tracking
61
+ let agent;
62
+ try {
63
+ agent = flags['authoring-bundle']
64
+ ? await Agent.init({ connection: conn, project: this.project, aabName: flags['authoring-bundle'] })
65
+ : await Agent.init({ connection: conn, project: this.project, apiNameOrId: flags['api-name'] });
66
+ }
67
+ catch (error) {
68
+ const wrapped = SfError.wrap(error);
69
+ await Lifecycle.getInstance().emitTelemetry({ eventName: 'agent_preview_send_agent_not_found' });
70
+ throw new SfError(messages.getMessage('error.agentNotFound', [agentIdentifier]), 'AgentNotFound', [], 2, wrapped);
71
+ }
72
+ // Get or validate session ID
55
73
  let sessionId = flags['session-id'];
56
74
  if (sessionId === undefined) {
57
75
  const cached = await getCachedSessionIds(this.project, agent);
58
76
  if (cached.length === 0) {
59
- throw new SfError(messages.getMessage('error.noSession'), 'PreviewSessionNotFound');
77
+ await Lifecycle.getInstance().emitTelemetry({ eventName: 'agent_preview_send_no_session' });
78
+ throw new SfError(messages.getMessage('error.noSession'), 'PreviewSessionNotFound', [], 2);
60
79
  }
61
80
  if (cached.length > 1) {
62
- throw new SfError(messages.getMessage('error.multipleSessions', [cached.join(', ')]), 'PreviewSessionAmbiguous');
81
+ await Lifecycle.getInstance().emitTelemetry({ eventName: 'agent_preview_send_multiple_sessions' });
82
+ throw new SfError(messages.getMessage('error.multipleSessions', [cached.join(', ')]), 'PreviewSessionAmbiguous', [], 5);
63
83
  }
64
84
  sessionId = cached[0];
65
85
  }
66
86
  agent.setSessionId(sessionId);
67
- await validatePreviewSession(agent);
68
- const response = await agent.preview.send(flags.utterance);
87
+ // Validate session
88
+ try {
89
+ await validatePreviewSession(agent);
90
+ }
91
+ catch (error) {
92
+ const wrapped = SfError.wrap(error);
93
+ await Lifecycle.getInstance().emitTelemetry({ eventName: 'agent_preview_send_session_invalid' });
94
+ throw new SfError(messages.getMessage('error.sessionInvalid', [sessionId]), 'PreviewSessionInvalid', [], 2, wrapped);
95
+ }
96
+ // Send message with error tracking
97
+ let response;
98
+ try {
99
+ response = await agent.preview.send(flags.utterance);
100
+ }
101
+ catch (error) {
102
+ const wrapped = SfError.wrap(error);
103
+ await Lifecycle.getInstance().emitTelemetry({ eventName: 'agent_preview_send_failed' });
104
+ throw new SfError(messages.getMessage('error.sendFailed', [wrapped.message]), 'PreviewSendFailed', [wrapped.message], 4, wrapped);
105
+ }
106
+ await Lifecycle.getInstance().emitTelemetry({ eventName: 'agent_preview_send_success' });
69
107
  this.log(response.messages[0].message);
70
108
  return { messages: response.messages ?? [] };
71
109
  }