@salesforce/agents 0.9.4 → 0.9.5-preview.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.
@@ -0,0 +1,61 @@
1
+ import { Connection } from '@salesforce/core';
2
+ type ApiStatus = {
3
+ status: 'UP' | 'DOWN';
4
+ };
5
+ type Href = {
6
+ href: string;
7
+ };
8
+ type Links = {
9
+ self: Href | null;
10
+ messages: Href | null;
11
+ session: Href | null;
12
+ end: Href | null;
13
+ };
14
+ type Message = {
15
+ type: string;
16
+ id: string;
17
+ feedbackId: string;
18
+ planId: string;
19
+ isContentSafe: boolean;
20
+ message: string;
21
+ result: {
22
+ type: string;
23
+ property: string;
24
+ value: any;
25
+ };
26
+ citedReferences: {
27
+ type: string;
28
+ value: string;
29
+ };
30
+ };
31
+ type StartResponse = {
32
+ sessionId: string;
33
+ _links: Links;
34
+ messages: Message[];
35
+ };
36
+ type SendResponse = {
37
+ messages: Message[];
38
+ _links: Links;
39
+ };
40
+ type EndResponse = {
41
+ messages: {
42
+ type: string;
43
+ id: string;
44
+ reason: string;
45
+ feedbackId: string;
46
+ };
47
+ _links: Links;
48
+ };
49
+ type EndReason = 'UserRequest' | 'Transfer' | 'Expiration' | 'Error' | 'Other';
50
+ export declare class AgentPreview {
51
+ private got;
52
+ private headers;
53
+ private instanceUrl;
54
+ private tempApiBase;
55
+ constructor(connection: Connection);
56
+ start(botId: string): Promise<StartResponse>;
57
+ send(sessionId: string, message: string): Promise<SendResponse>;
58
+ end(sessionId: string, reason: EndReason): Promise<EndResponse>;
59
+ status(): Promise<ApiStatus>;
60
+ }
61
+ export {};
@@ -0,0 +1,71 @@
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.AgentPreview = void 0;
10
+ const request_preview_1 = require("./request-preview");
11
+ class AgentPreview {
12
+ got;
13
+ headers;
14
+ instanceUrl;
15
+ tempApiBase = process.env.AFDX_TEMP_AGENT_API_BASE;
16
+ constructor(connection) {
17
+ this.got = new request_preview_1.RequestPreview();
18
+ const auth = process.env.AFDX_TEMP_AGENT_API_KEY;
19
+ const env = process.env.AFDX_TEMP_AGENT_ENV;
20
+ this.instanceUrl = connection.instanceUrl;
21
+ this.headers = {
22
+ 'x-sfdc-tenant-id': `core/${env}/${connection.getAuthInfoFields().orgId}`,
23
+ 'x-salesforce-region': process.env.AFDX_TEMP_AGENT_REGION,
24
+ Accept: 'application/json',
25
+ 'Content-Type': 'application/json',
26
+ Authorization: `API_KEY ${auth}`,
27
+ };
28
+ }
29
+ async start(botId) {
30
+ const url = `${this.tempApiBase}/einstein/ai-agent/v1/agents/${botId}/sessions`;
31
+ const body = {
32
+ // TODO: this needs to generate a unique guid
33
+ externalSessionKey: '44736288-030b-4080-b477-975a60f00a12',
34
+ instanceConfig: {
35
+ endpoint: `${this.instanceUrl}/`,
36
+ },
37
+ streamingCapabilities: {
38
+ chunkTypes: ['Text'],
39
+ },
40
+ variables: [],
41
+ };
42
+ return this.got.request('POST', url, body, this.headers);
43
+ }
44
+ async send(sessionId, message) {
45
+ const url = `${this.tempApiBase}/einstein/ai-agent/v1/sessions/${sessionId}/messages`;
46
+ const body = {
47
+ message: {
48
+ sequenceId: Date.now(),
49
+ type: 'Text',
50
+ text: message,
51
+ },
52
+ variables: [],
53
+ };
54
+ return this.got.request('POST', url, body, this.headers);
55
+ }
56
+ async end(sessionId, reason) {
57
+ const url = `${this.tempApiBase}/einstein/ai-agent/v1/sessions/${sessionId}`;
58
+ return this.got.request('DELETE', url, undefined, {
59
+ ...this.headers,
60
+ 'x-session-end-reason': reason,
61
+ });
62
+ }
63
+ // Get the status of the Agent API (UP | DOWN)
64
+ async status() {
65
+ const base = 'https://test.api.salesforce.com';
66
+ const url = `${base}/einstein/ai-agent/v1/status`;
67
+ return this.got.request('GET', url, undefined, this.headers);
68
+ }
69
+ }
70
+ exports.AgentPreview = AgentPreview;
71
+ //# sourceMappingURL=agentPreview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"agentPreview.js","sourceRoot":"","sources":["../src/agentPreview.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAGH,uDAAmD;AAyDnD,MAAa,YAAY;IACf,GAAG,CAAiB;IACpB,OAAO,CAAC;IACR,WAAW,CAAS;IACpB,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,wBAAkC,CAAC;IAErE,YAAmB,UAAsB;QACvC,IAAI,CAAC,GAAG,GAAG,IAAI,gCAAc,EAAE,CAAC;QAChC,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,uBAAiC,CAAC;QAC3D,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,mBAA6B,CAAC;QAEtD,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC,WAAW,CAAC;QAE1C,IAAI,CAAC,OAAO,GAAG;YACb,kBAAkB,EAAE,QAAQ,GAAG,IAAI,UAAU,CAAC,iBAAiB,EAAE,CAAC,KAAe,EAAE;YACnF,qBAAqB,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAgC;YACnE,MAAM,EAAE,kBAAkB;YAC1B,cAAc,EAAE,kBAAkB;YAClC,aAAa,EAAE,WAAW,IAAI,EAAE;SACjC,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,KAAK,CAAC,KAAa;QAC9B,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,WAAW,gCAAgC,KAAK,WAAW,CAAC;QAEhF,MAAM,IAAI,GAAG;YACX,6CAA6C;YAC7C,kBAAkB,EAAE,sCAAsC;YAC1D,cAAc,EAAE;gBACd,QAAQ,EAAE,GAAG,IAAI,CAAC,WAAW,GAAG;aACjC;YACD,qBAAqB,EAAE;gBACrB,UAAU,EAAE,CAAC,MAAM,CAAC;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entCreateConfigV2, type AgentCreateResponse, type AgentCreateResponseV2, type AgentJobSpec, type AgentJobSpecV2, type AgentJobSpecCreateConfig, type AgentJobSpecCreateConfigV2, type AgentJobSpecCreateResponse, type DraftAgentTopics, type DraftAgentTopicsBody, type DraftAgentTopicsResponse, SfAgent, } from './types';
2
2
  export { Agent, AgentCreateLifecycleStages, AgentCreateLifecycleStagesV2, generateAgentApiName } from './agent';
3
3
  export { AgentTester, convertTestResultsToFormat, generateTestSpec, AgentTestCreateLifecycleStages, type AvailableDefinition, type AgentTestResultsResponse, type AgentTestStartResponse, type AgentTestStatusResponse, type TestCaseResult, type TestStatus, } from './agentTester';
4
+ export { AgentPreview } from './agentPreview';
package/lib/index.js CHANGED
@@ -6,7 +6,7 @@
6
6
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
7
7
  */
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.AgentTestCreateLifecycleStages = exports.generateTestSpec = exports.convertTestResultsToFormat = exports.AgentTester = exports.generateAgentApiName = exports.AgentCreateLifecycleStagesV2 = exports.AgentCreateLifecycleStages = exports.Agent = void 0;
9
+ exports.AgentPreview = exports.AgentTestCreateLifecycleStages = exports.generateTestSpec = exports.convertTestResultsToFormat = exports.AgentTester = exports.generateAgentApiName = exports.AgentCreateLifecycleStagesV2 = exports.AgentCreateLifecycleStages = 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
12
  Object.defineProperty(exports, "AgentCreateLifecycleStages", { enumerable: true, get: function () { return agent_1.AgentCreateLifecycleStages; } });
@@ -17,4 +17,6 @@ Object.defineProperty(exports, "AgentTester", { enumerable: true, get: function
17
17
  Object.defineProperty(exports, "convertTestResultsToFormat", { enumerable: true, get: function () { return agentTester_1.convertTestResultsToFormat; } });
18
18
  Object.defineProperty(exports, "generateTestSpec", { enumerable: true, get: function () { return agentTester_1.generateTestSpec; } });
19
19
  Object.defineProperty(exports, "AgentTestCreateLifecycleStages", { enumerable: true, get: function () { return agentTester_1.AgentTestCreateLifecycleStages; } });
20
+ var agentPreview_1 = require("./agentPreview");
21
+ Object.defineProperty(exports, "AgentPreview", { enumerable: true, get: function () { return agentPreview_1.AgentPreview; } });
20
22
  //# 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;;;AAiBH,iCAAgH;AAAvG,8FAAA,KAAK,OAAA;AAAE,mHAAA,0BAA0B,OAAA;AAAE,qHAAA,4BAA4B,OAAA;AAAE,6GAAA,oBAAoB,OAAA;AAC9F,6CAWuB;AAVrB,0GAAA,WAAW,OAAA;AACX,yHAAA,0BAA0B,OAAA;AAC1B,+GAAA,gBAAgB,OAAA;AAChB,6HAAA,8BAA8B,OAAA"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAiBH,iCAAgH;AAAvG,8FAAA,KAAK,OAAA;AAAE,mHAAA,0BAA0B,OAAA;AAAE,qHAAA,4BAA4B,OAAA;AAAE,6GAAA,oBAAoB,OAAA;AAC9F,6CAWuB;AAVrB,0GAAA,WAAW,OAAA;AACX,yHAAA,0BAA0B,OAAA;AAC1B,+GAAA,gBAAgB,OAAA;AAChB,6HAAA,8BAA8B,OAAA;AAQhC,+CAA8C;AAArC,4GAAA,YAAY,OAAA"}
@@ -0,0 +1,5 @@
1
+ export declare class RequestPreview {
2
+ private logger;
3
+ constructor();
4
+ request<Response>(method: 'GET' | 'POST' | 'DELETE', url: string, body: Record<string, unknown> | undefined, headers?: Record<string, string>): Promise<Response>;
5
+ }
@@ -0,0 +1,39 @@
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.RequestPreview = void 0;
13
+ const core_1 = require("@salesforce/core");
14
+ const got_1 = __importDefault(require("got"));
15
+ class RequestPreview {
16
+ logger;
17
+ constructor() {
18
+ this.logger = core_1.Logger.childFromRoot(this.constructor.name);
19
+ }
20
+ async request(method, url, body, headers) {
21
+ this.logger.debug(`Making ${method} request to ${url}`);
22
+ switch (method) {
23
+ case 'GET':
24
+ return got_1.default.get(url, { headers }).json();
25
+ case 'POST':
26
+ if (!body) {
27
+ throw core_1.SfError.create({
28
+ name: 'InvalidBody',
29
+ message: 'POST requests must include a body',
30
+ });
31
+ }
32
+ return got_1.default.post(url, { headers, json: body }).json();
33
+ case 'DELETE':
34
+ return got_1.default.delete(url, { headers }).json();
35
+ }
36
+ }
37
+ }
38
+ exports.RequestPreview = RequestPreview;
39
+ //# sourceMappingURL=request-preview.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"request-preview.js","sourceRoot":"","sources":["../src/request-preview.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,2CAAmD;AACnD,8CAAsB;AAEtB,MAAa,cAAc;IACjB,MAAM,CAAS;IAEvB;QACE,IAAI,CAAC,MAAM,GAAG,aAAM,CAAC,aAAa,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC;IAEM,KAAK,CAAC,OAAO,CAClB,MAAiC,EACjC,GAAW,EACX,IAAyC,EACzC,OAAgC;QAEhC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,UAAU,MAAM,eAAe,GAAG,EAAE,CAAC,CAAC;QAExD,QAAQ,MAAM,EAAE,CAAC;YACf,KAAK,KAAK;gBACR,OAAO,aAAG,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;YAC1C,KAAK,MAAM;gBACT,IAAI,CAAC,IAAI,EAAE,CAAC;oBACV,MAAM,cAAO,CAAC,MAAM,CAAC;wBACnB,IAAI,EAAE,aAAa;wBACnB,OAAO,EAAE,mCAAmC;qBAC7C,CAAC,CAAC;gBACL,CAAC;gBACD,OAAO,aAAG,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;YACvD,KAAK,QAAQ;gBACX,OAAO,aAAG,CAAC,MAAM,CAAC,GAAG,EAAE,EAAE,OAAO,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;QAC/C,CAAC;IACH,CAAC;CACF;AA9BD,wCA8BC"}
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.9.4",
4
+ "version": "0.9.5-preview.0",
5
5
  "license": "BSD-3-Clause",
6
6
  "author": "Salesforce",
7
7
  "main": "lib/index",
@@ -17,6 +17,7 @@
17
17
  "@salesforce/source-deploy-retrieve": "^12.14.1",
18
18
  "ansis": "^3.10.0",
19
19
  "fast-xml-parser": "^4.5.1",
20
+ "got": "^11.8.6",
20
21
  "nock": "^13.5.6",
21
22
  "yaml": "^2.7.0"
22
23
  },