@salesforce/agents 0.1.5 → 0.2.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,10 +1,9 @@
1
1
  import { Connection, SfProject } from '@salesforce/core';
2
2
  import { type SfAgent, type AgentCreateConfig, type AgentCreateResponse, type AgentJobSpec, type AgentJobSpecCreateConfig } from './types.js';
3
3
  export declare class Agent implements SfAgent {
4
- private connection;
5
4
  private project;
6
5
  private logger;
7
- private mockDir?;
6
+ private maybeMock;
8
7
  constructor(connection: Connection, project: SfProject);
9
8
  create(config: AgentCreateConfig): Promise<AgentCreateResponse>;
10
9
  /**
package/lib/agent.js CHANGED
@@ -7,22 +7,18 @@
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.Agent = void 0;
10
- const node_path_1 = require("node:path");
11
- const node_fs_1 = require("node:fs");
12
10
  const node_util_1 = require("node:util");
13
11
  const core_1 = require("@salesforce/core");
14
12
  const kit_1 = require("@salesforce/kit");
15
- const mockDir_1 = require("./mockDir");
13
+ const maybe_mock_1 = require("./maybe-mock");
16
14
  class Agent {
17
- connection;
18
15
  project;
19
16
  logger;
20
- mockDir;
17
+ maybeMock;
21
18
  constructor(connection, project) {
22
- this.connection = connection;
23
19
  this.project = project;
24
20
  this.logger = core_1.Logger.childFromRoot(this.constructor.name);
25
- this.mockDir = (0, mockDir_1.getMockDir)();
21
+ this.maybeMock = new maybe_mock_1.MaybeMock(connection);
26
22
  }
27
23
  async create(config) {
28
24
  this.logger.debug(`Creating Agent using config: ${(0, node_util_1.inspect)(config)} in project: ${this.project.getPath()}`);
@@ -40,51 +36,15 @@ class Agent {
40
36
  async createSpec(config) {
41
37
  this.verifyAgentSpecConfig(config);
42
38
  let agentSpec;
43
- if (this.mockDir) {
44
- const specFileName = `${config.name}.json`;
45
- const specFilePath = (0, node_path_1.join)(this.mockDir, `${specFileName}`);
46
- try {
47
- this.logger.debug(`Using mock directory: ${this.mockDir} for agent job spec creation`);
48
- (0, node_fs_1.statSync)(specFilePath);
49
- }
50
- catch (err) {
51
- throw core_1.SfError.create({
52
- name: 'MissingMockFile',
53
- message: `SF_MOCK_DIR [${this.mockDir}] must contain a spec file with name ${specFileName}`,
54
- cause: err,
55
- });
56
- }
57
- try {
58
- this.logger.debug(`Returning mock agent spec file: ${specFilePath}`);
59
- agentSpec = JSON.parse((0, node_fs_1.readFileSync)(specFilePath, 'utf8'));
60
- }
61
- catch (err) {
62
- throw core_1.SfError.create({
63
- name: 'InvalidMockFile',
64
- message: `SF_MOCK_DIR [${this.mockDir}] must contain a valid spec file with name ${specFileName}`,
65
- cause: err,
66
- actions: [
67
- 'Check that the file is readable',
68
- 'Check that the file is a valid JSON array of jobTitle and jobDescription objects',
69
- ],
70
- });
71
- }
39
+ const response = await this.maybeMock.request('GET', this.buildAgentJobSpecUrl(config));
40
+ if (response.isSuccess && response.jobSpecs) {
41
+ agentSpec = response.jobSpecs;
72
42
  }
73
43
  else {
74
- // TODO: We'll probably want to wrap this for better error handling but let's see
75
- // what it looks like first.
76
- const response = await this.connection.requestGet(this.buildAgentJobSpecUrl(config), {
77
- retry: { maxRetries: 3 },
44
+ throw core_1.SfError.create({
45
+ name: 'AgentJobSpecCreateError',
46
+ message: response.errorMessage ?? 'unknown',
78
47
  });
79
- if (response.isSuccess) {
80
- agentSpec = response?.jobSpecs;
81
- }
82
- else {
83
- throw core_1.SfError.create({
84
- name: 'AgentJobSpecCreateError',
85
- message: response.errorMessage ?? 'unknown',
86
- });
87
- }
88
48
  }
89
49
  return agentSpec;
90
50
  }
package/lib/agent.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"agent.js","sourceRoot":"","sources":["../src/agent.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,yCAAiC;AACjC,qCAAiD;AACjD,yCAAoC;AACpC,2CAA0E;AAC1E,yCAAkD;AAClD,uCAAuC;AAUvC,MAAa,KAAK;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,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,UAAU,CAAC,MAAgC;QACtD,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC;QAEnC,IAAI,SAAuB,CAAC;QAC5B,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,OAAO,CAA6B,KAAK,EAAE,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,CAAC,CAAC;QACpH,IAAI,QAAQ,CAAC,SAAS,IAAI,QAAQ,CAAC,QAAQ,EAAE,CAAC;YAC5C,SAAS,GAAG,QAAQ,CAAC,QAAQ,CAAC;QAChC,CAAC;aAAM,CAAC;YACN,MAAM,cAAO,CAAC,MAAM,CAAC;gBACnB,IAAI,EAAE,yBAAyB;gBAC/B,OAAO,EAAE,QAAQ,CAAC,YAAY,IAAI,SAAS;aAC5C,CAAC,CAAC;QACL,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,kDAAkD;IAC1C,qBAAqB,CAAC,MAAgC;QAC5D,6EAA6E;QAC7E,IAAI,MAAM;YAAE,OAAO;IACrB,CAAC;IAED,kDAAkD;IAC1C,oBAAoB,CAAC,MAAgC;QAC3D,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,WAAW,EAAE,kBAAkB,EAAE,cAAc,EAAE,GAAG,MAAM,CAAC;QAC/E,MAAM,OAAO,GAAG,cAAc,CAAC,CAAC,CAAC,mBAAmB,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1E,OAAO,qCAAqC,IAAI,SAAS,IAAI,gBAAgB,WAAW,uBAAuB,kBAAkB,GAAG,OAAO,EAAE,CAAC;IAChJ,CAAC;CACF;AAvDD,sBAuDC"}
@@ -0,0 +1,77 @@
1
+ import { Connection } from '@salesforce/core';
2
+ import { Duration } from '@salesforce/kit';
3
+ type Format = 'human' | 'json';
4
+ type TestStatus = 'NEW' | 'IN_PROGRESS' | 'COMPLETED' | 'ERROR';
5
+ type AgentTestStatusResponse = {
6
+ status: TestStatus;
7
+ startTime: string;
8
+ endTime?: string;
9
+ errorMessage?: string;
10
+ };
11
+ type TestCaseResult = {
12
+ status: TestStatus;
13
+ number: string;
14
+ startTime: string;
15
+ endTime?: string;
16
+ generatedData: {
17
+ type: 'AGENT';
18
+ actionsSequence: string[];
19
+ outcome: 'Success' | 'Failure';
20
+ topic: string;
21
+ inputTokensCount: string;
22
+ outputTokensCount: string;
23
+ };
24
+ expectationResults: Array<{
25
+ name: string;
26
+ actualValue: string;
27
+ expectedValue: string;
28
+ score: number;
29
+ result: 'Passed' | 'Failed';
30
+ metricLabel: 'Accuracy' | 'Precision';
31
+ metricExplainability: string;
32
+ status: TestStatus;
33
+ startTime: string;
34
+ endTime?: string;
35
+ errorCode?: string;
36
+ errorMessage?: string;
37
+ }>;
38
+ };
39
+ type AgentTestDetailsResponse = {
40
+ status: TestStatus;
41
+ startTime: string;
42
+ endTime?: string;
43
+ errorMessage?: string;
44
+ testCases: TestCaseResult[];
45
+ };
46
+ export declare class AgentTester {
47
+ private maybeMock;
48
+ constructor(connection: Connection);
49
+ /**
50
+ * Starts an AI evaluation run based on the provided name or ID.
51
+ *
52
+ * @param nameOrId - The name or ID of the AI evaluation definition.
53
+ * @param type - Specifies whether the provided identifier is a 'name' or 'id'. Defaults to 'name'. If 'name' is provided, nameOrId is treated as the name of the AiEvaluationDefinition. If 'id' is provided, nameOrId is treated as the unique ID of the AiEvaluationDefinition.
54
+ * @returns A promise that resolves to an object containing the ID of the started AI evaluation run.
55
+ */
56
+ start(nameOrId: string, type?: 'name' | 'id'): Promise<{
57
+ aiEvaluationId: string;
58
+ }>;
59
+ status(jobId: string): Promise<AgentTestStatusResponse>;
60
+ poll(jobId: string, { format, timeout, }?: {
61
+ format?: Format;
62
+ timeout?: Duration;
63
+ }): Promise<{
64
+ response: AgentTestDetailsResponse;
65
+ formatted: string;
66
+ }>;
67
+ details(jobId: string, format?: Format): Promise<{
68
+ response: AgentTestDetailsResponse;
69
+ formatted: string;
70
+ }>;
71
+ cancel(jobId: string): Promise<{
72
+ success: boolean;
73
+ }>;
74
+ }
75
+ export declare function humanFormat(name: string, details: AgentTestDetailsResponse): Promise<string>;
76
+ export declare function jsonFormat(details: AgentTestDetailsResponse): Promise<string>;
77
+ export {};
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AgentTester = void 0;
4
+ exports.humanFormat = humanFormat;
5
+ exports.jsonFormat = jsonFormat;
6
+ /*
7
+ * Copyright (c) 2024, salesforce.com, inc.
8
+ * All rights reserved.
9
+ * Licensed under the BSD 3-Clause license.
10
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
11
+ */
12
+ const core_1 = require("@salesforce/core");
13
+ const kit_1 = require("@salesforce/kit");
14
+ const maybe_mock_1 = require("./maybe-mock");
15
+ class AgentTester {
16
+ maybeMock;
17
+ constructor(connection) {
18
+ this.maybeMock = new maybe_mock_1.MaybeMock(connection);
19
+ }
20
+ /**
21
+ * Starts an AI evaluation run based on the provided name or ID.
22
+ *
23
+ * @param nameOrId - The name or ID of the AI evaluation definition.
24
+ * @param type - Specifies whether the provided identifier is a 'name' or 'id'. Defaults to 'name'. If 'name' is provided, nameOrId is treated as the name of the AiEvaluationDefinition. If 'id' is provided, nameOrId is treated as the unique ID of the AiEvaluationDefinition.
25
+ * @returns A promise that resolves to an object containing the ID of the started AI evaluation run.
26
+ */
27
+ async start(nameOrId, type = 'name') {
28
+ const url = '/einstein/ai-evaluations/runs';
29
+ return this.maybeMock.request('POST', url, {
30
+ [type === 'name' ? 'aiEvaluationDefinitionName' : 'aiEvaluationDefinitionVersionId']: nameOrId,
31
+ });
32
+ }
33
+ async status(jobId) {
34
+ const url = `/einstein/ai-evaluations/runs/${jobId}`;
35
+ return this.maybeMock.request('GET', url);
36
+ }
37
+ async poll(jobId, { format = 'human', timeout = kit_1.Duration.minutes(5), } = {
38
+ format: 'human',
39
+ timeout: kit_1.Duration.minutes(5),
40
+ }) {
41
+ const lifecycle = core_1.Lifecycle.getInstance();
42
+ const client = await core_1.PollingClient.create({
43
+ poll: async () => {
44
+ // NOTE: we don't actually need to call the status API here since all the same information is present on the
45
+ // details API. We could just call the details API and check the status there.
46
+ const [detailsResponse, statusResponse] = await Promise.all([this.details(jobId, format), this.status(jobId)]);
47
+ const totalTestCases = detailsResponse.response.testCases.length;
48
+ const failingTestCases = detailsResponse.response.testCases.filter((tc) => tc.status === 'ERROR').length;
49
+ const passingTestCases = detailsResponse.response.testCases.filter((tc) => tc.status === 'COMPLETED' && tc.expectationResults.every((r) => r.result === 'Passed')).length;
50
+ if (statusResponse.status.toLowerCase() === 'completed') {
51
+ await lifecycle.emit('AGENT_TEST_POLLING_EVENT', {
52
+ jobId,
53
+ status: statusResponse.status,
54
+ totalTestCases,
55
+ failingTestCases,
56
+ passingTestCases,
57
+ });
58
+ return { payload: await this.details(jobId, format), completed: true };
59
+ }
60
+ await lifecycle.emit('AGENT_TEST_POLLING_EVENT', {
61
+ jobId,
62
+ status: statusResponse.status,
63
+ totalTestCases,
64
+ failingTestCases,
65
+ passingTestCases,
66
+ });
67
+ return { completed: false };
68
+ },
69
+ frequency: kit_1.Duration.seconds(1),
70
+ timeout,
71
+ });
72
+ const result = await client.subscribe();
73
+ return result;
74
+ }
75
+ async details(jobId, format = 'human') {
76
+ const url = `/einstein/ai-evaluations/runs/${jobId}/details`;
77
+ const response = await this.maybeMock.request('GET', url);
78
+ return {
79
+ response,
80
+ formatted: format === 'human' ? await humanFormat(jobId, response) : await jsonFormat(response),
81
+ };
82
+ }
83
+ async cancel(jobId) {
84
+ const url = `/einstein/ai-evaluations/runs/${jobId}/cancel`;
85
+ return this.maybeMock.request('POST', url);
86
+ }
87
+ }
88
+ exports.AgentTester = AgentTester;
89
+ async function humanFormat(name, details) {
90
+ const { Ux } = await import('@salesforce/sf-plugins-core');
91
+ const ux = new Ux();
92
+ const tables = [];
93
+ for (const testCase of details.testCases) {
94
+ const table = ux.makeTable({
95
+ title: `Test Case #${testCase.number}`,
96
+ data: testCase.expectationResults.map((r) => ({
97
+ name: r.name,
98
+ outcome: r.result === 'Passed' ? 'Pass' : 'Fail',
99
+ actualValue: r.actualValue,
100
+ expectedValue: r.expectedValue,
101
+ score: r.score,
102
+ 'metric label': r.metricLabel,
103
+ message: r.errorMessage ?? '',
104
+ 'runtime (MS)': r.endTime ? new Date(r.endTime).getTime() - new Date(r.startTime).getTime() : 0,
105
+ })),
106
+ });
107
+ tables.push(table);
108
+ }
109
+ return tables.join('\n');
110
+ }
111
+ async function jsonFormat(details) {
112
+ return Promise.resolve(JSON.stringify(details, null, 2));
113
+ }
114
+ //# sourceMappingURL=agentTester.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agentTester.js","sourceRoot":"","sources":["../src/agentTester.ts"],"names":[],"mappings":";;;AAmKA,kCAsBC;AAED,gCAEC;AA7LD;;;;;GAKG;AACH,2CAAsF;AACtF,yCAA2C;AAC3C,6CAAyC;AAuDzC,MAAa,WAAW;IACd,SAAS,CAAY;IAC7B,YAAmB,UAAsB;QACvC,IAAI,CAAC,SAAS,GAAG,IAAI,sBAAS,CAAC,UAAU,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;;OAMG;IACI,KAAK,CAAC,KAAK,CAAC,QAAgB,EAAE,OAAsB,MAAM;QAC/D,MAAM,GAAG,GAAG,+BAA+B,CAAC;QAE5C,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAAyB,MAAM,EAAE,GAAG,EAAE;YACjE,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC,CAAC,4BAA4B,CAAC,CAAC,CAAC,iCAAiC,CAAC,EAAE,QAAQ;SAC/F,CAAC,CAAC;IACL,CAAC;IAEM,KAAK,CAAC,MAAM,CAAC,KAAa;QAC/B,MAAM,GAAG,GAAG,iCAAiC,KAAK,EAAE,CAAC;QAErD,OAAO,IAAI,CAAC,SAAS,CAAC,OAAO,CAA0B,KAAK,EAA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,UAAU,CAAC,OAAiC;IAChE,OAAO,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;AAC3D,CAAC"}
package/lib/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { AgentCreateConfig, AgentCreateResponse, AgentJobSpec, AgentJobSpecCreateConfig, AgentJobSpecCreateResponse, SfAgent, } from './types';
2
2
  export { Agent } from './agent';
3
+ export { AgentTester } from './agentTester';
package/lib/index.js CHANGED
@@ -6,7 +6,9 @@
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.Agent = void 0;
9
+ exports.AgentTester = exports.Agent = void 0;
10
10
  var agent_1 = require("./agent");
11
11
  Object.defineProperty(exports, "Agent", { enumerable: true, get: function () { return agent_1.Agent; } });
12
+ var agentTester_1 = require("./agentTester");
13
+ Object.defineProperty(exports, "AgentTester", { enumerable: true, get: function () { return agentTester_1.AgentTester; } });
12
14
  //# 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;;;AAUH,iCAAgC;AAAvB,8FAAA,KAAK,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAUH,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,6CAA4C;AAAnC,0GAAA,WAAW,OAAA"}
@@ -0,0 +1,10 @@
1
+ import { Connection } from '@salesforce/core';
2
+ import nock from 'nock';
3
+ export declare class MaybeMock {
4
+ private connection;
5
+ private mockDir;
6
+ private scopes;
7
+ private logger;
8
+ constructor(connection: Connection);
9
+ request<T extends nock.Body>(method: 'GET' | 'POST', url: string, body?: nock.RequestBodyMatcher): Promise<T>;
10
+ }
@@ -0,0 +1,154 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2024, 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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
9
+ return (mod && mod.__esModule) ? mod : { "default": mod };
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.MaybeMock = void 0;
13
+ const node_path_1 = require("node:path");
14
+ const node_fs_1 = require("node:fs");
15
+ const promises_1 = require("node:fs/promises");
16
+ const core_1 = require("@salesforce/core");
17
+ const kit_1 = require("@salesforce/kit");
18
+ const nock_1 = __importDefault(require("nock"));
19
+ /**
20
+ * If the `SF_MOCK_DIR` environment variable is set, resolve to an absolute path
21
+ * and ensure the directory exits, then return the path.
22
+ *
23
+ * NOTE: THIS SHOULD BE MOVED TO SOME OTHER LIBRARY LIKE `@salesforce/kit`.
24
+ *
25
+ * @returns the absolute path to an existing directory used for mocking behavior
26
+ */
27
+ const getMockDir = () => {
28
+ const mockDir = kit_1.env.getString('SF_MOCK_DIR');
29
+ if (mockDir) {
30
+ let mockDirStat;
31
+ try {
32
+ mockDirStat = (0, node_fs_1.statSync)((0, node_path_1.resolve)(mockDir));
33
+ }
34
+ catch (err) {
35
+ throw core_1.SfError.create({
36
+ name: 'InvalidMockDir',
37
+ message: `SF_MOCK_DIR [${mockDir}] not found`,
38
+ cause: err,
39
+ actions: [
40
+ "If you're trying to mock agent behavior you must create the mock directory and add expected mock files to it.",
41
+ ],
42
+ });
43
+ }
44
+ if (!mockDirStat.isDirectory()) {
45
+ throw core_1.SfError.create({
46
+ name: 'InvalidMockDir',
47
+ message: `SF_MOCK_DIR [${mockDir}] is not a directory`,
48
+ actions: [
49
+ "If you're trying to mock agent behavior you must create the mock directory and add expected mock files to it.",
50
+ ],
51
+ });
52
+ }
53
+ return mockDir;
54
+ }
55
+ };
56
+ async function readJson(path) {
57
+ return JSON.parse(await (0, promises_1.readFile)(path, 'utf-8'));
58
+ }
59
+ async function readPlainText(path) {
60
+ return (0, promises_1.readFile)(path, 'utf-8');
61
+ }
62
+ async function readDirectory(path) {
63
+ const files = await (0, promises_1.readdir)(path);
64
+ const promises = files.map((file) => {
65
+ if (file.endsWith('.json')) {
66
+ return readJson((0, node_path_1.join)(path, file));
67
+ }
68
+ else {
69
+ return readPlainText((0, node_path_1.join)(path, file));
70
+ }
71
+ });
72
+ return (await Promise.all(promises)).filter((r) => !!r);
73
+ }
74
+ async function readResponses(mockDir, url, logger) {
75
+ const mockResponseName = url.replace(/\//g, '_').replace(/^_/, '').split('?')[0];
76
+ const mockResponsePath = (0, node_path_1.join)(mockDir, mockResponseName);
77
+ // Try all possibilities for the mock response file
78
+ const responses = (await Promise.all([
79
+ readJson(`${mockResponsePath}.json`)
80
+ .then((r) => {
81
+ logger.debug(`Found JSON mock file: ${mockResponsePath}.json`);
82
+ return r;
83
+ })
84
+ .catch(() => undefined),
85
+ readPlainText(mockResponsePath)
86
+ .then((r) => {
87
+ logger.debug(`Found plain text mock file: ${mockResponsePath}`);
88
+ return r;
89
+ })
90
+ .catch(() => undefined),
91
+ readDirectory(mockResponsePath)
92
+ .then((r) => {
93
+ logger.debug(`Found directory of mock files: ${mockResponsePath}`);
94
+ return r;
95
+ })
96
+ .catch(() => undefined),
97
+ ]))
98
+ .filter((r) => !!r)
99
+ .flat();
100
+ if (responses.length === 0) {
101
+ throw core_1.SfError.create({
102
+ name: 'MissingMockFile',
103
+ message: `SF_MOCK_DIR [${mockDir}] must contain a spec file with name ${mockResponsePath} or ${mockResponsePath}.json`,
104
+ });
105
+ }
106
+ logger.debug(`Using responses: ${responses.map((r) => JSON.stringify(r)).join(', ')}`);
107
+ return responses;
108
+ }
109
+ class MaybeMock {
110
+ connection;
111
+ mockDir = getMockDir();
112
+ scopes = new Map();
113
+ logger;
114
+ constructor(connection) {
115
+ this.connection = connection;
116
+ this.logger = core_1.Logger.childFromRoot(this.constructor.name);
117
+ }
118
+ async request(method, url, body = {}) {
119
+ if (this.mockDir) {
120
+ this.logger.debug(`Mocking ${method} request to ${url} using ${this.mockDir}`);
121
+ const responses = await readResponses(this.mockDir, url, this.logger);
122
+ const baseUrl = this.connection.baseUrl();
123
+ const scope = this.scopes.get(baseUrl) ?? (0, nock_1.default)(baseUrl);
124
+ this.scopes.set(baseUrl, scope);
125
+ switch (method) {
126
+ case 'GET':
127
+ for (const response of responses) {
128
+ scope.get(url).reply(200, response);
129
+ }
130
+ break;
131
+ case 'POST':
132
+ for (const response of responses) {
133
+ scope.post(url, body).reply(200, response);
134
+ }
135
+ break;
136
+ }
137
+ }
138
+ this.logger.debug(`Making ${method} request to ${url}`);
139
+ switch (method) {
140
+ case 'GET':
141
+ return this.connection.requestGet(url, { retry: { maxRetries: 3 } });
142
+ case 'POST':
143
+ if (!body) {
144
+ throw core_1.SfError.create({
145
+ name: 'InvalidBody',
146
+ message: 'POST requests must include a body',
147
+ });
148
+ }
149
+ return this.connection.requestPost(url, body, { retry: { maxRetries: 3 } });
150
+ }
151
+ }
152
+ }
153
+ exports.MaybeMock = MaybeMock;
154
+ //# sourceMappingURL=maybe-mock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"maybe-mock.js","sourceRoot":"","sources":["../src/maybe-mock.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,yCAA0C;AAC1C,qCAA+C;AAC/C,+CAAqD;AACrD,2CAA+D;AAC/D,yCAAsC;AACtC,gDAAwB;AAExB;;;;;;;GAOG;AACH,MAAM,UAAU,GAAG,GAAuB,EAAE;IAC1C,MAAM,OAAO,GAAG,SAAG,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IAC7C,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,WAAkB,CAAC;QACvB,IAAI,CAAC;YACH,WAAW,GAAG,IAAA,kBAAQ,EAAC,IAAA,mBAA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AC;QACnF,CAAC;IACH,CAAC;CACF;AAhDD,8BAgDC"}
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.1.5",
4
+ "version": "0.2.0",
5
5
  "license": "BSD-3-Clause",
6
6
  "author": "Salesforce",
7
7
  "main": "lib/index",
@@ -11,11 +11,14 @@
11
11
  "url": "https://github.com/forcedotcom/agents.git"
12
12
  },
13
13
  "dependencies": {
14
+ "@oclif/table": "^0.3.3",
14
15
  "@salesforce/core": "^8.8.0",
15
- "@salesforce/kit": "^3.2.3"
16
+ "@salesforce/kit": "^3.2.3",
17
+ "@salesforce/sf-plugins-core": "^12.1.0",
18
+ "nock": "^13.5.6"
16
19
  },
17
20
  "devDependencies": {
18
- "@salesforce/cli-plugins-testkit": "^5.3.20",
21
+ "@salesforce/cli-plugins-testkit": "^5.3.38",
19
22
  "@salesforce/dev-scripts": "^10.2.10",
20
23
  "ts-node": "^10.9.2",
21
24
  "typescript": "^5.5.4"
package/lib/mockDir.d.ts DELETED
@@ -1,9 +0,0 @@
1
- /**
2
- * If the `SF_MOCK_DIR` environment variable is set, resolve to an absolue path
3
- * and ensure the directory exits, then return the path.
4
- *
5
- * NOTE: THIS SHOULD BE MOVED TO SOME OTHER LIBRARY LIKE `@salesforce/kit`.
6
- *
7
- * @returns the absolute path to an existing directory used for mocking behavior
8
- */
9
- export declare const getMockDir: () => string | undefined;
package/lib/mockDir.js DELETED
@@ -1,48 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2024, 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.getMockDir = void 0;
10
- const node_path_1 = require("node:path");
11
- const node_fs_1 = require("node:fs");
12
- const core_1 = require("@salesforce/core");
13
- const kit_1 = require("@salesforce/kit");
14
- /**
15
- * If the `SF_MOCK_DIR` environment variable is set, resolve to an absolue path
16
- * and ensure the directory exits, then return the path.
17
- *
18
- * NOTE: THIS SHOULD BE MOVED TO SOME OTHER LIBRARY LIKE `@salesforce/kit`.
19
- *
20
- * @returns the absolute path to an existing directory used for mocking behavior
21
- */
22
- const getMockDir = () => {
23
- const mockDir = kit_1.env.getString('SF_MOCK_DIR');
24
- if (mockDir) {
25
- let mockDirStat;
26
- try {
27
- mockDirStat = (0, node_fs_1.statSync)((0, node_path_1.resolve)(mockDir));
28
- }
29
- catch (err) {
30
- throw core_1.SfError.create({
31
- name: 'InvalidMockDir',
32
- message: `SF_MOCK_DIR [${mockDir}] not found`,
33
- cause: err,
34
- actions: ['If you\'re trying to mock agent behavior you must create the mock directory and add expected mock files to it.']
35
- });
36
- }
37
- if (!mockDirStat.isDirectory()) {
38
- throw core_1.SfError.create({
39
- name: 'InvalidMockDir',
40
- message: `SF_MOCK_DIR [${mockDir}] is not a directory`,
41
- actions: ['If you\'re trying to mock agent behavior you must create the mock directory and add expected mock files to it.']
42
- });
43
- }
44
- return mockDir;
45
- }
46
- };
47
- exports.getMockDir = getMockDir;
48
- //# sourceMappingURL=mockDir.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mockDir.js","sourceRoot":"","sources":["../src/mockDir.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,yCAAoC;AACpC,qCAA+C;AAC/C,2CAA2C;AAC3C,yCAAsC;AAEtC;;;;;;;GAOG;AACI,MAAM,UAAU,GAAG,GAAuB,EAAE;IACjD,MAAM,OAAO,GAAG,SAAG,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC;IAC7C,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,WAAkB,CAAC;QACvB,IAAI,CAAC;YACH,WAAW,GAAG,IAAA,kBAAQ,EAAC,IAAA,mBAAO,EAAC,OAAO,CAAC,CAAC,CAAC;QAC3C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,MAAM,cAAO,CAAC,MAAM,CAAC;gBACnB,IAAI,EAAE,gBAAgB;gBACtB,OAAO,EAAE,gBAAgB,OAAO,aAAa;gBAC7C,KAAK,EAAE,GAAG;gBACV,OAAO,EAAE,CAAC,gHAAgH,CAAC;aAC5H,CAAC,CAAC;QACL,CAAC;QAED,IAAI,CAAC,WAAW,CAAC,WAAW,EAAE,EAAE,CAAC;YAC/B,MAAM,cAAO,CAAC,MAAM,CAAC;gBACnB,IAAI,EAAE,gBAAgB;gBACtB,OAAO,EAAE,gBAAgB,OAAO,sBAAsB;gBACtD,OAAO,EAAE,CAAC,gHAAgH,CAAC;aAC5H,CAAC,CAAC;QACL,CAAC;QACD,OAAO,OAAO,CAAC;IACjB,CAAC;AACH,CAAC,CAAA;AAxBY,QAAA,UAAU,cAwBtB"}