@salesforce/sfdx-agent-sdk 0.1.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.
Files changed (67) hide show
  1. package/LICENSE.txt +21 -0
  2. package/README.md +508 -0
  3. package/dist/agent-connectivity-resolver.d.ts +62 -0
  4. package/dist/agent-connectivity-resolver.js +47 -0
  5. package/dist/agent-connectivity-resolver.js.map +1 -0
  6. package/dist/agent-manager.d.ts +134 -0
  7. package/dist/agent-manager.js +266 -0
  8. package/dist/agent-manager.js.map +1 -0
  9. package/dist/agent.d.ts +218 -0
  10. package/dist/agent.js +313 -0
  11. package/dist/agent.js.map +1 -0
  12. package/dist/chat-session.d.ts +298 -0
  13. package/dist/chat-session.js +407 -0
  14. package/dist/chat-session.js.map +1 -0
  15. package/dist/errors.d.ts +12 -0
  16. package/dist/errors.js +20 -0
  17. package/dist/errors.js.map +1 -0
  18. package/dist/harness/agent-harness.d.ts +200 -0
  19. package/dist/harness/agent-harness.js +6 -0
  20. package/dist/harness/agent-harness.js.map +1 -0
  21. package/dist/harness/harness-bus-owner.d.ts +34 -0
  22. package/dist/harness/harness-bus-owner.js +78 -0
  23. package/dist/harness/harness-bus-owner.js.map +1 -0
  24. package/dist/harness/harness-config.d.ts +89 -0
  25. package/dist/harness/harness-config.js +26 -0
  26. package/dist/harness/harness-config.js.map +1 -0
  27. package/dist/harness/harness-factory.d.ts +21 -0
  28. package/dist/harness/harness-factory.js +6 -0
  29. package/dist/harness/harness-factory.js.map +1 -0
  30. package/dist/harness/index.d.ts +4 -0
  31. package/dist/harness/index.js +6 -0
  32. package/dist/harness/index.js.map +1 -0
  33. package/dist/index.d.ts +23 -0
  34. package/dist/index.js +20 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/internal/telemetry-router.d.ts +41 -0
  37. package/dist/internal/telemetry-router.js +128 -0
  38. package/dist/internal/telemetry-router.js.map +1 -0
  39. package/dist/mcp-auth.d.ts +20 -0
  40. package/dist/mcp-auth.js +40 -0
  41. package/dist/mcp-auth.js.map +1 -0
  42. package/dist/mcp-config.d.ts +52 -0
  43. package/dist/mcp-config.js +13 -0
  44. package/dist/mcp-config.js.map +1 -0
  45. package/dist/test/tsconfig.tsbuildinfo +1 -0
  46. package/dist/types/events.d.ts +151 -0
  47. package/dist/types/events.js +6 -0
  48. package/dist/types/events.js.map +1 -0
  49. package/dist/types/index.d.ts +4 -0
  50. package/dist/types/index.js +6 -0
  51. package/dist/types/index.js.map +1 -0
  52. package/dist/types/messages.d.ts +60 -0
  53. package/dist/types/messages.js +6 -0
  54. package/dist/types/messages.js.map +1 -0
  55. package/dist/types/telemetry-events.d.ts +93 -0
  56. package/dist/types/telemetry-events.js +6 -0
  57. package/dist/types/telemetry-events.js.map +1 -0
  58. package/dist/types/tools.d.ts +57 -0
  59. package/dist/types/tools.js +6 -0
  60. package/dist/types/tools.js.map +1 -0
  61. package/dist/types/usage.d.ts +31 -0
  62. package/dist/types/usage.js +6 -0
  63. package/dist/types/usage.js.map +1 -0
  64. package/dist/workspace.d.ts +15 -0
  65. package/dist/workspace.js +48 -0
  66. package/dist/workspace.js.map +1 -0
  67. package/package.json +64 -0
@@ -0,0 +1,134 @@
1
+ import { type Clock, LogBus, type LogRecord, type Unsubscribe, type UniqueIDGenerator } from '@salesforce/agentic-common';
2
+ import { type AgentHarness } from './harness/agent-harness.js';
3
+ import type { HarnessFactory } from './harness/harness-factory.js';
4
+ import { type AgentConfig } from './harness/harness-config.js';
5
+ import { type Agent } from './agent.js';
6
+ import type { TelemetryEventCallback } from './types/telemetry-events.js';
7
+ import { type AgentConnectivityResolver } from './agent-connectivity-resolver.js';
8
+ /**
9
+ * Manages the lifecycle of {@link Agent} instances.
10
+ *
11
+ * The manager owns an {@link AgentHarness} and coordinates initialization,
12
+ * agent creation, and graceful shutdown. The harness implementation is
13
+ * abstracted away from downstream code (agents, sessions).
14
+ *
15
+ * ### Persistence Responsibility
16
+ * Persistence is shared between the harness and the consuming application:
17
+ * - **Engine**: Handles physical data persistence (database storage of threads, messages, and memory state).
18
+ * - **Application**: Handles lifecycle persistence. It manages the discovery and restoration of saved agents,
19
+ * and calls `createAgent(projectRoot, { agentId: savedId, ...savedConfig })` to rebuild active agent state in memory
20
+ * (like MCP connections and custom tool closures) while reconnecting to the persistent memory data.
21
+ */
22
+ export declare class AgentManager {
23
+ private readonly harness;
24
+ private readonly agentIdGenerator;
25
+ private readonly agentConnectivityResolver;
26
+ private readonly clock;
27
+ private readonly agents;
28
+ private readonly telemetryBus;
29
+ private readonly logBus;
30
+ private readonly router;
31
+ private readonly unroutedUnsubs;
32
+ private disposed;
33
+ /**
34
+ * Creates a new {@link AgentManager}.
35
+ *
36
+ * This constructor is **exposed for testing only** so unit tests can inject a stubbed
37
+ * {@link AgentHarness} and deterministic ID generator.
38
+ *
39
+ * Production callers should use {@link createAgentManager} instead.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * // Recommended for production usage (constructs the default connectivity resolver):
44
+ * const manager = await createAgentManager(storageRootFolder, harnessFactory);
45
+ * ```
46
+ */
47
+ constructor(harness: AgentHarness, agentConnectivityResolver: AgentConnectivityResolver, agentIdGenerator?: UniqueIDGenerator, clock?: Clock, logBus?: LogBus);
48
+ /**
49
+ * Shuts down the harness and destroys all managed agents.
50
+ *
51
+ * @requirements
52
+ * - MUST iterate through all agents in the internal `agents` map and call `agent.destroy()` on each.
53
+ * - MUST clear the internal `agents` map.
54
+ * - MUST delegate to `this.harness.shutdown()` to release harness-level resources.
55
+ */
56
+ shutdown(): Promise<void>;
57
+ /**
58
+ * Creates a new `Agent` with the given configuration.
59
+ *
60
+ * @param projectRoot - Absolute path to the project folder the agent can manipulate files from.
61
+ * Relative paths are resolved against `process.cwd()`. The path must exist and be a directory.
62
+ * @param config - Agent configuration (instructions, tools, model, etc.).
63
+ * @param options - Optional execution options, including abort signals.
64
+ * @returns A new `Agent` ready for chat sessions.
65
+ *
66
+ * @throws If `projectRoot` does not exist or is not a directory.
67
+ *
68
+ * @requirements
69
+ * - MUST resolve `projectRoot` to an absolute, normalized path before use.
70
+ * - MUST throw an Error if the resolved `projectRoot` does not exist or is not a directory.
71
+ * - MUST throw an Error if `config.agentId` is provided and an agent with that ID already exists in the internal `agents` map.
72
+ * - MUST generate a unique ID via `this.agentIdGenerator` if `config.agentId` is omitted.
73
+ * - MUST delegate to `this.harness.createAgent(agentId, projectRoot, llmGatewayClient, config, options)` to register the agent in the harness and allow for cancellation.
74
+ * - MUST instantiate a `DefaultAgent` with the harness and the complete configuration.
75
+ * - MUST store the newly created agent in the internal `agents` map, keyed by its `agentId`.
76
+ * - MUST return the newly created agent.
77
+ */
78
+ createAgent(projectRoot: string, config?: AgentConfig & {
79
+ agentId?: string;
80
+ }, options?: {
81
+ abortSignal?: AbortSignal;
82
+ }): Promise<Agent>;
83
+ /**
84
+ * Returns the IDs of all currently managed agents.
85
+ *
86
+ * @requirements
87
+ * - MUST return an array of all string keys (agent IDs) currently tracked in the internal `agents` map.
88
+ */
89
+ getAgentIds(): string[];
90
+ /**
91
+ * Retrieves a managed agent by its ID.
92
+ *
93
+ * @param agentId - ID of the agent to retrieve.
94
+ *
95
+ * @requirements
96
+ * - MUST throw an Error if the provided `agentId` is not found in the internal `agents` map.
97
+ * - MUST return the `Agent` instance associated with the given `agentId`.
98
+ */
99
+ getAgent(agentId: string): Agent;
100
+ /**
101
+ * Destroys a managed agent by its ID, releasing all its resources.
102
+ *
103
+ * @param agentId - ID of the agent to destroy.
104
+ *
105
+ * @requirements
106
+ * - MUST throw an Error if the provided `agentId` is not found in the internal `agents` map.
107
+ * - MUST call `destroy()` on the target agent instance.
108
+ * - MUST remove the agent from the internal `agents` map.
109
+ */
110
+ destroyAgent(agentId: string): Promise<void>;
111
+ /** Subscribe to telemetry events across every managed agent. Returns an unsubscribe function. */
112
+ onTelemetry(callback: TelemetryEventCallback): Unsubscribe;
113
+ /** Subscribe to structured log records across every managed agent. Returns an unsubscribe function. */
114
+ onLog(callback: (record: LogRecord) => void): Unsubscribe;
115
+ private assertNotDisposed;
116
+ }
117
+ /**
118
+ * Creates an {@link AgentManager} using the provided harness factory.
119
+ *
120
+ * Use this function in production code. It validates the `storageRootFolder`,
121
+ * verifies the factory advertises a supported protocol version (failing fast
122
+ * before any expensive harness construction), constructs the harness
123
+ * asynchronously, sanity-checks that the constructed harness honors the
124
+ * factory's advertised version, and returns a ready-to-use manager.
125
+ *
126
+ * @param storageRootFolder - Existing directory used for agent persistence.
127
+ * @param harnessFactory - Factory that constructs the harness implementation.
128
+ *
129
+ * @throws {AgentSDKError} `INCOMPATIBLE_HARNESS` when either the factory or
130
+ * the constructed harness reports a `protocolVersion` outside
131
+ * {@link SUPPORTED_PROTOCOL_VERSIONS}, or when the harness's reported
132
+ * version disagrees with the factory's.
133
+ */
134
+ export declare function createAgentManager(storageRootFolder: string, harnessFactory: HarnessFactory): Promise<AgentManager>;
@@ -0,0 +1,266 @@
1
+ /*
2
+ * Copyright 2026, Salesforce, Inc. All rights reserved.
3
+ * See LICENSE.txt for license terms.
4
+ */
5
+ import { EventBus, LogBus, RealClock, UUIDGenerator, } from '@salesforce/agentic-common';
6
+ import { resolve } from 'node:path';
7
+ import { stat } from 'node:fs/promises';
8
+ import { SUPPORTED_PROTOCOL_VERSIONS } from './harness/agent-harness.js';
9
+ import { toHarnessConfig } from './harness/harness-config.js';
10
+ import { DefaultAgent } from './agent.js';
11
+ import { AgentSDKError, AgentSDKErrorType } from './errors.js';
12
+ import { TelemetryRouter } from './internal/telemetry-router.js';
13
+ import { DefaultAgentConnectivityResolver } from './agent-connectivity-resolver.js';
14
+ /**
15
+ * Manages the lifecycle of {@link Agent} instances.
16
+ *
17
+ * The manager owns an {@link AgentHarness} and coordinates initialization,
18
+ * agent creation, and graceful shutdown. The harness implementation is
19
+ * abstracted away from downstream code (agents, sessions).
20
+ *
21
+ * ### Persistence Responsibility
22
+ * Persistence is shared between the harness and the consuming application:
23
+ * - **Engine**: Handles physical data persistence (database storage of threads, messages, and memory state).
24
+ * - **Application**: Handles lifecycle persistence. It manages the discovery and restoration of saved agents,
25
+ * and calls `createAgent(projectRoot, { agentId: savedId, ...savedConfig })` to rebuild active agent state in memory
26
+ * (like MCP connections and custom tool closures) while reconnecting to the persistent memory data.
27
+ */
28
+ export class AgentManager {
29
+ harness;
30
+ agentIdGenerator;
31
+ agentConnectivityResolver;
32
+ clock;
33
+ agents = new Map();
34
+ telemetryBus = new EventBus();
35
+ logBus;
36
+ router;
37
+ unroutedUnsubs;
38
+ disposed = false;
39
+ /**
40
+ * Creates a new {@link AgentManager}.
41
+ *
42
+ * This constructor is **exposed for testing only** so unit tests can inject a stubbed
43
+ * {@link AgentHarness} and deterministic ID generator.
44
+ *
45
+ * Production callers should use {@link createAgentManager} instead.
46
+ *
47
+ * @example
48
+ * ```ts
49
+ * // Recommended for production usage (constructs the default connectivity resolver):
50
+ * const manager = await createAgentManager(storageRootFolder, harnessFactory);
51
+ * ```
52
+ */
53
+ constructor(harness, agentConnectivityResolver, agentIdGenerator = new UUIDGenerator(), clock = new RealClock(), logBus = new LogBus()) {
54
+ this.harness = harness;
55
+ this.agentConnectivityResolver = agentConnectivityResolver;
56
+ this.agentIdGenerator = agentIdGenerator;
57
+ this.clock = clock;
58
+ this.logBus = logBus;
59
+ this.router = new TelemetryRouter(harness);
60
+ this.unroutedUnsubs = [
61
+ this.router.unrouted.telemetry.forwardTo(this.telemetryBus),
62
+ this.router.unrouted.log.forwardTo(this.logBus),
63
+ ];
64
+ }
65
+ // Note: harness construction is async (see createAgentManager), so AgentManager itself no longer has initialize().
66
+ /**
67
+ * Shuts down the harness and destroys all managed agents.
68
+ *
69
+ * @requirements
70
+ * - MUST iterate through all agents in the internal `agents` map and call `agent.destroy()` on each.
71
+ * - MUST clear the internal `agents` map.
72
+ * - MUST delegate to `this.harness.shutdown()` to release harness-level resources.
73
+ */
74
+ async shutdown() {
75
+ if (this.disposed) {
76
+ return;
77
+ }
78
+ for (const [agentId, agent] of this.agents) {
79
+ await agent.destroy();
80
+ this.router.unregisterAgent(agentId);
81
+ }
82
+ this.agents.clear();
83
+ await this.harness.shutdown();
84
+ for (const unsub of this.unroutedUnsubs)
85
+ unsub();
86
+ this.router.dispose();
87
+ this.telemetryBus.dispose();
88
+ this.logBus.dispose();
89
+ this.disposed = true;
90
+ }
91
+ /**
92
+ * Creates a new `Agent` with the given configuration.
93
+ *
94
+ * @param projectRoot - Absolute path to the project folder the agent can manipulate files from.
95
+ * Relative paths are resolved against `process.cwd()`. The path must exist and be a directory.
96
+ * @param config - Agent configuration (instructions, tools, model, etc.).
97
+ * @param options - Optional execution options, including abort signals.
98
+ * @returns A new `Agent` ready for chat sessions.
99
+ *
100
+ * @throws If `projectRoot` does not exist or is not a directory.
101
+ *
102
+ * @requirements
103
+ * - MUST resolve `projectRoot` to an absolute, normalized path before use.
104
+ * - MUST throw an Error if the resolved `projectRoot` does not exist or is not a directory.
105
+ * - MUST throw an Error if `config.agentId` is provided and an agent with that ID already exists in the internal `agents` map.
106
+ * - MUST generate a unique ID via `this.agentIdGenerator` if `config.agentId` is omitted.
107
+ * - MUST delegate to `this.harness.createAgent(agentId, projectRoot, llmGatewayClient, config, options)` to register the agent in the harness and allow for cancellation.
108
+ * - MUST instantiate a `DefaultAgent` with the harness and the complete configuration.
109
+ * - MUST store the newly created agent in the internal `agents` map, keyed by its `agentId`.
110
+ * - MUST return the newly created agent.
111
+ */
112
+ async createAgent(projectRoot, config = {}, options) {
113
+ this.assertNotDisposed();
114
+ const resolvedProjectRoot = resolve(projectRoot);
115
+ let dirStat;
116
+ try {
117
+ dirStat = await stat(resolvedProjectRoot);
118
+ }
119
+ catch {
120
+ throw new Error(`projectRoot does not exist: "${resolvedProjectRoot}"`);
121
+ }
122
+ if (!dirStat.isDirectory()) {
123
+ throw new Error(`projectRoot is not a directory: "${resolvedProjectRoot}"`);
124
+ }
125
+ const { agentId: providedAgentId, ...agentConfig } = config;
126
+ const agentId = providedAgentId ?? this.agentIdGenerator.getUniqueId();
127
+ if (providedAgentId && this.agents.has(providedAgentId)) {
128
+ throw new Error(`Agent with id "${providedAgentId}" already exists`);
129
+ }
130
+ const runtime = await this.agentConnectivityResolver.resolve(resolvedProjectRoot, agentConfig);
131
+ await this.harness.createAgent(agentId, resolvedProjectRoot, runtime.llmGatewayClient, toHarnessConfig(agentConfig, runtime.orgJwt), options);
132
+ const agentSlice = this.router.registerAgent(agentId);
133
+ const agent = new DefaultAgent(this.harness, agentId, resolvedProjectRoot, agentConfig, runtime.llmGatewayClient, runtime.orgConnection, runtime.orgJwt, this.agentConnectivityResolver, this.router, agentSlice, { telemetry: this.telemetryBus, log: this.logBus }, this.clock, this.agentIdGenerator);
134
+ this.agents.set(agentId, agent);
135
+ this.telemetryBus.emit({
136
+ type: 'agent-created',
137
+ timestamp: this.clock.now(),
138
+ agentId,
139
+ projectRoot: resolvedProjectRoot,
140
+ modelName: runtime.llmGatewayClient.getModel().name,
141
+ });
142
+ return agent;
143
+ }
144
+ /**
145
+ * Returns the IDs of all currently managed agents.
146
+ *
147
+ * @requirements
148
+ * - MUST return an array of all string keys (agent IDs) currently tracked in the internal `agents` map.
149
+ */
150
+ getAgentIds() {
151
+ this.assertNotDisposed();
152
+ return Array.from(this.agents.keys());
153
+ }
154
+ /**
155
+ * Retrieves a managed agent by its ID.
156
+ *
157
+ * @param agentId - ID of the agent to retrieve.
158
+ *
159
+ * @requirements
160
+ * - MUST throw an Error if the provided `agentId` is not found in the internal `agents` map.
161
+ * - MUST return the `Agent` instance associated with the given `agentId`.
162
+ */
163
+ getAgent(agentId) {
164
+ this.assertNotDisposed();
165
+ const agent = this.agents.get(agentId);
166
+ if (!agent) {
167
+ throw new AgentSDKError(`No Agent found with id: "${agentId}"`, AgentSDKErrorType.AGENT_NOT_FOUND);
168
+ }
169
+ return agent;
170
+ }
171
+ /**
172
+ * Destroys a managed agent by its ID, releasing all its resources.
173
+ *
174
+ * @param agentId - ID of the agent to destroy.
175
+ *
176
+ * @requirements
177
+ * - MUST throw an Error if the provided `agentId` is not found in the internal `agents` map.
178
+ * - MUST call `destroy()` on the target agent instance.
179
+ * - MUST remove the agent from the internal `agents` map.
180
+ */
181
+ async destroyAgent(agentId) {
182
+ this.assertNotDisposed();
183
+ const agent = this.agents.get(agentId);
184
+ if (!agent) {
185
+ throw new AgentSDKError(`No Agent found with id: "${agentId}"`, AgentSDKErrorType.AGENT_NOT_FOUND);
186
+ }
187
+ await agent.destroy();
188
+ this.router.unregisterAgent(agentId);
189
+ this.agents.delete(agentId);
190
+ }
191
+ /** Subscribe to telemetry events across every managed agent. Returns an unsubscribe function. */
192
+ onTelemetry(callback) {
193
+ this.assertNotDisposed();
194
+ return this.telemetryBus.on(callback);
195
+ }
196
+ /** Subscribe to structured log records across every managed agent. Returns an unsubscribe function. */
197
+ onLog(callback) {
198
+ this.assertNotDisposed();
199
+ return this.logBus.on(callback);
200
+ }
201
+ assertNotDisposed() {
202
+ if (this.disposed) {
203
+ throw new AgentSDKError('AgentManager has been shut down.', AgentSDKErrorType.DISPOSED);
204
+ }
205
+ }
206
+ }
207
+ /**
208
+ * Creates an {@link AgentManager} using the provided harness factory.
209
+ *
210
+ * Use this function in production code. It validates the `storageRootFolder`,
211
+ * verifies the factory advertises a supported protocol version (failing fast
212
+ * before any expensive harness construction), constructs the harness
213
+ * asynchronously, sanity-checks that the constructed harness honors the
214
+ * factory's advertised version, and returns a ready-to-use manager.
215
+ *
216
+ * @param storageRootFolder - Existing directory used for agent persistence.
217
+ * @param harnessFactory - Factory that constructs the harness implementation.
218
+ *
219
+ * @throws {AgentSDKError} `INCOMPATIBLE_HARNESS` when either the factory or
220
+ * the constructed harness reports a `protocolVersion` outside
221
+ * {@link SUPPORTED_PROTOCOL_VERSIONS}, or when the harness's reported
222
+ * version disagrees with the factory's.
223
+ */
224
+ export async function createAgentManager(storageRootFolder, harnessFactory) {
225
+ let stats;
226
+ try {
227
+ stats = await stat(storageRootFolder);
228
+ }
229
+ catch {
230
+ throw new Error(`storageRootFolder does not exist: "${storageRootFolder}"`);
231
+ }
232
+ if (!stats.isDirectory()) {
233
+ throw new Error(`storageRootFolder is not a directory: "${storageRootFolder}"`);
234
+ }
235
+ const factoryVersion = harnessFactory.protocolVersion;
236
+ if (!isSupportedProtocolVersion(factoryVersion)) {
237
+ throw new AgentSDKError(`Harness "${harnessFactory.harnessId}" advertises protocolVersion ${String(factoryVersion)} ` +
238
+ `which is not supported by this SDK (supported: ${SUPPORTED_PROTOCOL_VERSIONS.join(', ')}). ` +
239
+ `Update the SDK or harness package.`, AgentSDKErrorType.INCOMPATIBLE_HARNESS);
240
+ }
241
+ const harness = await harnessFactory.create(storageRootFolder);
242
+ const harnessVersion = harness.protocolVersion;
243
+ const harnessVersionMismatch = !isSupportedProtocolVersion(harnessVersion) || harnessVersion !== factoryVersion;
244
+ if (harnessVersionMismatch) {
245
+ try {
246
+ await harness.shutdown();
247
+ }
248
+ catch (shutdownError) {
249
+ // We have no LogBus at this stage (AgentManager not constructed yet),
250
+ // so surface the swallowed error instead of silently dropping it.
251
+ console.warn('[sfdx-agent-sdk] harness.shutdown() failed during INCOMPATIBLE_HARNESS rejection:', shutdownError);
252
+ }
253
+ throw new AgentSDKError(`Harness "${harness.harnessId}" returned by factory "${harnessFactory.harnessId}" ` +
254
+ `reports protocolVersion ${String(harnessVersion)} which does not match the factory's ` +
255
+ `advertised version ${factoryVersion} (SDK supports: ${SUPPORTED_PROTOCOL_VERSIONS.join(', ')}). ` +
256
+ `Update the SDK or harness package.`, AgentSDKErrorType.INCOMPATIBLE_HARNESS);
257
+ }
258
+ const agentConnectivityResolver = new DefaultAgentConnectivityResolver();
259
+ return new AgentManager(harness, agentConnectivityResolver, new UUIDGenerator());
260
+ }
261
+ function isSupportedProtocolVersion(version) {
262
+ return (typeof version === 'number' &&
263
+ Number.isFinite(version) &&
264
+ SUPPORTED_PROTOCOL_VERSIONS.includes(version));
265
+ }
266
+ //# sourceMappingURL=agent-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ag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AAO,CAAC;QACvB,2BAAiD,CAAC,QAAQ,CAAC,OAAO,CAAC,CACvE,CAAC;AACN,CAAC"}
@@ -0,0 +1,218 @@
1
+ import { type Clock, LogBus, type LogRecord, type OrgConnection, type UniqueIDGenerator, type Unsubscribe } from '@salesforce/agentic-common';
2
+ import type { AgentHarness } from './harness/agent-harness.js';
3
+ import { type AgentConfig } from './harness/harness-config.js';
4
+ import { type ChatSession } from './chat-session.js';
5
+ import type { McpServerInfo } from './mcp-config.js';
6
+ import { type JSONWebToken, type LLMGatewayClient } from '@salesforce/llm-gateway-sdk';
7
+ import type { AgentConnectivityResolver } from './agent-connectivity-resolver.js';
8
+ import type { TelemetryRouter, TelemetrySlice } from './internal/telemetry-router.js';
9
+ import type { TelemetryBus, TelemetryEventCallback } from './types/telemetry-events.js';
10
+ /**
11
+ * Parent bus pair wired at construction time so an agent's events bubble upward into the manager's buses.
12
+ */
13
+ export type AgentParentBuses = {
14
+ telemetry: TelemetryBus;
15
+ log: LogBus;
16
+ };
17
+ /**
18
+ * Represents a configured agent managed by the {@link AgentManager}.
19
+ *
20
+ * Each `Agent` wraps a single agent in the underlying harness. It
21
+ * provides agent-level operations (configuration, MCP, lifecycle) and serves
22
+ * as the factory for {@link ChatSession} instances.
23
+ */
24
+ export interface Agent {
25
+ /** Returns the unique agent identifier. */
26
+ getId(): string;
27
+ /** Returns the project root folder this agent operates within. */
28
+ getProjectRoot(): string;
29
+ /** Returns the authenticated org connection for the org this agent runs under. */
30
+ getOrgConnection(): OrgConnection;
31
+ /** Returns the current agent configuration. */
32
+ getAgentConfig(): AgentConfig;
33
+ /**
34
+ * Returns runtime information about MCP servers attached to this agent,
35
+ * including connection status and discovered tool names. This is a synchronous
36
+ * snapshot — status is updated asynchronously by background discovery promises.
37
+ */
38
+ getMcpServerInfo(): McpServerInfo[];
39
+ /**
40
+ * Update the agent's configuration. The harness applies the changes
41
+ * to the live agent (e.g., new instructions, tools, model).
42
+ *
43
+ * @param config - Partial configuration to merge with the current config.
44
+ * @param options - Optional execution options, including abort signals.
45
+ */
46
+ updateAgentConfig(config?: AgentConfig, options?: {
47
+ abortSignal?: AbortSignal;
48
+ }): Promise<void>;
49
+ /**
50
+ * Create a new chat session (conversation thread) for this agent.
51
+ * @returns A new {@link ChatSession} with a unique thread ID.
52
+ */
53
+ createChatSession(): Promise<ChatSession>;
54
+ /**
55
+ * Destroy a chat session and its message history.
56
+ * @param sessionId - ID of the session to destroy.
57
+ */
58
+ destroyChatSession(sessionId: string): Promise<void>;
59
+ /**
60
+ * Retrieve an existing chat session by its ID.
61
+ * @param sessionId - ID of the session to retrieve.
62
+ * @throws Error if no session with the given ID exists.
63
+ */
64
+ getChatSession(sessionId: string): ChatSession;
65
+ /**
66
+ * List all active session IDs for this agent.
67
+ */
68
+ getChatSessionIds(): string[];
69
+ /**
70
+ * Clone an existing chat session, creating a new session with copied
71
+ * message history.
72
+ *
73
+ * @param sourceSessionId - ID of the session to clone.
74
+ * @returns A new {@link ChatSession} with cloned history.
75
+ */
76
+ cloneChatSession(sourceSessionId: string): Promise<ChatSession>;
77
+ /**
78
+ * Compact a chat session's message history to reduce context window usage.
79
+ * Creates a new session seeded with an LLM-generated summary of the
80
+ * source session's conversation.
81
+ *
82
+ * @param sessionId - ID of the session to compact.
83
+ * @returns A new {@link ChatSession} with the compacted summary.
84
+ */
85
+ compactChatSession(sessionId: string): Promise<ChatSession>;
86
+ /**
87
+ * Destroy this agent and release all resources (MCP connections,
88
+ * workspace, memory, and all sessions).
89
+ */
90
+ destroy(): Promise<void>;
91
+ /** Subscribe to telemetry events scoped to this agent (and its sessions). Returns an unsubscribe function. */
92
+ onTelemetry(callback: TelemetryEventCallback): Unsubscribe;
93
+ /** Subscribe to structured log records scoped to this agent (and its sessions). Returns an unsubscribe function. */
94
+ onLog(callback: (record: LogRecord) => void): Unsubscribe;
95
+ }
96
+ /**
97
+ * Default implementation of {@link Agent} that delegates
98
+ * agent and thread operations to an {@link AgentHarness}.
99
+ */
100
+ export declare class DefaultAgent implements Agent {
101
+ private readonly harness;
102
+ private readonly agentId;
103
+ private readonly projectRoot;
104
+ private config;
105
+ private llmGatewayClient;
106
+ private orgConnection;
107
+ private orgJwt;
108
+ private readonly agentConnectivityResolver;
109
+ private readonly sessions;
110
+ private readonly sessionSliceUnregisters;
111
+ private readonly router;
112
+ private readonly telemetryBus;
113
+ private readonly logBus;
114
+ private readonly inboundUnsubs;
115
+ private readonly parentUnsubs;
116
+ private readonly clock;
117
+ private readonly idGenerator;
118
+ private disposed;
119
+ /**
120
+ * @param harness - The agent harness managing agent and thread lifecycle.
121
+ * @param agentId - Unique identifier for this agent.
122
+ * @param projectRoot - Project folder this agent is allowed to operate within.
123
+ * @param config - Initial agent configuration (instructions, model, tools, etc.).
124
+ * @param llmGatewayClient - Authenticated LLM gateway client for the resolved org.
125
+ * @param orgConnection - Authenticated org connection carrying identity and env inference.
126
+ * @param orgJwt - Self-refreshing JWT for the resolved org (used for MCP auth injection).
127
+ * @param agentConnectivityResolver - Used to re-resolve org connectivity when the org or model changes.
128
+ * @param router - Telemetry router used to obtain session slices when sessions are created.
129
+ * @param inbound - Router slice delivering harness events routed to this agent (non-session-scoped).
130
+ * @param parent - Manager's bus pair; this agent forwards its events upward into them.
131
+ */
132
+ constructor(harness: AgentHarness, agentId: string, projectRoot: string, config: AgentConfig, llmGatewayClient: LLMGatewayClient, orgConnection: OrgConnection, orgJwt: JSONWebToken, agentConnectivityResolver: AgentConnectivityResolver, router: TelemetryRouter, inbound: TelemetrySlice, parent: AgentParentBuses, clock?: Clock, idGenerator?: UniqueIDGenerator);
133
+ /**
134
+ * @requirements
135
+ * - MUST return the agent's ID.
136
+ */
137
+ getId(): string;
138
+ /** Returns the project root folder this agent operates within. */
139
+ getProjectRoot(): string;
140
+ getOrgConnection(): OrgConnection;
141
+ /**
142
+ * @requirements
143
+ * - MUST return a shallow copy of the internal `config` object to prevent external mutation of the agent's state.
144
+ */
145
+ getAgentConfig(): AgentConfig;
146
+ getMcpServerInfo(): McpServerInfo[];
147
+ /**
148
+ * @requirements
149
+ * - MUST merge the provided `config` with the internal `config` object.
150
+ * - MUST guarantee that the `agentId` remains unchanged during the merge.
151
+ * - MUST destroy the existing agent in the harness by delegating to `this.harness.destroyAgent(this.getId())`.
152
+ * - MUST recreate the agent in the harness with the newly merged configuration by delegating to `this.harness.createAgent(...)`.
153
+ * - MUST preserve the previous in-memory config state if recreation fails.
154
+ */
155
+ updateAgentConfig(config?: AgentConfig, options?: {
156
+ abortSignal?: AbortSignal;
157
+ }): Promise<void>;
158
+ /**
159
+ * @requirements
160
+ * - MUST delegate to `this.harness.createThread(this.config.agentId)` to generate a new thread ID.
161
+ * - MUST instantiate a new `DefaultChatSession` initialized with the harness, agent ID, and the new thread ID.
162
+ * - MUST store the newly created session in the internal `sessions` map, keyed by the thread ID.
163
+ * - MUST return the newly created session.
164
+ */
165
+ createChatSession(): Promise<ChatSession>;
166
+ /**
167
+ * @requirements
168
+ * - MUST throw an Error if the provided `sessionId` is not found in the internal `sessions` map.
169
+ * - MUST delegate to `this.harness.destroyThread(this.config.agentId, sessionId)`.
170
+ * - MUST remove the session from the internal `sessions` map.
171
+ */
172
+ destroyChatSession(sessionId: string): Promise<void>;
173
+ /**
174
+ * @requirements
175
+ * - MUST throw an Error if the provided `sessionId` is not found in the internal `sessions` map.
176
+ * - MUST return the session object associated with the given `sessionId`.
177
+ */
178
+ getChatSession(sessionId: string): ChatSession;
179
+ /**
180
+ * @requirements
181
+ * - MUST return an array of all string keys (session IDs) currently tracked in the internal `sessions` map.
182
+ */
183
+ getChatSessionIds(): string[];
184
+ /**
185
+ * @requirements
186
+ * - MUST throw an Error if the provided `sourceSessionId` is not found in the internal `sessions` map.
187
+ * - MUST delegate to `this.harness.cloneThread(this.config.agentId, sourceSessionId)` to create a new thread with cloned history.
188
+ * - MUST instantiate a new `DefaultChatSession` initialized with the harness, agent ID, and the new thread ID.
189
+ * - MUST store the newly created session in the internal `sessions` map, keyed by the new thread ID.
190
+ * - MUST return the newly created session.
191
+ */
192
+ cloneChatSession(sourceSessionId: string): Promise<ChatSession>;
193
+ /**
194
+ * @requirements
195
+ * - MUST throw an Error if the provided `sessionId` is not found in the internal `sessions` map.
196
+ * - MUST delegate to `this.harness.compactThread(this.agentId, sessionId)` to create a new thread with a summary.
197
+ * - MUST detach the source session from this agent on success — the
198
+ * harness destroys the source thread, so leaving the wrapper attached
199
+ * would leak a router slice and a `DefaultChatSession` whose thread
200
+ * no longer exists.
201
+ * - MUST instantiate a new `DefaultChatSession` initialized with the harness, agent ID, and the new thread ID.
202
+ * - MUST store the newly created session in the internal `sessions` map, keyed by the new thread ID.
203
+ * - MUST return the newly created session.
204
+ */
205
+ compactChatSession(sessionId: string): Promise<ChatSession>;
206
+ /**
207
+ * @requirements
208
+ * - MUST iterate over all active session IDs and sequentially delegate to `this.harness.destroyThread()` for each.
209
+ * - MUST clear the internal `sessions` map.
210
+ * - MUST delegate to `this.harness.destroyAgent(this.config.agentId)` to clean up the agent's harness resources.
211
+ */
212
+ destroy(): Promise<void>;
213
+ onTelemetry(callback: TelemetryEventCallback): Unsubscribe;
214
+ onLog(callback: (record: LogRecord) => void): Unsubscribe;
215
+ private attachSession;
216
+ private detachSession;
217
+ private assertNotDisposed;
218
+ }