@salesforce/agents 0.20.0 → 0.21.1
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/README.md +2 -0
- package/lib/agent.d.ts +25 -86
- package/lib/agent.js +90 -310
- package/lib/agent.js.map +1 -1
- package/lib/agentTest.js +1 -1
- package/lib/agentTestResults.js +1 -1
- package/lib/agentTester.js +1 -1
- package/lib/agents/agentBase.d.ts +77 -0
- package/lib/agents/agentBase.js +106 -0
- package/lib/agents/agentBase.js.map +1 -0
- package/lib/agents/productionAgent.d.ts +57 -0
- package/lib/agents/productionAgent.js +368 -0
- package/lib/agents/productionAgent.js.map +1 -0
- package/lib/agents/scriptAgent.d.ts +69 -0
- package/lib/agents/scriptAgent.js +463 -0
- package/lib/agents/scriptAgent.js.map +1 -0
- package/lib/{agentPublisher.d.ts → agents/scriptAgentPublisher.d.ts} +23 -10
- package/lib/{agentPublisher.js → agents/scriptAgentPublisher.js} +42 -17
- package/lib/agents/scriptAgentPublisher.js.map +1 -0
- package/lib/apexUtils.js +1 -1
- package/lib/index.d.ts +4 -5
- package/lib/index.js +8 -10
- package/lib/index.js.map +1 -1
- package/lib/maybe-mock.js +1 -1
- package/lib/templates/agentScriptTemplate.d.ts +9 -0
- package/lib/templates/agentScriptTemplate.js +149 -0
- package/lib/templates/agentScriptTemplate.js.map +1 -0
- package/lib/types.d.ts +44 -13
- package/lib/types.js +1 -1
- package/lib/types.js.map +1 -1
- package/lib/utils.d.ts +68 -7
- package/lib/utils.js +215 -20
- package/lib/utils.js.map +1 -1
- package/package.json +3 -3
- package/lib/agentPreview.d.ts +0 -78
- package/lib/agentPreview.js +0 -258
- package/lib/agentPreview.js.map +0 -1
- package/lib/agentPreviewBase.d.ts +0 -59
- package/lib/agentPreviewBase.js +0 -55
- package/lib/agentPreviewBase.js.map +0 -1
- package/lib/agentPublisher.js.map +0 -1
- package/lib/agentSimulate.d.ts +0 -79
- package/lib/agentSimulate.js +0 -297
- package/lib/agentSimulate.js.map +0 -1
- package/lib/agentTrace.d.ts +0 -23
- package/lib/agentTrace.js +0 -47
- package/lib/agentTrace.js.map +0 -1
package/lib/utils.js
CHANGED
|
@@ -33,9 +33,10 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
33
33
|
};
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.readTranscriptEntries = exports.
|
|
36
|
+
exports.readTranscriptEntries = exports.getAllHistory = exports.updateMetadataEndTime = exports.writeMetaFileToHistory = exports.writeTraceToHistory = exports.appendTranscriptToHistory = exports.getHistoryDir = exports.useNamedUserJwt = exports.findLocalAgents = exports.findAuthoringBundle = exports.decodeHtmlEntities = exports.sanitizeFilename = exports.metric = void 0;
|
|
37
|
+
exports.getEndpoint = getEndpoint;
|
|
37
38
|
/*
|
|
38
|
-
* Copyright
|
|
39
|
+
* Copyright 2026, Salesforce, Inc.
|
|
39
40
|
*
|
|
40
41
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
41
42
|
* you may not use this file except in compliance with the License.
|
|
@@ -53,6 +54,7 @@ const node_fs_1 = require("node:fs");
|
|
|
53
54
|
const promises_1 = require("node:fs/promises");
|
|
54
55
|
const path = __importStar(require("node:path"));
|
|
55
56
|
const core_1 = require("@salesforce/core");
|
|
57
|
+
const kit_1 = require("@salesforce/kit");
|
|
56
58
|
exports.metric = ['completeness', 'coherence', 'conciseness', 'output_latency_milliseconds'];
|
|
57
59
|
/**
|
|
58
60
|
* Sanitize a filename by removing or replacing illegal characters.
|
|
@@ -190,6 +192,12 @@ const findLocalAgents = (dir) => {
|
|
|
190
192
|
return results;
|
|
191
193
|
};
|
|
192
194
|
exports.findLocalAgents = findLocalAgents;
|
|
195
|
+
/**
|
|
196
|
+
* takes a connection and upgrades it to a NamedJWT connection
|
|
197
|
+
*
|
|
198
|
+
* @param {Connection} connection original Connection
|
|
199
|
+
* @returns {Promise<Connection>} upgraded connection
|
|
200
|
+
*/
|
|
193
201
|
const useNamedUserJwt = async (connection) => {
|
|
194
202
|
// Refresh the connection to ensure we have the latest, valid access token
|
|
195
203
|
try {
|
|
@@ -248,39 +256,226 @@ const resolveProjectLocalSfdx = async () => {
|
|
|
248
256
|
return undefined;
|
|
249
257
|
}
|
|
250
258
|
};
|
|
251
|
-
|
|
259
|
+
/**
|
|
260
|
+
* returns a path, and ensures it's created, to the agents history directory
|
|
261
|
+
*
|
|
262
|
+
* Initialize session directory
|
|
263
|
+
* Session directory structure:
|
|
264
|
+
* .sfdx/agents/<agentId>/sessions/<sessionId>/
|
|
265
|
+
* ├── transcript.jsonl # All transcript entries (one per line)
|
|
266
|
+
* ├── traces/ # Individual trace files
|
|
267
|
+
* │ ├── <planId1>.json
|
|
268
|
+
* │ └── <planId2>.json
|
|
269
|
+
* └── metadata.json # Session metadata (start time, end time, planIds, etc.)
|
|
270
|
+
*
|
|
271
|
+
* @param {string} agentId gotten from Agent.getAgentIdForStorage()
|
|
272
|
+
* @param {string} sessionId the preview's start call .SessionId
|
|
273
|
+
* @returns {Promise<string>} path to where history/metadata/transcripts are stored inside of local .sfdx
|
|
274
|
+
*/
|
|
275
|
+
const getHistoryDir = async (agentId, sessionId) => {
|
|
252
276
|
const base = (await resolveProjectLocalSfdx()) ?? path.join(process.cwd(), '.sfdx');
|
|
253
|
-
const dir = path.join(base, 'agents', agentId);
|
|
277
|
+
const dir = path.join(base, 'agents', agentId, 'sessions', sessionId);
|
|
254
278
|
await (0, promises_1.mkdir)(dir, { recursive: true });
|
|
255
279
|
return dir;
|
|
256
280
|
};
|
|
257
|
-
|
|
281
|
+
exports.getHistoryDir = getHistoryDir;
|
|
258
282
|
/**
|
|
259
|
-
* Append a transcript entry to the
|
|
260
|
-
*
|
|
261
|
-
*
|
|
283
|
+
* Append a transcript entry to the transcript.jsonl transcript file
|
|
284
|
+
*
|
|
285
|
+
* @param {TranscriptEntry} entry to save
|
|
286
|
+
* @param {string} sessionDir the preview's start call .SessionId
|
|
287
|
+
* @returns {Promise<void>}
|
|
262
288
|
*/
|
|
263
|
-
const
|
|
264
|
-
const
|
|
289
|
+
const appendTranscriptToHistory = async (entry, sessionDir) => {
|
|
290
|
+
const transcriptPath = path.join(sessionDir, 'transcript.jsonl');
|
|
265
291
|
const line = `${JSON.stringify(entry)}\n`;
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
292
|
+
await (0, promises_1.appendFile)(transcriptPath, line, 'utf-8');
|
|
293
|
+
};
|
|
294
|
+
exports.appendTranscriptToHistory = appendTranscriptToHistory;
|
|
295
|
+
/**
|
|
296
|
+
* writes a trace to <plan-id>.json in history directory
|
|
297
|
+
*
|
|
298
|
+
* @param {string} planId
|
|
299
|
+
* @param {PlannerResponse | undefined} trace
|
|
300
|
+
* @param {string} historyDir
|
|
301
|
+
* @returns {Promise<void>}
|
|
302
|
+
*/
|
|
303
|
+
const writeTraceToHistory = async (planId, trace, historyDir) => {
|
|
304
|
+
const tracesDir = path.join(historyDir, 'traces');
|
|
305
|
+
await (0, promises_1.mkdir)(tracesDir, { recursive: true });
|
|
306
|
+
const tracePath = path.join(tracesDir, `${planId}.json`);
|
|
307
|
+
await (0, promises_1.writeFile)(tracePath, JSON.stringify(trace ?? {}, null, 2), 'utf-8');
|
|
308
|
+
};
|
|
309
|
+
exports.writeTraceToHistory = writeTraceToHistory;
|
|
310
|
+
/**
|
|
311
|
+
* Write preview metadata to the history directory
|
|
312
|
+
*/
|
|
313
|
+
const writeMetaFileToHistory = async (historyDir, metadata) => {
|
|
314
|
+
const metadataPath = path.join(historyDir, 'metadata.json');
|
|
315
|
+
await (0, promises_1.writeFile)(metadataPath, JSON.stringify(metadata, null, 2), 'utf-8');
|
|
316
|
+
};
|
|
317
|
+
exports.writeMetaFileToHistory = writeMetaFileToHistory;
|
|
318
|
+
/**
|
|
319
|
+
* Calculates the correct endpoint based on env vars
|
|
320
|
+
*
|
|
321
|
+
* @returns {string}
|
|
322
|
+
*/
|
|
323
|
+
function getEndpoint() {
|
|
324
|
+
return kit_1.env.getBoolean('SF_TEST_API') ? 'test.' : '';
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Update preview metadata with end time and plan IDs
|
|
328
|
+
*/
|
|
329
|
+
const updateMetadataEndTime = async (historyDir, endTime, planIds) => {
|
|
330
|
+
const metadataPath = path.join(historyDir, 'metadata.json');
|
|
331
|
+
try {
|
|
332
|
+
const metadata = JSON.parse(await (0, promises_1.readFile)(metadataPath, 'utf-8'));
|
|
333
|
+
metadata.endTime = endTime;
|
|
334
|
+
metadata.planIds = Array.from(planIds);
|
|
335
|
+
await (0, promises_1.writeFile)(metadataPath, JSON.stringify(metadata, null, 2), 'utf-8');
|
|
336
|
+
}
|
|
337
|
+
catch {
|
|
338
|
+
// If metadata doesn't exist, create it
|
|
339
|
+
await (0, exports.writeMetaFileToHistory)(historyDir, {
|
|
340
|
+
sessionId: '',
|
|
341
|
+
agentId: '',
|
|
342
|
+
startTime: '',
|
|
343
|
+
endTime,
|
|
344
|
+
planIds: Array.from(planIds),
|
|
345
|
+
});
|
|
346
|
+
}
|
|
347
|
+
};
|
|
348
|
+
exports.updateMetadataEndTime = updateMetadataEndTime;
|
|
349
|
+
/**
|
|
350
|
+
* Find the most recent session ID for an agent by checking metadata.json startTime
|
|
351
|
+
*
|
|
352
|
+
* @param agentId gotten from Agent.getAgentIdForStorage()
|
|
353
|
+
* @returns The most recent sessionId, or undefined if no sessions found
|
|
354
|
+
*/
|
|
355
|
+
const findMostRecentSessionId = async (agentId) => {
|
|
356
|
+
const base = (await resolveProjectLocalSfdx()) ?? path.join(process.cwd(), '.sfdx');
|
|
357
|
+
const sessionsDir = path.join(base, 'agents', agentId, 'sessions');
|
|
358
|
+
try {
|
|
359
|
+
const sessionDirs = await (0, promises_1.readdir)(sessionsDir);
|
|
360
|
+
if (sessionDirs.length === 0) {
|
|
361
|
+
return undefined;
|
|
362
|
+
}
|
|
363
|
+
// Get all sessions with their metadata to find the most recent
|
|
364
|
+
const sessionPromises = sessionDirs.map(async (sessionId) => {
|
|
365
|
+
const sessionPath = path.join(sessionsDir, sessionId);
|
|
366
|
+
const metadataPath = path.join(sessionPath, 'metadata.json');
|
|
367
|
+
try {
|
|
368
|
+
const metadataData = await (0, promises_1.readFile)(metadataPath, 'utf-8');
|
|
369
|
+
const metadata = JSON.parse(metadataData);
|
|
370
|
+
const statResult = await (0, promises_1.stat)(sessionPath);
|
|
371
|
+
return {
|
|
372
|
+
sessionId,
|
|
373
|
+
startTime: metadata.startTime ? new Date(metadata.startTime).getTime() : statResult.mtimeMs,
|
|
374
|
+
mtime: statResult.mtimeMs,
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
catch {
|
|
378
|
+
// If metadata doesn't exist or can't be read, use directory modification time
|
|
379
|
+
try {
|
|
380
|
+
const statResult = await (0, promises_1.stat)(sessionPath);
|
|
381
|
+
return {
|
|
382
|
+
sessionId,
|
|
383
|
+
startTime: statResult.mtimeMs,
|
|
384
|
+
mtime: statResult.mtimeMs,
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
catch {
|
|
388
|
+
return null;
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
const sessions = (await Promise.all(sessionPromises)).filter((s) => s !== null);
|
|
393
|
+
if (sessions.length === 0) {
|
|
394
|
+
return undefined;
|
|
395
|
+
}
|
|
396
|
+
// Sort by startTime (most recent first), fallback to mtime
|
|
397
|
+
sessions.sort((a, b) => b.startTime - a.startTime);
|
|
398
|
+
return sessions[0].sessionId;
|
|
399
|
+
}
|
|
400
|
+
catch {
|
|
401
|
+
// Sessions directory doesn't exist or can't be read
|
|
402
|
+
return undefined;
|
|
403
|
+
}
|
|
404
|
+
};
|
|
405
|
+
/**
|
|
406
|
+
* Get all history data for a session including metadata, transcript, and traces
|
|
407
|
+
*
|
|
408
|
+
* @param agentId gotten from Agent.getAgentIdForStorage()
|
|
409
|
+
* @param sessionId optional - the preview sessions' ID, gotten originally from /start .SessionId. If not provided, returns the most recent conversation
|
|
410
|
+
* @returns Object containing parsed metadata, transcript entries, and traces
|
|
411
|
+
*/
|
|
412
|
+
const getAllHistory = async (agentId, sessionId) => {
|
|
413
|
+
// If sessionId is not provided, find the most recent session
|
|
414
|
+
let actualSessionId = sessionId;
|
|
415
|
+
if (!actualSessionId) {
|
|
416
|
+
actualSessionId = await findMostRecentSessionId(agentId);
|
|
417
|
+
if (!actualSessionId) {
|
|
418
|
+
throw core_1.SfError.create({
|
|
419
|
+
name: 'NoSessionFound',
|
|
420
|
+
message: `No sessions found for agent ${agentId}`,
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
const historyDir = await (0, exports.getHistoryDir)(agentId, actualSessionId);
|
|
425
|
+
const result = {
|
|
426
|
+
metadata: null,
|
|
427
|
+
transcript: [],
|
|
428
|
+
traces: [],
|
|
429
|
+
};
|
|
430
|
+
// Read metadata.json
|
|
431
|
+
try {
|
|
432
|
+
const metadataPath = path.join(historyDir, 'metadata.json');
|
|
433
|
+
const metadataData = await (0, promises_1.readFile)(metadataPath, 'utf-8');
|
|
434
|
+
result.metadata = JSON.parse(metadataData);
|
|
435
|
+
}
|
|
436
|
+
catch {
|
|
437
|
+
// Metadata file doesn't exist or can't be read - leave as null
|
|
438
|
+
}
|
|
439
|
+
// Read transcript.jsonl
|
|
440
|
+
try {
|
|
441
|
+
const transcriptPath = path.join(historyDir, 'transcript.jsonl');
|
|
442
|
+
const transcriptData = await (0, promises_1.readFile)(transcriptPath, 'utf-8');
|
|
443
|
+
result.transcript = transcriptData
|
|
444
|
+
.split('\n')
|
|
445
|
+
.filter((line) => line.trim().length > 0)
|
|
446
|
+
.map((line) => JSON.parse(line));
|
|
447
|
+
}
|
|
448
|
+
catch {
|
|
449
|
+
// Transcript file doesn't exist or can't be read - leave as empty array
|
|
450
|
+
}
|
|
451
|
+
// Read all trace files from traces/ directory
|
|
452
|
+
try {
|
|
453
|
+
const tracesDir = path.join(historyDir, 'traces');
|
|
454
|
+
const files = await (0, promises_1.readdir)(tracesDir);
|
|
455
|
+
const tracePromises = files
|
|
456
|
+
.filter((file) => file.endsWith('.json'))
|
|
457
|
+
.map(async (file) => {
|
|
458
|
+
const tracePath = path.join(tracesDir, file);
|
|
459
|
+
const traceData = await (0, promises_1.readFile)(tracePath, 'utf-8');
|
|
460
|
+
return JSON.parse(traceData);
|
|
461
|
+
});
|
|
462
|
+
result.traces = await Promise.all(tracePromises);
|
|
269
463
|
}
|
|
270
|
-
|
|
271
|
-
|
|
464
|
+
catch {
|
|
465
|
+
// Traces directory doesn't exist or can't be read - leave as empty array
|
|
272
466
|
}
|
|
467
|
+
return result;
|
|
273
468
|
};
|
|
274
|
-
exports.
|
|
469
|
+
exports.getAllHistory = getAllHistory;
|
|
275
470
|
/**
|
|
276
471
|
* Read and parse the last conversation's transcript entries from JSON.
|
|
277
|
-
* Path: <project>/.sfdx/agents/conversations/<agentId>/history.json
|
|
278
472
|
*
|
|
279
|
-
* @param agentId
|
|
473
|
+
* @param agentId gotten from Agent.getAgentIdForStorage()
|
|
474
|
+
* @param sessionId the preview sessions' ID, gotten originally from /start .SessionId
|
|
280
475
|
* @returns Array of TranscriptEntry in file order (chronological append order).
|
|
281
476
|
*/
|
|
282
|
-
const readTranscriptEntries = async (agentId) => {
|
|
283
|
-
const filePath = await
|
|
477
|
+
const readTranscriptEntries = async (agentId, sessionId) => {
|
|
478
|
+
const filePath = await (0, exports.getHistoryDir)(agentId, sessionId);
|
|
284
479
|
try {
|
|
285
480
|
const data = await (0, promises_1.readFile)(filePath, 'utf-8');
|
|
286
481
|
return data
|
package/lib/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;;;;;;;;;;;;;GAcG;AACH,qCAAgD;AAChD,+CAA0E;AAC1E,gDAAkC;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ACrD,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAoB,CAAC;QAClD,CAAC,CAAC,CAAC;QACL,MAAM,CAAC,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC;IACnD,CAAC;IAAC,MAAM,CAAC;QACP,yEAAyE;IAC3E,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AArEW,QAAA,aAAa,iBAqExB;AAEF;;;;;;GAMG;AACI,MAAM,qBAAqB,GAAG,KAAK,EAAE,OAAe,EAAE,SAAiB,EAA8B,EAAE;IAC5G,MAAM,QAAQ,GAAG,MAAM,IAAA,qBAAa,EAAC,OAAO,EAAE,SAAS,CAAC,CAAC;IACzD,IAAI,CAAC;QACH,MAAM,IAAI,GAAG,MAAM,IAAA,mBAAQ,EAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC/C,OAAO,IAAI;aACR,KAAK,CAAC,IAAI,CAAC;aACX,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC;aAClC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAoB,CAAC,CAAC;IAClD,CAAC;IAAC,OAAO,EAAE,EAAE,CAAC;QACZ,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC,CAAC;AAXW,QAAA,qBAAqB,yBAWhC"}
|
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.
|
|
4
|
+
"version": "0.21.1",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "Salesforce",
|
|
7
7
|
"main": "lib/index",
|
|
@@ -11,9 +11,9 @@
|
|
|
11
11
|
"url": "https://github.com/forcedotcom/agents.git"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@salesforce/core": "^8.
|
|
14
|
+
"@salesforce/core": "^8.24.0",
|
|
15
15
|
"@salesforce/kit": "^3.2.4",
|
|
16
|
-
"@salesforce/source-deploy-retrieve": "^12.
|
|
16
|
+
"@salesforce/source-deploy-retrieve": "^12.31.6",
|
|
17
17
|
"@salesforce/types": "^1.5.0",
|
|
18
18
|
"fast-xml-parser": "^5.3.2",
|
|
19
19
|
"nock": "^13.5.6",
|
package/lib/agentPreview.d.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { Connection } from '@salesforce/core';
|
|
2
|
-
import { AgentPreviewBase } from './agentPreviewBase';
|
|
3
|
-
import { type AgentPreviewStartResponse, type AgentPreviewSendResponse, type AgentPreviewEndResponse, type ApiStatus, type EndReason, PlannerResponse } from './types.js';
|
|
4
|
-
/**
|
|
5
|
-
* A service to interact with an agent. Start an interactive session,
|
|
6
|
-
* send messages to the agent, and end the session.
|
|
7
|
-
*
|
|
8
|
-
* **Examples**
|
|
9
|
-
*
|
|
10
|
-
* Create an instance of the service:
|
|
11
|
-
*
|
|
12
|
-
* `const agentPreview = new AgentPreview(connection, botId);`
|
|
13
|
-
*
|
|
14
|
-
* Start an interactive session:
|
|
15
|
-
*
|
|
16
|
-
* `const { sessionId } = await agentPreview.start();`
|
|
17
|
-
*
|
|
18
|
-
* Send a message to the agent using the session ID from the startResponse:
|
|
19
|
-
*
|
|
20
|
-
* `const sendResponse = await agentPreview.send(sessionId, message);`
|
|
21
|
-
*
|
|
22
|
-
* End an interactive session:
|
|
23
|
-
*
|
|
24
|
-
* `await agentPreview.end(sessionId, 'UserRequest');`
|
|
25
|
-
*
|
|
26
|
-
* Enable Apex Debug Mode:
|
|
27
|
-
*
|
|
28
|
-
* `agentPreview.toggleApexDebugMode(true);`
|
|
29
|
-
*/
|
|
30
|
-
export declare class AgentPreview extends AgentPreviewBase {
|
|
31
|
-
protected readonly apiBase: string;
|
|
32
|
-
private readonly botId;
|
|
33
|
-
/**
|
|
34
|
-
* Create an instance of the service.
|
|
35
|
-
*
|
|
36
|
-
* @param connection The connection to use to make requests.
|
|
37
|
-
* @param botId The ID of the agent (`Bot` ID).
|
|
38
|
-
*/
|
|
39
|
-
constructor(connection: Connection, botId: string);
|
|
40
|
-
/**
|
|
41
|
-
* Start an interactive session with the agent.
|
|
42
|
-
*
|
|
43
|
-
* @returns `AgentPreviewStartResponse`, which includes a session ID needed for other actions.
|
|
44
|
-
*/
|
|
45
|
-
start(): Promise<AgentPreviewStartResponse>;
|
|
46
|
-
/**
|
|
47
|
-
* Send a message to the agent using the session ID obtained by calling `start()`.
|
|
48
|
-
*
|
|
49
|
-
* @param sessionId A session ID provided by first calling `agentPreview.start()`.
|
|
50
|
-
* @param message A message to send to the agent.
|
|
51
|
-
* @returns `AgentPreviewSendResponse`
|
|
52
|
-
*/
|
|
53
|
-
send(sessionId: string, message: string): Promise<AgentPreviewSendResponse>;
|
|
54
|
-
/**
|
|
55
|
-
* Ends an interactive session with the agent.
|
|
56
|
-
*
|
|
57
|
-
* @param sessionId A session ID provided by first calling `agentPreview.start()`.
|
|
58
|
-
* @param reason A reason why the interactive session was ended.
|
|
59
|
-
* @returns `AgentPreviewEndResponse`
|
|
60
|
-
*/
|
|
61
|
-
end(sessionId: string, reason: EndReason): Promise<AgentPreviewEndResponse>;
|
|
62
|
-
/**
|
|
63
|
-
* Get the status of the Agent API (UP | DOWN).
|
|
64
|
-
*
|
|
65
|
-
* @returns `ApiStatus`
|
|
66
|
-
*/
|
|
67
|
-
status(): Promise<ApiStatus>;
|
|
68
|
-
/**
|
|
69
|
-
* Get the traces for a given session and message IDs.
|
|
70
|
-
*
|
|
71
|
-
* @param sessionId A session ID provided by first calling `start()`.
|
|
72
|
-
* @param messageIds An array of message IDs to get the traces for.
|
|
73
|
-
* @returns `AgentPreviewEndResponse`
|
|
74
|
-
*/
|
|
75
|
-
traces(sessionId: string, messageIds: string[]): Promise<PlannerResponse[]>;
|
|
76
|
-
private getBotUserId;
|
|
77
|
-
private ensureTraceFlag;
|
|
78
|
-
}
|
package/lib/agentPreview.js
DELETED
|
@@ -1,258 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright 2025, Salesforce, Inc.
|
|
4
|
-
*
|
|
5
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
-
* you may not use this file except in compliance with the License.
|
|
7
|
-
* You may obtain a copy of the License at
|
|
8
|
-
*
|
|
9
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
-
*
|
|
11
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
-
* See the License for the specific language governing permissions and
|
|
15
|
-
* limitations under the License.
|
|
16
|
-
*/
|
|
17
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
-
exports.AgentPreview = void 0;
|
|
19
|
-
const node_crypto_1 = require("node:crypto");
|
|
20
|
-
const core_1 = require("@salesforce/core");
|
|
21
|
-
const kit_1 = require("@salesforce/kit");
|
|
22
|
-
const agent_1 = require("./agent");
|
|
23
|
-
const agentPreviewBase_1 = require("./agentPreviewBase");
|
|
24
|
-
const utils_1 = require("./utils");
|
|
25
|
-
const apexUtils_1 = require("./apexUtils");
|
|
26
|
-
;
|
|
27
|
-
const messages = new core_1.Messages('@salesforce/agents', 'agentPreview', new Map([["invalidBotId", "The Bot ID provided must begin with \"0Xx\" and be either 15 or 18 characters. Found: %s"], ["agentApexDebuggingError", "Agent must have a user assigned to enable apex debug mode."]]));
|
|
28
|
-
/**
|
|
29
|
-
* A service to interact with an agent. Start an interactive session,
|
|
30
|
-
* send messages to the agent, and end the session.
|
|
31
|
-
*
|
|
32
|
-
* **Examples**
|
|
33
|
-
*
|
|
34
|
-
* Create an instance of the service:
|
|
35
|
-
*
|
|
36
|
-
* `const agentPreview = new AgentPreview(connection, botId);`
|
|
37
|
-
*
|
|
38
|
-
* Start an interactive session:
|
|
39
|
-
*
|
|
40
|
-
* `const { sessionId } = await agentPreview.start();`
|
|
41
|
-
*
|
|
42
|
-
* Send a message to the agent using the session ID from the startResponse:
|
|
43
|
-
*
|
|
44
|
-
* `const sendResponse = await agentPreview.send(sessionId, message);`
|
|
45
|
-
*
|
|
46
|
-
* End an interactive session:
|
|
47
|
-
*
|
|
48
|
-
* `await agentPreview.end(sessionId, 'UserRequest');`
|
|
49
|
-
*
|
|
50
|
-
* Enable Apex Debug Mode:
|
|
51
|
-
*
|
|
52
|
-
* `agentPreview.toggleApexDebugMode(true);`
|
|
53
|
-
*/
|
|
54
|
-
class AgentPreview extends agentPreviewBase_1.AgentPreviewBase {
|
|
55
|
-
apiBase = `https://${kit_1.env.getBoolean('SF_TEST_API') ? 'test.' : ''}api.salesforce.com/einstein/ai-agent/v1`;
|
|
56
|
-
botId;
|
|
57
|
-
/**
|
|
58
|
-
* Create an instance of the service.
|
|
59
|
-
*
|
|
60
|
-
* @param connection The connection to use to make requests.
|
|
61
|
-
* @param botId The ID of the agent (`Bot` ID).
|
|
62
|
-
*/
|
|
63
|
-
constructor(connection, botId) {
|
|
64
|
-
super({ connection });
|
|
65
|
-
if (!botId.startsWith('0Xx') || ![15, 18].includes(botId.length)) {
|
|
66
|
-
throw messages.createError('invalidBotId', [botId]);
|
|
67
|
-
}
|
|
68
|
-
this.botId = botId;
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Start an interactive session with the agent.
|
|
72
|
-
*
|
|
73
|
-
* @returns `AgentPreviewStartResponse`, which includes a session ID needed for other actions.
|
|
74
|
-
*/
|
|
75
|
-
async start() {
|
|
76
|
-
const url = `${this.apiBase}/agents/${this.botId}/sessions`;
|
|
77
|
-
this.logger.debug(`Starting agent preview session for botId: ${this.botId}`);
|
|
78
|
-
const body = {
|
|
79
|
-
externalSessionKey: (0, node_crypto_1.randomUUID)(),
|
|
80
|
-
instanceConfig: {
|
|
81
|
-
endpoint: this.connection.instanceUrl,
|
|
82
|
-
},
|
|
83
|
-
streamingCapabilities: {
|
|
84
|
-
chunkTypes: ['Text'],
|
|
85
|
-
},
|
|
86
|
-
bypassUser: true,
|
|
87
|
-
};
|
|
88
|
-
try {
|
|
89
|
-
const response = await this.maybeMock.request('POST', url, body);
|
|
90
|
-
// Persist any initial agent messages (welcome, etc.)
|
|
91
|
-
await (0, utils_1.appendTranscriptEntry)({
|
|
92
|
-
timestamp: new Date().toISOString(),
|
|
93
|
-
agentId: this.botId,
|
|
94
|
-
sessionId: response.sessionId,
|
|
95
|
-
role: 'agent',
|
|
96
|
-
text: response.messages.map((m) => m.message).join('\n'),
|
|
97
|
-
raw: response.messages,
|
|
98
|
-
}, true);
|
|
99
|
-
return response;
|
|
100
|
-
}
|
|
101
|
-
catch (err) {
|
|
102
|
-
throw core_1.SfError.wrap(err);
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Send a message to the agent using the session ID obtained by calling `start()`.
|
|
107
|
-
*
|
|
108
|
-
* @param sessionId A session ID provided by first calling `agentPreview.start()`.
|
|
109
|
-
* @param message A message to send to the agent.
|
|
110
|
-
* @returns `AgentPreviewSendResponse`
|
|
111
|
-
*/
|
|
112
|
-
async send(sessionId, message) {
|
|
113
|
-
const url = `${this.apiBase}/sessions/${sessionId}/messages`;
|
|
114
|
-
const body = {
|
|
115
|
-
message: {
|
|
116
|
-
// https://developer.salesforce.com/docs/einstein/genai/guide/agent-api-examples.html#send-synchronous-messages
|
|
117
|
-
// > A number that you provide to represent the sequence ID. Increase this number for each subsequent message in this session.
|
|
118
|
-
sequenceId: Date.now(),
|
|
119
|
-
type: 'Text',
|
|
120
|
-
text: message,
|
|
121
|
-
},
|
|
122
|
-
variables: [],
|
|
123
|
-
};
|
|
124
|
-
this.logger.debug(`Sending message to botId: ${this.botId} with apexDebugMode ${this.apexDebugMode ? 'enabled' : 'disabled'}`);
|
|
125
|
-
try {
|
|
126
|
-
// If apex debug mode is enabled, ensure we have a trace flag for the bot user and
|
|
127
|
-
// if there isn't one, create one.
|
|
128
|
-
const start = Date.now();
|
|
129
|
-
if (this.apexDebugMode) {
|
|
130
|
-
await this.ensureTraceFlag();
|
|
131
|
-
}
|
|
132
|
-
const response = await this.maybeMock.request('POST', url, body);
|
|
133
|
-
// Save user entry
|
|
134
|
-
await (0, utils_1.appendTranscriptEntry)({
|
|
135
|
-
timestamp: new Date().toISOString(),
|
|
136
|
-
agentId: this.botId,
|
|
137
|
-
sessionId,
|
|
138
|
-
role: 'user',
|
|
139
|
-
text: message,
|
|
140
|
-
});
|
|
141
|
-
// Save agent response entry
|
|
142
|
-
const agentText = (response.messages ?? [])
|
|
143
|
-
.map((m) => m.message)
|
|
144
|
-
.filter(Boolean)
|
|
145
|
-
.join('\n');
|
|
146
|
-
await (0, utils_1.appendTranscriptEntry)({
|
|
147
|
-
timestamp: new Date().toISOString(),
|
|
148
|
-
agentId: this.botId,
|
|
149
|
-
sessionId,
|
|
150
|
-
role: 'agent',
|
|
151
|
-
text: agentText || undefined,
|
|
152
|
-
raw: response.messages,
|
|
153
|
-
});
|
|
154
|
-
if (this.apexDebugMode) {
|
|
155
|
-
// get apex debug logs and look for a log within the start and end time
|
|
156
|
-
const apexLog = await (0, apexUtils_1.getDebugLog)(this.connection, start, Date.now());
|
|
157
|
-
if (apexLog) {
|
|
158
|
-
if (apexLog.Id)
|
|
159
|
-
this.logger.debug(`Apex debug log ID for message is ${apexLog.Id}`);
|
|
160
|
-
response.apexDebugLog = apexLog;
|
|
161
|
-
}
|
|
162
|
-
else {
|
|
163
|
-
this.logger.debug('No apex debug log found for this message');
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
return response;
|
|
167
|
-
}
|
|
168
|
-
catch (err) {
|
|
169
|
-
throw core_1.SfError.wrap(err);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
/**
|
|
173
|
-
* Ends an interactive session with the agent.
|
|
174
|
-
*
|
|
175
|
-
* @param sessionId A session ID provided by first calling `agentPreview.start()`.
|
|
176
|
-
* @param reason A reason why the interactive session was ended.
|
|
177
|
-
* @returns `AgentPreviewEndResponse`
|
|
178
|
-
*/
|
|
179
|
-
async end(sessionId, reason) {
|
|
180
|
-
const url = `${this.apiBase}/sessions/${sessionId}`;
|
|
181
|
-
this.logger.debug(`Ending agent preview session for botId: ${this.botId} with sessionId: ${sessionId}`);
|
|
182
|
-
try {
|
|
183
|
-
// https://developer.salesforce.com/docs/einstein/genai/guide/agent-api-examples.html#end-session
|
|
184
|
-
const response = await this.maybeMock.request('DELETE', url, undefined, {
|
|
185
|
-
'x-session-end-reason': reason,
|
|
186
|
-
});
|
|
187
|
-
await (0, utils_1.appendTranscriptEntry)({
|
|
188
|
-
timestamp: new Date().toISOString(),
|
|
189
|
-
agentId: this.botId,
|
|
190
|
-
sessionId,
|
|
191
|
-
role: 'agent',
|
|
192
|
-
reason,
|
|
193
|
-
raw: response.messages,
|
|
194
|
-
});
|
|
195
|
-
return response;
|
|
196
|
-
}
|
|
197
|
-
catch (err) {
|
|
198
|
-
throw core_1.SfError.wrap(err);
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Get the status of the Agent API (UP | DOWN).
|
|
203
|
-
*
|
|
204
|
-
* @returns `ApiStatus`
|
|
205
|
-
*/
|
|
206
|
-
async status() {
|
|
207
|
-
const url = `https://${kit_1.env.getBoolean('SF_TEST_API') ? 'test.' : ''}api.salesforce.com/einstein/ai-agent/v1/status`;
|
|
208
|
-
try {
|
|
209
|
-
return await this.maybeMock.request('GET', url);
|
|
210
|
-
}
|
|
211
|
-
catch (err) {
|
|
212
|
-
throw core_1.SfError.wrap(err);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Get the traces for a given session and message IDs.
|
|
217
|
-
*
|
|
218
|
-
* @param sessionId A session ID provided by first calling `start()`.
|
|
219
|
-
* @param messageIds An array of message IDs to get the traces for.
|
|
220
|
-
* @returns `AgentPreviewEndResponse`
|
|
221
|
-
*/
|
|
222
|
-
traces(sessionId, messageIds) {
|
|
223
|
-
this.logger.info(`Get traces for published agents is not implemented yet. Session ID: ${sessionId}, Message IDs: ${messageIds.join(', ')}`);
|
|
224
|
-
return Promise.resolve([]);
|
|
225
|
-
}
|
|
226
|
-
async getBotUserId() {
|
|
227
|
-
const agent = new agent_1.Agent({ connection: this.connection, nameOrId: this.botId });
|
|
228
|
-
const botMetadata = await agent.getBotMetadata();
|
|
229
|
-
return botMetadata.BotUserId;
|
|
230
|
-
}
|
|
231
|
-
// If apex debug mode is enabled, ensure we have a trace flag for the bot user
|
|
232
|
-
// that is not expired checking in this order:
|
|
233
|
-
// 1. instance var (this.apexTraceFlag)
|
|
234
|
-
// 2. query the org
|
|
235
|
-
// 3. create a new trace flag
|
|
236
|
-
async ensureTraceFlag() {
|
|
237
|
-
if (this.apexTraceFlag) {
|
|
238
|
-
const expDate = this.apexTraceFlag.ExpirationDate;
|
|
239
|
-
if (expDate && new Date(expDate) > new Date()) {
|
|
240
|
-
this.logger.debug(`Using cached apexTraceFlag with ExpirationDate of ${expDate}`);
|
|
241
|
-
return;
|
|
242
|
-
}
|
|
243
|
-
else {
|
|
244
|
-
this.logger.debug('Cached apex trace flag is expired');
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
const userId = await this.getBotUserId();
|
|
248
|
-
if (!userId) {
|
|
249
|
-
throw messages.createError('agentApexDebuggingError');
|
|
250
|
-
}
|
|
251
|
-
this.apexTraceFlag = await (0, apexUtils_1.findTraceFlag)(this.connection, userId);
|
|
252
|
-
if (!this.apexTraceFlag) {
|
|
253
|
-
await (0, apexUtils_1.createTraceFlag)(this.connection, userId);
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
exports.AgentPreview = AgentPreview;
|
|
258
|
-
//# sourceMappingURL=agentPreview.js.map
|