@salesforce/sfdx-agent-harness-openai 0.3.0 → 0.5.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/CHANGELOG.md +13 -0
- package/README.md +14 -4
- package/dist/openai-agents-harness.d.ts +1 -0
- package/dist/openai-agents-harness.js +27 -5
- package/dist/openai-agents-harness.js.map +1 -1
- package/dist/openai-approval-coordinator.d.ts +22 -0
- package/dist/openai-approval-coordinator.js +31 -1
- package/dist/openai-approval-coordinator.js.map +1 -1
- package/dist/openai-event-adapter.d.ts +17 -2
- package/dist/openai-event-adapter.js +60 -4
- package/dist/openai-event-adapter.js.map +1 -1
- package/dist/openai-mcp-client-facade.d.ts +53 -0
- package/dist/openai-mcp-client-facade.js +169 -0
- package/dist/openai-mcp-client-facade.js.map +1 -0
- package/dist/openai-mcp-config-mapper.d.ts +28 -0
- package/dist/openai-mcp-config-mapper.js +5 -4
- package/dist/openai-mcp-config-mapper.js.map +1 -1
- package/dist/openai-model-provider.d.ts +22 -1
- package/dist/openai-model-provider.js +162 -14
- package/dist/openai-model-provider.js.map +1 -1
- package/dist/openai-tool-redaction.d.ts +17 -0
- package/dist/openai-tool-redaction.js +60 -19
- package/dist/openai-tool-redaction.js.map +1 -1
- package/dist/test/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -3
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Copyright 2026, Salesforce, Inc. All rights reserved.
|
|
3
3
|
* See LICENSE.txt for license terms.
|
|
4
4
|
*/
|
|
5
|
+
import { AgentSDKError, AgentSDKErrorType } from '@salesforce/sfdx-agent-sdk';
|
|
5
6
|
/**
|
|
6
7
|
* Per-stream stateful mapper from `@openai/agents` `RunStreamEvent`s to the
|
|
7
8
|
* SDK's `ChatEvent` variants. A new instance is constructed per `stream()` call
|
|
@@ -23,6 +24,7 @@
|
|
|
23
24
|
*/
|
|
24
25
|
export class OpenAIEventAdapter {
|
|
25
26
|
mcpCatalog;
|
|
27
|
+
wireCommunication;
|
|
26
28
|
stepIndex = 0;
|
|
27
29
|
started = false;
|
|
28
30
|
lastStepUsage;
|
|
@@ -40,6 +42,7 @@ export class OpenAIEventAdapter {
|
|
|
40
42
|
deferredStepFinish;
|
|
41
43
|
/** Outstanding `tool_output`s for the deferred step; `step-finish` flushes at 0. */
|
|
42
44
|
pendingToolOutputs = 0;
|
|
45
|
+
pendingMcpToolCalls = new Map();
|
|
43
46
|
/**
|
|
44
47
|
* Optional MCP tool catalog (bare tool name → `{ serverName, annotations }`),
|
|
45
48
|
* used to enrich `tool-call` / `tool-result` events for MCP-sourced tools
|
|
@@ -47,8 +50,9 @@ export class OpenAIEventAdapter {
|
|
|
47
50
|
* discovery settle enriches later events. `undefined` (or a miss) leaves the
|
|
48
51
|
* fields unset — the contract for consumer / built-in tools.
|
|
49
52
|
*/
|
|
50
|
-
constructor(mcpCatalog) {
|
|
53
|
+
constructor(mcpCatalog, wireCommunication) {
|
|
51
54
|
this.mcpCatalog = mcpCatalog;
|
|
55
|
+
this.wireCommunication = wireCommunication;
|
|
52
56
|
}
|
|
53
57
|
/**
|
|
54
58
|
* Map one `RunStreamEvent` to zero or more `ChatEvent`s. Emits a synthetic
|
|
@@ -93,13 +97,16 @@ export class OpenAIEventAdapter {
|
|
|
93
97
|
const toolCallId = item.callId ?? raw.callId;
|
|
94
98
|
if (toolName === undefined || toolCallId === undefined)
|
|
95
99
|
return;
|
|
100
|
+
const args = parseArgs(raw.arguments);
|
|
101
|
+
const enrichment = this.enrich(toolName);
|
|
96
102
|
out.push({
|
|
97
103
|
type: 'tool-call',
|
|
98
104
|
toolCallId,
|
|
99
105
|
toolName,
|
|
100
|
-
args
|
|
101
|
-
...
|
|
106
|
+
args,
|
|
107
|
+
...enrichment,
|
|
102
108
|
});
|
|
109
|
+
this.recordMcpToolCall(toolCallId, toolName, args, enrichment);
|
|
103
110
|
}
|
|
104
111
|
else if (event.name === 'tool_output') {
|
|
105
112
|
const item = event.item;
|
|
@@ -108,13 +115,15 @@ export class OpenAIEventAdapter {
|
|
|
108
115
|
const toolName = raw.name;
|
|
109
116
|
if (toolName === undefined || toolCallId === undefined)
|
|
110
117
|
return;
|
|
118
|
+
const result = normalizeOutput(item.output ?? raw.output);
|
|
111
119
|
out.push({
|
|
112
120
|
type: 'tool-result',
|
|
113
121
|
toolCallId,
|
|
114
122
|
toolName,
|
|
115
|
-
result
|
|
123
|
+
result,
|
|
116
124
|
...this.enrich(toolName),
|
|
117
125
|
});
|
|
126
|
+
this.emitMcpToolCallCompleted(toolCallId, result);
|
|
118
127
|
// The tool-result is now emitted INSIDE its step. Once every tool
|
|
119
128
|
// output of the deferred step has drained, flush the held
|
|
120
129
|
// `step-finish` so it closes the step after its results.
|
|
@@ -156,6 +165,52 @@ export class OpenAIEventAdapter {
|
|
|
156
165
|
lastUsage() {
|
|
157
166
|
return this.lastStepUsage;
|
|
158
167
|
}
|
|
168
|
+
clearPendingMcpToolCalls() {
|
|
169
|
+
this.pendingMcpToolCalls.clear();
|
|
170
|
+
}
|
|
171
|
+
recordMcpToolCall(toolCallId, toolName, args, enrichment) {
|
|
172
|
+
if (enrichment.serverName === undefined || enrichment.bareToolName === undefined)
|
|
173
|
+
return;
|
|
174
|
+
if (this.wireCommunication?.hasSubscribers() !== true)
|
|
175
|
+
return;
|
|
176
|
+
this.pendingMcpToolCalls.set(toolCallId, {
|
|
177
|
+
serverName: enrichment.serverName,
|
|
178
|
+
toolName,
|
|
179
|
+
bareToolName: enrichment.bareToolName,
|
|
180
|
+
args,
|
|
181
|
+
startedAt: this.wireCommunication.clock.now(),
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Emits adapter-observed call-to-output latency, not MCP RPC latency. The
|
|
186
|
+
* OpenAI run-item window can include approval parking, scheduling, and resume.
|
|
187
|
+
*/
|
|
188
|
+
emitMcpToolCallCompleted(toolCallId, result) {
|
|
189
|
+
const pending = this.pendingMcpToolCalls.get(toolCallId);
|
|
190
|
+
if (pending === undefined)
|
|
191
|
+
return;
|
|
192
|
+
this.pendingMcpToolCalls.delete(toolCallId);
|
|
193
|
+
if (this.wireCommunication?.hasSubscribers() !== true)
|
|
194
|
+
return;
|
|
195
|
+
const completedAt = this.wireCommunication.clock.now();
|
|
196
|
+
try {
|
|
197
|
+
this.wireCommunication.emit({
|
|
198
|
+
type: 'mcp-tool-call-completed',
|
|
199
|
+
timestamp: completedAt,
|
|
200
|
+
serverName: pending.serverName,
|
|
201
|
+
toolName: pending.toolName,
|
|
202
|
+
bareToolName: pending.bareToolName,
|
|
203
|
+
args: pending.args,
|
|
204
|
+
result,
|
|
205
|
+
durationMs: completedAt.getTime() - pending.startedAt.getTime(),
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
catch (error) {
|
|
209
|
+
if (error instanceof AgentSDKError && error.type === AgentSDKErrorType.DISPOSED)
|
|
210
|
+
return;
|
|
211
|
+
throw error;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
159
214
|
/**
|
|
160
215
|
* Emit a synthetic `start` if the stream produced no events at all (e.g. a
|
|
161
216
|
* turn that failed before the first delta). Called by the pump on the error
|
|
@@ -231,6 +286,7 @@ export class OpenAIEventAdapter {
|
|
|
231
286
|
drainDeferredStepFinish() {
|
|
232
287
|
const out = [];
|
|
233
288
|
this.flushDeferredStepFinish(out);
|
|
289
|
+
this.clearPendingMcpToolCalls();
|
|
234
290
|
return out;
|
|
235
291
|
}
|
|
236
292
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-event-adapter.js","sourceRoot":"","sources":["../src/openai-event-adapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;
|
|
1
|
+
{"version":3,"file":"openai-event-adapter.js","sourceRoot":"","sources":["../src/openai-event-adapter.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAW9E;;;;;;;;;;;;;;;;;;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,CAAC;QAAE,OAAO,CAAC,CAAC;IACrC,OAAO,MAAM,CAAC,MAAM,CAChB,CAAC,IAAI,EAA4B,EAAE,CAC/B,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,KAAK,IAAI,IAAK,IAA2B,CAAC,IAAI,KAAK,eAAe,CACzG,CAAC,MAAM,CAAC;AACb,CAAC;AAED,kFAAkF;AAClF,SAAS,SAAS,CAAC,GAAY;IAC3B,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,EAAE,CAAC;IACvC,IAAI,CAAC;QACD,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAY,CAAC;QAC1C,OAAO,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,CAAC,CAAC,CAAE,MAAkC,CAAC,CAAC,CAAC,EAAE,CAAC;IACpG,CAAC;IAAC,MAAM,CAAC;QACL,OAAO,EAAE,CAAC;IACd,CAAC;AACL,CAAC;AAED;;;;;GAKG;AACH,SAAS,eAAe,CAAC,MAAe;IACpC,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC;IAC9C,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,IAAK,MAA6B,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;QAClG,OAAQ,MAA6B,CAAC,IAAI,IAAI,EAAE,CAAC;IACrD,CAAC;IACD,OAAO,MAAM,CAAC;AAClB,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
2
|
+
import type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
3
|
+
import type { CallToolResult, Progress } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
+
import type { JSONWebToken } from '@salesforce/agentic-common';
|
|
5
|
+
import type { MCPServer } from '@openai/agents';
|
|
6
|
+
import type { MCPServerConfig } from '@salesforce/sfdx-agent-sdk';
|
|
7
|
+
export type McpClient = {
|
|
8
|
+
readonly client: Client;
|
|
9
|
+
readonly transport: Transport;
|
|
10
|
+
};
|
|
11
|
+
export type CallToolOptions = {
|
|
12
|
+
readonly onprogress?: (progress: Progress) => void;
|
|
13
|
+
readonly signal?: AbortSignal;
|
|
14
|
+
readonly timeout?: number;
|
|
15
|
+
};
|
|
16
|
+
export type ProgressCapableMcpServerOptions = {
|
|
17
|
+
readonly name: string;
|
|
18
|
+
readonly client: Client;
|
|
19
|
+
readonly transport: Transport;
|
|
20
|
+
readonly config: MCPServerConfig;
|
|
21
|
+
};
|
|
22
|
+
/** Builds an MCP SDK client and transport without starting the protocol handshake. */
|
|
23
|
+
export declare function buildMcpClient(config: MCPServerConfig, orgJwt?: JSONWebToken, innerFetch?: typeof fetch): McpClient;
|
|
24
|
+
/** Mirrors the OpenAI Agents SDK input parse before a materialized MCP invocation. */
|
|
25
|
+
export declare function parseToolInput(raw: unknown): Record<string, unknown>;
|
|
26
|
+
/**
|
|
27
|
+
* Mirrors @openai/agents' content-only MCP output mode. Structured content is
|
|
28
|
+
* deliberately excluded so this facade remains byte-identical to its default.
|
|
29
|
+
*/
|
|
30
|
+
export declare function normalizeCallToolResultToModelOutput(result: CallToolResult): string;
|
|
31
|
+
/**
|
|
32
|
+
* Host-owned MCPServer that exposes the MCP SDK's progress and cancellation
|
|
33
|
+
* request options while retaining the OpenAI Agents MCPServer contract.
|
|
34
|
+
*/
|
|
35
|
+
export declare class ProgressCapableMcpServer implements MCPServer {
|
|
36
|
+
#private;
|
|
37
|
+
private readonly options;
|
|
38
|
+
readonly name: string;
|
|
39
|
+
cacheToolsList: boolean;
|
|
40
|
+
toolFilter: MCPServer['toolFilter'];
|
|
41
|
+
toolMetaResolver: MCPServer['toolMetaResolver'];
|
|
42
|
+
customDataExtractor: MCPServer['customDataExtractor'];
|
|
43
|
+
useStructuredContent: boolean;
|
|
44
|
+
errorFunction: MCPServer['errorFunction'];
|
|
45
|
+
constructor(options: ProgressCapableMcpServerOptions);
|
|
46
|
+
connect(): Promise<void>;
|
|
47
|
+
close(): Promise<void>;
|
|
48
|
+
listTools(): ReturnType<MCPServer['listTools']>;
|
|
49
|
+
invalidateToolsCache(): Promise<void>;
|
|
50
|
+
callTool(toolName: string, args: Record<string, unknown> | undefined, options: CallToolOptions): Promise<string>;
|
|
51
|
+
callTool(toolName: string, args: Record<string, unknown> | null, meta?: Record<string, unknown> | null): ReturnType<MCPServer['callTool']>;
|
|
52
|
+
callToolResult(toolName: string, args: Record<string, unknown> | null, _meta?: Record<string, unknown> | null): Promise<CallToolResult>;
|
|
53
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2026, Salesforce, Inc. All rights reserved.
|
|
3
|
+
* See LICENSE.txt for license terms.
|
|
4
|
+
*/
|
|
5
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
6
|
+
import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
|
|
7
|
+
import { StreamableHTTPClientTransport } from '@modelcontextprotocol/sdk/client/streamableHttp.js';
|
|
8
|
+
import { createAuthFetch, DEFAULT_RECONNECTION_OPTIONS } from './openai-mcp-config-mapper.js';
|
|
9
|
+
const CLIENT_INFO = { name: '@salesforce/sfdx-agent-harness-openai', version: '1.0.0' };
|
|
10
|
+
/** Builds an MCP SDK client and transport without starting the protocol handshake. */
|
|
11
|
+
export function buildMcpClient(config, orgJwt, innerFetch = globalThis.fetch) {
|
|
12
|
+
const transport = config.type === 'stdio' ? buildStdioTransport(config) : buildRemoteTransport(config, orgJwt, innerFetch);
|
|
13
|
+
return { client: new Client(CLIENT_INFO), transport };
|
|
14
|
+
}
|
|
15
|
+
function buildStdioTransport(config) {
|
|
16
|
+
return new StdioClientTransport({
|
|
17
|
+
command: config.command,
|
|
18
|
+
...(config.args !== undefined ? { args: config.args } : {}),
|
|
19
|
+
...(config.env !== undefined ? { env: config.env } : {}),
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
function buildRemoteTransport(config, orgJwt, innerFetch) {
|
|
23
|
+
const url = config.url instanceof URL ? config.url : new URL(config.url);
|
|
24
|
+
return new StreamableHTTPClientTransport(url, {
|
|
25
|
+
...(config.headers !== undefined ? { requestInit: { headers: config.headers } } : {}),
|
|
26
|
+
...(orgJwt !== undefined ? { fetch: createAuthFetch(config.url, orgJwt, innerFetch, config.headers) } : {}),
|
|
27
|
+
...(config.reconnectionOptions !== undefined
|
|
28
|
+
? { reconnectionOptions: { ...DEFAULT_RECONNECTION_OPTIONS, ...config.reconnectionOptions } }
|
|
29
|
+
: {}),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/** Mirrors the OpenAI Agents SDK input parse before a materialized MCP invocation. */
|
|
33
|
+
export function parseToolInput(raw) {
|
|
34
|
+
if (typeof raw === 'string' && raw) {
|
|
35
|
+
return JSON.parse(raw);
|
|
36
|
+
}
|
|
37
|
+
if (typeof raw === 'object' && raw !== null && !Array.isArray(raw)) {
|
|
38
|
+
return raw;
|
|
39
|
+
}
|
|
40
|
+
return {};
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Mirrors @openai/agents' content-only MCP output mode. Structured content is
|
|
44
|
+
* deliberately excluded so this facade remains byte-identical to its default.
|
|
45
|
+
*/
|
|
46
|
+
export function normalizeCallToolResultToModelOutput(result) {
|
|
47
|
+
const output = result.content.length === 1 ? result.content[0] : result.content;
|
|
48
|
+
return typeof output === 'object' && !Array.isArray(output) && output.type === 'text'
|
|
49
|
+
? output.text
|
|
50
|
+
: JSON.stringify(output);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Host-owned MCPServer that exposes the MCP SDK's progress and cancellation
|
|
54
|
+
* request options while retaining the OpenAI Agents MCPServer contract.
|
|
55
|
+
*/
|
|
56
|
+
export class ProgressCapableMcpServer {
|
|
57
|
+
options;
|
|
58
|
+
name;
|
|
59
|
+
cacheToolsList = true;
|
|
60
|
+
toolFilter;
|
|
61
|
+
toolMetaResolver;
|
|
62
|
+
customDataExtractor;
|
|
63
|
+
useStructuredContent = false;
|
|
64
|
+
errorFunction;
|
|
65
|
+
#connected = false;
|
|
66
|
+
#closed = false;
|
|
67
|
+
#inFlight = 0;
|
|
68
|
+
#cachedTools;
|
|
69
|
+
#drained = Promise.resolve();
|
|
70
|
+
#resolveDrained;
|
|
71
|
+
constructor(options) {
|
|
72
|
+
this.options = options;
|
|
73
|
+
this.name = options.name;
|
|
74
|
+
}
|
|
75
|
+
async connect() {
|
|
76
|
+
if (!this.#connected) {
|
|
77
|
+
await this.options.client.connect(this.options.transport);
|
|
78
|
+
this.#connected = true;
|
|
79
|
+
this.#closed = false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
async close() {
|
|
83
|
+
if (this.#closed)
|
|
84
|
+
return;
|
|
85
|
+
if (this.#inFlight > 0)
|
|
86
|
+
await this.#drained;
|
|
87
|
+
try {
|
|
88
|
+
await this.options.client.close();
|
|
89
|
+
}
|
|
90
|
+
catch {
|
|
91
|
+
// Client teardown is best-effort: transports may already be closed.
|
|
92
|
+
}
|
|
93
|
+
this.#connected = false;
|
|
94
|
+
this.#closed = true;
|
|
95
|
+
}
|
|
96
|
+
async listTools() {
|
|
97
|
+
if (this.cacheToolsList && this.#cachedTools !== undefined)
|
|
98
|
+
return this.#cachedTools;
|
|
99
|
+
const tools = (await this.options.client.listTools()).tools.map(toOpenAIMcpTool);
|
|
100
|
+
if (this.cacheToolsList)
|
|
101
|
+
this.#cachedTools = tools;
|
|
102
|
+
return tools;
|
|
103
|
+
}
|
|
104
|
+
async invalidateToolsCache() {
|
|
105
|
+
this.#cachedTools = undefined;
|
|
106
|
+
}
|
|
107
|
+
async callTool(toolName, args, optionsOrMeta) {
|
|
108
|
+
const options = isCallToolOptions(optionsOrMeta) ? optionsOrMeta : undefined;
|
|
109
|
+
const result = await this.#callToolResult(toolName, args, options);
|
|
110
|
+
return options === undefined ? result.content : normalizeCallToolResultToModelOutput(result);
|
|
111
|
+
}
|
|
112
|
+
async callToolResult(toolName, args, _meta) {
|
|
113
|
+
return this.#callToolResult(toolName, args, undefined);
|
|
114
|
+
}
|
|
115
|
+
async #callToolResult(toolName, args, options) {
|
|
116
|
+
this.#beginCall();
|
|
117
|
+
try {
|
|
118
|
+
const timeout = options?.timeout ?? this.options.config.timeout;
|
|
119
|
+
const result = await this.options.client.callTool({ name: toolName, arguments: args ?? {} }, undefined, {
|
|
120
|
+
...(options?.signal !== undefined ? { signal: options.signal } : {}),
|
|
121
|
+
...(options?.onprogress !== undefined
|
|
122
|
+
? { onprogress: options.onprogress, resetTimeoutOnProgress: true }
|
|
123
|
+
: {}),
|
|
124
|
+
...(timeout !== undefined ? { timeout } : {}),
|
|
125
|
+
});
|
|
126
|
+
if (!hasContent(result)) {
|
|
127
|
+
throw new Error('MCP task responses are not supported by the OpenAI MCP facade.');
|
|
128
|
+
}
|
|
129
|
+
return result;
|
|
130
|
+
}
|
|
131
|
+
finally {
|
|
132
|
+
this.#endCall();
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
#beginCall() {
|
|
136
|
+
if (this.#inFlight === 0) {
|
|
137
|
+
this.#drained = new Promise((resolve) => {
|
|
138
|
+
this.#resolveDrained = resolve;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
this.#inFlight += 1;
|
|
142
|
+
}
|
|
143
|
+
#endCall() {
|
|
144
|
+
this.#inFlight -= 1;
|
|
145
|
+
if (this.#inFlight === 0) {
|
|
146
|
+
this.#resolveDrained?.();
|
|
147
|
+
this.#resolveDrained = undefined;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
function hasContent(result) {
|
|
152
|
+
return 'content' in result;
|
|
153
|
+
}
|
|
154
|
+
function toOpenAIMcpTool(tool) {
|
|
155
|
+
return {
|
|
156
|
+
name: tool.name,
|
|
157
|
+
...(tool.description !== undefined ? { description: tool.description } : {}),
|
|
158
|
+
inputSchema: {
|
|
159
|
+
type: 'object',
|
|
160
|
+
properties: tool.inputSchema.properties ?? {},
|
|
161
|
+
required: tool.inputSchema.required ?? [],
|
|
162
|
+
additionalProperties: tool.inputSchema['additionalProperties'] === true,
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function isCallToolOptions(value) {
|
|
167
|
+
return value !== null && value !== undefined && ('onprogress' in value || 'signal' in value || 'timeout' in value);
|
|
168
|
+
}
|
|
169
|
+
//# sourceMappingURL=openai-mcp-client-facade.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai-mcp-client-facade.js","sourceRoot":"","sources":["../src/openai-mcp-client-facade.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AAMnG,OAAO,EAAE,eAAe,EAAE,4BAA4B,EAAE,MAAM,+BAA+B,CAAC;AAE9F,MAAM,WAAW,GAAG,EAAE,IAAI,EAAE,uCAAuC,EAAE,OAAO,EAAE,OAAO,EAAW,CAAC;AAkBjG,sFAAsF;AACtF,MAAM,UAAU,cAAc,CAC1B,MAAuB,EACvB,MAAqB,EACrB,aAA2B,UAAU,CAAC,KAAK;IAE3C,MAAM,SAAS,GACX,MAAM,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,mBAAmB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,CAAC,CAAC;IAC7G,OAAO,EAAE,MAAM,EAAE,IAAI,MAAM,CAAC,WAAW,CAAC,EAAE,SAAS,EAAE,CAAC;AAC1D,CAAC;AAED,SAAS,mBAAmB,CAAC,MAA4D;IACrF,OAAO,IAAI,oBAAoB,CAAC;QAC5B,OAAO,EAAE,MAAM,C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AAC,sBAAsB,CAAC,KAAK,IAAI;SAC1E;KACJ,CAAC;AACN,CAAC;AAED,SAAS,iBAAiB,CACtB,KAAmE;IAEnE,OAAO,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,IAAI,CAAC,YAAY,IAAI,KAAK,IAAI,QAAQ,IAAI,KAAK,IAAI,SAAS,IAAI,KAAK,CAAC,CAAC;AACvH,CAAC"}
|
|
@@ -9,6 +9,26 @@ import { MCPServerStdio, MCPServerStreamableHttp, type MCPServer } from '@openai
|
|
|
9
9
|
*/
|
|
10
10
|
type MCPServerStdioOptions = ConstructorParameters<typeof MCPServerStdio>[0];
|
|
11
11
|
type MCPServerStreamableHttpOptions = ConstructorParameters<typeof MCPServerStreamableHttp>[0];
|
|
12
|
+
/**
|
|
13
|
+
* MCP SDK's built-in `StreamableHTTPReconnectionOptions` defaults. This is a
|
|
14
|
+
* byte-identical copy of the Mastra harness's `DEFAULT_RECONNECTION_OPTIONS`
|
|
15
|
+
* (`mcp-config-mapper.ts`) and the Claude harness's copy
|
|
16
|
+
* (`mcp-client-factory.ts`) — cross-harness imports are lint-blocked
|
|
17
|
+
* (`harnessIsolationPack`), so the constant is duplicated on purpose and the
|
|
18
|
+
* shared `@salesforce/harness-conformance` `RECONNECTION_DEFAULTS` table is the
|
|
19
|
+
* drift-guard that keeps the three in lockstep.
|
|
20
|
+
*
|
|
21
|
+
* The field-wise merge below (`{ ...DEFAULT_RECONNECTION_OPTIONS, ...input }`)
|
|
22
|
+
* is required because the underlying transport replaces the entire defaults
|
|
23
|
+
* object when `reconnectionOptions` is set — a partial override would otherwise
|
|
24
|
+
* zero out the unspecified fields.
|
|
25
|
+
*/
|
|
26
|
+
export declare const DEFAULT_RECONNECTION_OPTIONS: {
|
|
27
|
+
readonly maxRetries: 2;
|
|
28
|
+
readonly initialReconnectionDelay: 1000;
|
|
29
|
+
readonly maxReconnectionDelay: 30000;
|
|
30
|
+
readonly reconnectionDelayGrowFactor: 1.5;
|
|
31
|
+
};
|
|
12
32
|
/**
|
|
13
33
|
* Returns `true` if `config` contains at least one server that is not explicitly
|
|
14
34
|
* disabled. A server is enabled when its `enabled` property is `true` or absent.
|
|
@@ -55,4 +75,12 @@ export declare function toOpenAIMcpServerOptions(name: string, config: MCPServer
|
|
|
55
75
|
* `close()` lifecycle.
|
|
56
76
|
*/
|
|
57
77
|
export declare function mapToOpenAIMcpServers(config: MCPConfiguration, orgJwt?: JSONWebToken, innerFetch?: typeof fetch): Map<string, MCPServer>;
|
|
78
|
+
/**
|
|
79
|
+
* Build a `fetch` that resolves fresh MCP auth headers per request. Copied from
|
|
80
|
+
* the Mastra harness's `createAuthFetch` — {@link resolveMcpServerHeaders}
|
|
81
|
+
* injects the rotating JWT only for Salesforce Platform MCP URLs and passes
|
|
82
|
+
* every other URL through unchanged, so this is safe to wire on any remote
|
|
83
|
+
* server whenever an `orgJwt` is available.
|
|
84
|
+
*/
|
|
85
|
+
export declare function createAuthFetch(serverUrl: string | URL, orgJwt: JSONWebToken, innerFetch: typeof fetch, existingHeaders?: Record<string, string>): typeof fetch;
|
|
58
86
|
export {};
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
import { resolveMcpServerHeaders } from '@salesforce/sfdx-agent-sdk';
|
|
6
6
|
import { MCPServerStdio, MCPServerStreamableHttp } from '@openai/agents';
|
|
7
|
+
import { buildMcpClient, ProgressCapableMcpServer } from './openai-mcp-client-facade.js';
|
|
7
8
|
/**
|
|
8
9
|
* MCP SDK's built-in `StreamableHTTPReconnectionOptions` defaults. This is a
|
|
9
10
|
* byte-identical copy of the Mastra harness's `DEFAULT_RECONNECTION_OPTIONS`
|
|
@@ -18,7 +19,7 @@ import { MCPServerStdio, MCPServerStreamableHttp } from '@openai/agents';
|
|
|
18
19
|
* object when `reconnectionOptions` is set — a partial override would otherwise
|
|
19
20
|
* zero out the unspecified fields.
|
|
20
21
|
*/
|
|
21
|
-
const DEFAULT_RECONNECTION_OPTIONS = {
|
|
22
|
+
export const DEFAULT_RECONNECTION_OPTIONS = {
|
|
22
23
|
maxRetries: 2,
|
|
23
24
|
initialReconnectionDelay: 1000,
|
|
24
25
|
maxReconnectionDelay: 30000,
|
|
@@ -107,8 +108,8 @@ export function mapToOpenAIMcpServers(config, orgJwt, innerFetch = fetch) {
|
|
|
107
108
|
for (const [name, serverConfig] of Object.entries(config)) {
|
|
108
109
|
if (serverConfig.enabled === false)
|
|
109
110
|
continue;
|
|
110
|
-
const
|
|
111
|
-
const server =
|
|
111
|
+
const built = buildMcpClient(serverConfig, orgJwt, innerFetch);
|
|
112
|
+
const server = new ProgressCapableMcpServer({ name, ...built, config: serverConfig });
|
|
112
113
|
servers.set(name, server);
|
|
113
114
|
}
|
|
114
115
|
return servers;
|
|
@@ -120,7 +121,7 @@ export function mapToOpenAIMcpServers(config, orgJwt, innerFetch = fetch) {
|
|
|
120
121
|
* every other URL through unchanged, so this is safe to wire on any remote
|
|
121
122
|
* server whenever an `orgJwt` is available.
|
|
122
123
|
*/
|
|
123
|
-
function createAuthFetch(serverUrl, orgJwt, innerFetch, existingHeaders) {
|
|
124
|
+
export function createAuthFetch(serverUrl, orgJwt, innerFetch, existingHeaders) {
|
|
124
125
|
return async (url, init) => {
|
|
125
126
|
const authHeaders = await resolveMcpServerHeaders(serverUrl, orgJwt, existingHeaders);
|
|
126
127
|
const merged = new Headers(init?.headers);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openai-mcp-config-mapper.js","sourceRoot":"","sources":["../src/openai-mcp-config-mapper.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAA+C,uBAAuB,EAAE,MAAM,4BAA4B,CAAC;AAClH,OAAO,EAAE,cAAc,EAAE,uBAAuB,EAAkB,MAAM,gBAAgB,CAAC;AAWzF;;;;;;;;;;;;;GAaG;AACH,MAAM,4BAA4B,GAAG;
|
|
1
|
+
{"version":3,"file":"openai-mcp-config-mapper.js","sourceRoot":"","sources":["../src/openai-mc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AAC;IACzD,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type ModelProvider } from '@openai/agents';
|
|
2
|
-
import { type Clock } from '@salesforce/agentic-common';
|
|
2
|
+
import { type Clock, type UniqueIDGenerator } from '@salesforce/agentic-common';
|
|
3
3
|
import type { ModelConnectivityInfo, WireCommunicationEvent } from '@salesforce/sfdx-agent-sdk';
|
|
4
4
|
/**
|
|
5
5
|
* Per-request wire-communication hooks. When supplied to
|
|
@@ -15,6 +15,12 @@ export type WireHooks = {
|
|
|
15
15
|
emitWireCommunication: (event: WireCommunicationEvent) => void;
|
|
16
16
|
/** Time source for the event `timestamp`s; defaults to a fresh `RealClock`. */
|
|
17
17
|
clock?: Clock;
|
|
18
|
+
/** ID source for pairing one fetch's request and terminal response events. */
|
|
19
|
+
idGenerator?: UniqueIDGenerator;
|
|
20
|
+
/** Whether the harness currently has wire subscribers (avoids a tee when it does not). */
|
|
21
|
+
hasWireCommunicationSubscribers?: () => boolean;
|
|
22
|
+
/** Aborted by harness shutdown so detached body observers cannot outlive their owner. */
|
|
23
|
+
disposeSignal?: AbortSignal;
|
|
18
24
|
};
|
|
19
25
|
/**
|
|
20
26
|
* Builds a `@openai/agents` {@link ModelProvider} bound to the live
|
|
@@ -44,3 +50,18 @@ export declare function buildOpenAIModelProvider(opts: {
|
|
|
44
50
|
/** Wire-communication emission hooks. Omit to disable emission. */
|
|
45
51
|
wireHooks?: WireHooks;
|
|
46
52
|
}): ModelProvider;
|
|
53
|
+
/**
|
|
54
|
+
* Returns a `fetch` that merges the resolver's fresh headers into every
|
|
55
|
+
* outbound request. `getHeaders()` is re-evaluated per call so JWT rotation /
|
|
56
|
+
* premium-rate-limit gate flips land on the next request without rebuilding the
|
|
57
|
+
* client. Delegates to the proxy-aware `innerFetch` when supplied (so
|
|
58
|
+
* `HTTPS_PROXY` is honored), else the global `fetch`.
|
|
59
|
+
*
|
|
60
|
+
* When `wireHooks` is supplied, every outbound call emits one `llm-request`
|
|
61
|
+
* event before the fetch and one `llm-response` when its HTTP body terminates —
|
|
62
|
+
* or, on a transport failure, an `llm-response` with `status: 0` + the captured
|
|
63
|
+
* error, then rethrows (a wire hook never swallows the underlying fetch). Body capture
|
|
64
|
+
* is best-effort and bounded ({@link TRACE_BODY_BYTE_BUDGET}); a decode failure
|
|
65
|
+
* never blocks the call.
|
|
66
|
+
*/
|
|
67
|
+
export declare function buildGatewayFetch(getInfo: () => ModelConnectivityInfo, innerFetch?: typeof fetch, wireHooks?: WireHooks): typeof fetch;
|