@openai/agents-core 0.4.1 → 0.4.3
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/dist/agent.d.ts +5 -4
- package/dist/agent.js +22 -3
- package/dist/agent.js.map +1 -1
- package/dist/agent.mjs +22 -3
- package/dist/agent.mjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +5 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/logger.js +2 -2
- package/dist/logger.js.map +1 -1
- package/dist/logger.mjs +2 -2
- package/dist/logger.mjs.map +1 -1
- package/dist/mcpServers.d.ts +55 -0
- package/dist/mcpServers.js +472 -0
- package/dist/mcpServers.js.map +1 -0
- package/dist/mcpServers.mjs +467 -0
- package/dist/mcpServers.mjs.map +1 -0
- package/dist/metadata.js +2 -2
- package/dist/metadata.mjs +2 -2
- package/dist/result.d.ts +5 -0
- package/dist/result.js +62 -17
- package/dist/result.js.map +1 -1
- package/dist/result.mjs +62 -17
- package/dist/result.mjs.map +1 -1
- package/dist/run.d.ts +16 -9
- package/dist/run.js +55 -0
- package/dist/run.js.map +1 -1
- package/dist/run.mjs +56 -1
- package/dist/run.mjs.map +1 -1
- package/dist/runState.d.ts +10 -0
- package/dist/runState.js +11 -0
- package/dist/runState.js.map +1 -1
- package/dist/runState.mjs +11 -0
- package/dist/runState.mjs.map +1 -1
- package/dist/runner/errorHandlers.d.ts +57 -0
- package/dist/runner/errorHandlers.js +65 -0
- package/dist/runner/errorHandlers.js.map +1 -0
- package/dist/runner/errorHandlers.mjs +61 -0
- package/dist/runner/errorHandlers.mjs.map +1 -0
- package/dist/runner/runLoop.js +4 -0
- package/dist/runner/runLoop.js.map +1 -1
- package/dist/runner/runLoop.mjs +4 -0
- package/dist/runner/runLoop.mjs.map +1 -1
- package/dist/runner/tracing.d.ts +14 -1
- package/dist/runner/tracing.js +43 -0
- package/dist/runner/tracing.js.map +1 -1
- package/dist/runner/tracing.mjs +42 -0
- package/dist/runner/tracing.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,467 @@
|
|
|
1
|
+
import { getLogger } from "./logger.mjs";
|
|
2
|
+
const DEFAULT_CONNECT_TIMEOUT_MS = 10_000;
|
|
3
|
+
const DEFAULT_CLOSE_TIMEOUT_MS = 10_000;
|
|
4
|
+
const logger = getLogger('openai-agents:mcp-servers');
|
|
5
|
+
class ServerWorker {
|
|
6
|
+
server;
|
|
7
|
+
connectTimeoutMs;
|
|
8
|
+
closeTimeoutMs;
|
|
9
|
+
queue = [];
|
|
10
|
+
draining = false;
|
|
11
|
+
done = false;
|
|
12
|
+
closing = null;
|
|
13
|
+
closeResult = null;
|
|
14
|
+
constructor(server, connectTimeoutMs, closeTimeoutMs) {
|
|
15
|
+
this.server = server;
|
|
16
|
+
this.connectTimeoutMs = connectTimeoutMs;
|
|
17
|
+
this.closeTimeoutMs = closeTimeoutMs;
|
|
18
|
+
}
|
|
19
|
+
get isDone() {
|
|
20
|
+
return this.done;
|
|
21
|
+
}
|
|
22
|
+
connect() {
|
|
23
|
+
return this.submit('connect', this.connectTimeoutMs);
|
|
24
|
+
}
|
|
25
|
+
close() {
|
|
26
|
+
return this.submit('close', this.closeTimeoutMs);
|
|
27
|
+
}
|
|
28
|
+
submit(action, timeoutMs) {
|
|
29
|
+
if (this.done) {
|
|
30
|
+
return Promise.reject(createClosedError(this.server));
|
|
31
|
+
}
|
|
32
|
+
if (this.closeResult || this.closing) {
|
|
33
|
+
if (action === 'close' && this.closeResult) {
|
|
34
|
+
return this.closeResult;
|
|
35
|
+
}
|
|
36
|
+
return Promise.reject(createClosingError(this.server));
|
|
37
|
+
}
|
|
38
|
+
let resolveCommand;
|
|
39
|
+
let rejectCommand;
|
|
40
|
+
const promise = new Promise((resolve, reject) => {
|
|
41
|
+
resolveCommand = resolve;
|
|
42
|
+
rejectCommand = reject;
|
|
43
|
+
});
|
|
44
|
+
const command = {
|
|
45
|
+
action,
|
|
46
|
+
timeoutMs,
|
|
47
|
+
resolve: resolveCommand,
|
|
48
|
+
reject: rejectCommand,
|
|
49
|
+
};
|
|
50
|
+
if (action === 'close') {
|
|
51
|
+
this.closeResult = promise;
|
|
52
|
+
}
|
|
53
|
+
this.queue.push(command);
|
|
54
|
+
void this.drain();
|
|
55
|
+
return promise;
|
|
56
|
+
}
|
|
57
|
+
async drain() {
|
|
58
|
+
if (this.draining) {
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
this.draining = true;
|
|
62
|
+
while (this.queue.length > 0) {
|
|
63
|
+
const command = this.queue.shift();
|
|
64
|
+
if (!command) {
|
|
65
|
+
continue;
|
|
66
|
+
}
|
|
67
|
+
const shouldExit = command.action === 'close';
|
|
68
|
+
let closeError = null;
|
|
69
|
+
try {
|
|
70
|
+
if (command.action === 'connect') {
|
|
71
|
+
await runWithTimeout(() => this.server.connect(), command.timeoutMs, createTimeoutError('connect', this.server, command.timeoutMs));
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
const closeTask = this.server.close();
|
|
75
|
+
this.closing = closeTask
|
|
76
|
+
.then(() => undefined, () => undefined)
|
|
77
|
+
.finally(() => {
|
|
78
|
+
this.closing = null;
|
|
79
|
+
});
|
|
80
|
+
await runWithTimeoutTask(closeTask, command.timeoutMs, createTimeoutError('close', this.server, command.timeoutMs));
|
|
81
|
+
}
|
|
82
|
+
command.resolve();
|
|
83
|
+
}
|
|
84
|
+
catch (error) {
|
|
85
|
+
const err = toError(error);
|
|
86
|
+
command.reject(err);
|
|
87
|
+
if (shouldExit) {
|
|
88
|
+
closeError = err;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (shouldExit) {
|
|
92
|
+
const pendingError = closeError ?? createClosedError(this.server);
|
|
93
|
+
while (this.queue.length > 0) {
|
|
94
|
+
const pending = this.queue.shift();
|
|
95
|
+
if (pending) {
|
|
96
|
+
pending.reject(pendingError);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
this.closeResult = null;
|
|
100
|
+
if (!closeError) {
|
|
101
|
+
this.done = true;
|
|
102
|
+
}
|
|
103
|
+
break;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
this.draining = false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Manages MCP server lifecycle and exposes only connected servers.
|
|
111
|
+
*/
|
|
112
|
+
export class MCPServers {
|
|
113
|
+
allServers;
|
|
114
|
+
activeServers;
|
|
115
|
+
failedServers = [];
|
|
116
|
+
failedServerSet = new Set();
|
|
117
|
+
errorsByServer = new Map();
|
|
118
|
+
suppressedAbortFailures = new Set();
|
|
119
|
+
workers = new Map();
|
|
120
|
+
connectTimeoutMs;
|
|
121
|
+
closeTimeoutMs;
|
|
122
|
+
dropFailed;
|
|
123
|
+
strict;
|
|
124
|
+
suppressAbortError;
|
|
125
|
+
connectInParallel;
|
|
126
|
+
static {
|
|
127
|
+
const asyncDispose = Symbol.asyncDispose;
|
|
128
|
+
if (asyncDispose) {
|
|
129
|
+
Object.defineProperty(this.prototype, asyncDispose, {
|
|
130
|
+
value: function () {
|
|
131
|
+
return this.close();
|
|
132
|
+
},
|
|
133
|
+
configurable: true,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
constructor(servers, options) {
|
|
138
|
+
this.allServers = [...servers];
|
|
139
|
+
this.activeServers = [...servers];
|
|
140
|
+
this.connectTimeoutMs =
|
|
141
|
+
options?.connectTimeoutMs === undefined
|
|
142
|
+
? DEFAULT_CONNECT_TIMEOUT_MS
|
|
143
|
+
: options.connectTimeoutMs;
|
|
144
|
+
this.closeTimeoutMs =
|
|
145
|
+
options?.closeTimeoutMs === undefined
|
|
146
|
+
? DEFAULT_CLOSE_TIMEOUT_MS
|
|
147
|
+
: options.closeTimeoutMs;
|
|
148
|
+
this.dropFailed = options?.dropFailed ?? true;
|
|
149
|
+
this.strict = options?.strict ?? false;
|
|
150
|
+
this.suppressAbortError = options?.suppressAbortError ?? true;
|
|
151
|
+
this.connectInParallel = options?.connectInParallel ?? false;
|
|
152
|
+
}
|
|
153
|
+
static async open(servers, options) {
|
|
154
|
+
const session = new MCPServers(servers, options);
|
|
155
|
+
logger.debug(`Opening MCPServers with ${session.allServers.length} server(s).`);
|
|
156
|
+
await session.connectAll();
|
|
157
|
+
return session;
|
|
158
|
+
}
|
|
159
|
+
get all() {
|
|
160
|
+
return [...this.allServers];
|
|
161
|
+
}
|
|
162
|
+
get active() {
|
|
163
|
+
return [...this.activeServers];
|
|
164
|
+
}
|
|
165
|
+
get failed() {
|
|
166
|
+
return [...this.failedServers];
|
|
167
|
+
}
|
|
168
|
+
get errors() {
|
|
169
|
+
return new Map(this.errorsByServer);
|
|
170
|
+
}
|
|
171
|
+
async reconnect(options = {}) {
|
|
172
|
+
const failedOnly = options.failedOnly ?? true;
|
|
173
|
+
let serversToRetry;
|
|
174
|
+
if (failedOnly) {
|
|
175
|
+
serversToRetry = uniqueServers(this.failedServers);
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
serversToRetry = [...this.allServers];
|
|
179
|
+
this.failedServers = [];
|
|
180
|
+
this.failedServerSet = new Set();
|
|
181
|
+
this.errorsByServer = new Map();
|
|
182
|
+
this.suppressedAbortFailures = new Set();
|
|
183
|
+
}
|
|
184
|
+
logger.debug(`Reconnecting MCP servers (failedOnly=${failedOnly}) with ${serversToRetry.length} target(s).`);
|
|
185
|
+
if (this.connectInParallel) {
|
|
186
|
+
await this.connectAllParallel(serversToRetry);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
for (const server of serversToRetry) {
|
|
190
|
+
await this.attemptConnect(server);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
this.refreshActiveServers();
|
|
194
|
+
return this.active;
|
|
195
|
+
}
|
|
196
|
+
async close() {
|
|
197
|
+
await this.closeAll();
|
|
198
|
+
}
|
|
199
|
+
async connectAll() {
|
|
200
|
+
this.failedServers = [];
|
|
201
|
+
this.failedServerSet = new Set();
|
|
202
|
+
this.errorsByServer = new Map();
|
|
203
|
+
this.suppressedAbortFailures = new Set();
|
|
204
|
+
const serversToConnect = [...this.allServers];
|
|
205
|
+
let connectedServers = [];
|
|
206
|
+
logger.debug(`Connecting ${serversToConnect.length} MCP server(s).`);
|
|
207
|
+
try {
|
|
208
|
+
if (this.connectInParallel) {
|
|
209
|
+
await this.connectAllParallel(serversToConnect);
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
for (const server of serversToConnect) {
|
|
213
|
+
await this.attemptConnect(server);
|
|
214
|
+
if (!this.failedServerSet.has(server)) {
|
|
215
|
+
connectedServers.push(server);
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
if (this.connectInParallel) {
|
|
222
|
+
connectedServers = serversToConnect.filter((server) => !this.failedServerSet.has(server));
|
|
223
|
+
}
|
|
224
|
+
const serversToCleanup = uniqueServers([
|
|
225
|
+
...connectedServers,
|
|
226
|
+
...this.failedServers,
|
|
227
|
+
]);
|
|
228
|
+
await this.closeServers(serversToCleanup);
|
|
229
|
+
this.activeServers = [];
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
this.refreshActiveServers();
|
|
233
|
+
return this.active;
|
|
234
|
+
}
|
|
235
|
+
async closeAll() {
|
|
236
|
+
for (const server of [...this.allServers].reverse()) {
|
|
237
|
+
await this.closeServer(server);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
async attemptConnect(server) {
|
|
241
|
+
const raiseOnError = this.strict;
|
|
242
|
+
try {
|
|
243
|
+
logger.debug(`Connecting MCP server '${server.name}'.`);
|
|
244
|
+
await this.runConnect(server);
|
|
245
|
+
logger.debug(`Connected MCP server '${server.name}'.`);
|
|
246
|
+
if (this.failedServerSet.has(server)) {
|
|
247
|
+
this.removeFailedServer(server);
|
|
248
|
+
this.errorsByServer.delete(server);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
catch (error) {
|
|
252
|
+
const err = toError(error);
|
|
253
|
+
if (isAbortError(err)) {
|
|
254
|
+
this.recordFailure(server, err, 'connect');
|
|
255
|
+
if (!this.suppressAbortError) {
|
|
256
|
+
this.suppressedAbortFailures.delete(server);
|
|
257
|
+
throw err;
|
|
258
|
+
}
|
|
259
|
+
this.suppressedAbortFailures.add(server);
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
this.suppressedAbortFailures.delete(server);
|
|
263
|
+
this.recordFailure(server, err, 'connect');
|
|
264
|
+
if (raiseOnError) {
|
|
265
|
+
throw err;
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
refreshActiveServers() {
|
|
270
|
+
if (this.dropFailed) {
|
|
271
|
+
const failed = new Set(this.failedServerSet);
|
|
272
|
+
this.activeServers = this.allServers.filter((server) => !failed.has(server));
|
|
273
|
+
}
|
|
274
|
+
else {
|
|
275
|
+
this.activeServers = [...this.allServers];
|
|
276
|
+
}
|
|
277
|
+
logger.debug(`Active MCP servers: ${this.activeServers.length}; failed: ${this.failedServers.length}.`);
|
|
278
|
+
}
|
|
279
|
+
recordFailure(server, error, phase) {
|
|
280
|
+
logger.error(`Failed to ${phase} MCP server '${server.name}':`, error);
|
|
281
|
+
if (!this.failedServerSet.has(server)) {
|
|
282
|
+
this.failedServers.push(server);
|
|
283
|
+
this.failedServerSet.add(server);
|
|
284
|
+
}
|
|
285
|
+
this.errorsByServer.set(server, error);
|
|
286
|
+
}
|
|
287
|
+
async runConnect(server) {
|
|
288
|
+
if (this.connectInParallel) {
|
|
289
|
+
const worker = this.getWorker(server);
|
|
290
|
+
await worker.connect();
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
await runWithTimeout(() => server.connect(), this.connectTimeoutMs, createTimeoutError('connect', server, this.connectTimeoutMs));
|
|
294
|
+
}
|
|
295
|
+
async closeServer(server) {
|
|
296
|
+
try {
|
|
297
|
+
logger.debug(`Closing MCP server '${server.name}'.`);
|
|
298
|
+
await this.runClose(server);
|
|
299
|
+
logger.debug(`Closed MCP server '${server.name}'.`);
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
const err = toError(error);
|
|
303
|
+
if (isAbortError(err)) {
|
|
304
|
+
if (!this.suppressAbortError) {
|
|
305
|
+
throw err;
|
|
306
|
+
}
|
|
307
|
+
logger.debug(`Close cancelled for MCP server '${server.name}': ${err}`);
|
|
308
|
+
this.errorsByServer.set(server, err);
|
|
309
|
+
return;
|
|
310
|
+
}
|
|
311
|
+
logger.error(`Failed to close MCP server '${server.name}':`, err);
|
|
312
|
+
this.errorsByServer.set(server, err);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
async runClose(server) {
|
|
316
|
+
if (this.connectInParallel && this.workers.has(server)) {
|
|
317
|
+
const worker = this.workers.get(server);
|
|
318
|
+
if (worker) {
|
|
319
|
+
await worker.close();
|
|
320
|
+
if (worker.isDone) {
|
|
321
|
+
this.workers.delete(server);
|
|
322
|
+
}
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
await runWithTimeout(() => server.close(), this.closeTimeoutMs, createTimeoutError('close', server, this.closeTimeoutMs));
|
|
327
|
+
}
|
|
328
|
+
async closeServers(servers) {
|
|
329
|
+
for (const server of [...servers].reverse()) {
|
|
330
|
+
await this.closeServer(server);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
async connectAllParallel(servers) {
|
|
334
|
+
const results = await Promise.allSettled(servers.map((server) => this.attemptConnect(server)));
|
|
335
|
+
const rejection = results.find((result) => result.status === 'rejected');
|
|
336
|
+
if (rejection) {
|
|
337
|
+
throw rejection.reason;
|
|
338
|
+
}
|
|
339
|
+
if (this.strict && this.failedServers.length > 0) {
|
|
340
|
+
const firstFailure = this.failedServers.find((server) => !this.suppressedAbortFailures.has(server));
|
|
341
|
+
if (firstFailure) {
|
|
342
|
+
const error = this.errorsByServer.get(firstFailure);
|
|
343
|
+
if (error) {
|
|
344
|
+
throw error;
|
|
345
|
+
}
|
|
346
|
+
throw new Error(`Failed to connect MCP server '${firstFailure.name}'.`);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
getWorker(server) {
|
|
351
|
+
const worker = this.workers.get(server);
|
|
352
|
+
if (!worker || worker.isDone) {
|
|
353
|
+
const next = new ServerWorker(server, this.connectTimeoutMs, this.closeTimeoutMs);
|
|
354
|
+
this.workers.set(server, next);
|
|
355
|
+
return next;
|
|
356
|
+
}
|
|
357
|
+
return worker;
|
|
358
|
+
}
|
|
359
|
+
removeFailedServer(server) {
|
|
360
|
+
if (this.failedServerSet.has(server)) {
|
|
361
|
+
this.failedServerSet.delete(server);
|
|
362
|
+
}
|
|
363
|
+
this.suppressedAbortFailures.delete(server);
|
|
364
|
+
this.failedServers = this.failedServers.filter((failedServer) => failedServer !== server);
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Connect to multiple MCP servers and return a managed MCPServers instance.
|
|
369
|
+
*/
|
|
370
|
+
export async function connectMcpServers(servers, options) {
|
|
371
|
+
return MCPServers.open(servers, options);
|
|
372
|
+
}
|
|
373
|
+
function createTimeoutError(action, server, timeoutMs) {
|
|
374
|
+
if (timeoutMs === null) {
|
|
375
|
+
return new Error(`MCP server ${action} timed out.`);
|
|
376
|
+
}
|
|
377
|
+
const error = new Error(`MCP server ${action} timed out after ${timeoutMs}ms for '${server.name}'.`);
|
|
378
|
+
error.name = 'TimeoutError';
|
|
379
|
+
return error;
|
|
380
|
+
}
|
|
381
|
+
function createClosedError(server) {
|
|
382
|
+
const error = new Error(`MCP server '${server.name}' is closed.`);
|
|
383
|
+
error.name = 'ClosedError';
|
|
384
|
+
return error;
|
|
385
|
+
}
|
|
386
|
+
function createClosingError(server) {
|
|
387
|
+
const error = new Error(`MCP server '${server.name}' is closing.`);
|
|
388
|
+
error.name = 'ClosingError';
|
|
389
|
+
return error;
|
|
390
|
+
}
|
|
391
|
+
async function runWithTimeout(fn, timeoutMs, timeoutError) {
|
|
392
|
+
if (timeoutMs === null) {
|
|
393
|
+
await fn();
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
let timer;
|
|
397
|
+
let timedOut = false;
|
|
398
|
+
const task = fn();
|
|
399
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
400
|
+
timer = setTimeout(() => {
|
|
401
|
+
timedOut = true;
|
|
402
|
+
reject(timeoutError);
|
|
403
|
+
}, timeoutMs);
|
|
404
|
+
});
|
|
405
|
+
try {
|
|
406
|
+
await Promise.race([task, timeoutPromise]);
|
|
407
|
+
}
|
|
408
|
+
finally {
|
|
409
|
+
if (timer) {
|
|
410
|
+
clearTimeout(timer);
|
|
411
|
+
}
|
|
412
|
+
if (timedOut) {
|
|
413
|
+
task.catch(() => undefined);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
async function runWithTimeoutTask(task, timeoutMs, timeoutError) {
|
|
418
|
+
if (timeoutMs === null) {
|
|
419
|
+
await task;
|
|
420
|
+
return;
|
|
421
|
+
}
|
|
422
|
+
let timer;
|
|
423
|
+
let timedOut = false;
|
|
424
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
425
|
+
timer = setTimeout(() => {
|
|
426
|
+
timedOut = true;
|
|
427
|
+
reject(timeoutError);
|
|
428
|
+
}, timeoutMs);
|
|
429
|
+
});
|
|
430
|
+
try {
|
|
431
|
+
await Promise.race([task, timeoutPromise]);
|
|
432
|
+
}
|
|
433
|
+
finally {
|
|
434
|
+
if (timer) {
|
|
435
|
+
clearTimeout(timer);
|
|
436
|
+
}
|
|
437
|
+
if (timedOut) {
|
|
438
|
+
task.catch(() => undefined);
|
|
439
|
+
}
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
function toError(error) {
|
|
443
|
+
if (error instanceof Error) {
|
|
444
|
+
return error;
|
|
445
|
+
}
|
|
446
|
+
return new Error(String(error));
|
|
447
|
+
}
|
|
448
|
+
function isAbortError(error) {
|
|
449
|
+
const code = error.code;
|
|
450
|
+
return (error.name === 'AbortError' ||
|
|
451
|
+
error.name === 'CanceledError' ||
|
|
452
|
+
error.name === 'CancelledError' ||
|
|
453
|
+
code === 'ABORT_ERR' ||
|
|
454
|
+
code === 'ERR_ABORTED');
|
|
455
|
+
}
|
|
456
|
+
function uniqueServers(servers) {
|
|
457
|
+
const seen = new Set();
|
|
458
|
+
const unique = [];
|
|
459
|
+
for (const server of servers) {
|
|
460
|
+
if (!seen.has(server)) {
|
|
461
|
+
seen.add(server);
|
|
462
|
+
unique.push(server);
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
return unique;
|
|
466
|
+
}
|
|
467
|
+
//# sourceMappingURL=mcpServers.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcpServers.mjs","sourceRoot":"","sources":["../src/mcpServers.ts"],"names":[],"mappings":"OAAO,EAAE,SAAS,EAAE;AAGpB,MAAM,0BAA0B,GAAG,MAAM,CAAC;AAC1C,MAAM,wBAAwB,GAAG,MAAM,CAAC;AAExC,MAAM,MAAM,GAAG,SAAS,CAAC,2BAA2B,CAAC,CAAC;AAWtD,MAAM,YAAY;IAQG;IACA;IACA;IATX,KAAK,GAAoB,EAAE,CAAC;IAC5B,QAAQ,GAAG,KAAK,CAAC;IACjB,IAAI,GAAG,KAAK,CAAC;IACb,OAAO,GAAyB,IAAI,CAAC;IACrC,WAAW,GAAyB,IAAI,CAAC;IAEjD,YACmB,MAAiB,EACjB,gBAA+B,EAC/B,cAA6B;QAF7B,WAAM,GAAN,MAAM,CAAW;QACjB,qBAAgB,GAAhB,gBAAgB,CAAe;QAC/B,mBAAc,GAAd,cAAc,CAAe;IAC7C,CAAC;IAEJ,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;IAED,OAAO;QACL,OAAO,IAA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HANGED
|
@@ -4,9 +4,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
4
4
|
exports.METADATA = void 0;
|
|
5
5
|
exports.METADATA = {
|
|
6
6
|
"name": "@openai/agents-core",
|
|
7
|
-
"version": "0.4.
|
|
7
|
+
"version": "0.4.3",
|
|
8
8
|
"versions": {
|
|
9
|
-
"@openai/agents-core": "0.4.
|
|
9
|
+
"@openai/agents-core": "0.4.3",
|
|
10
10
|
"openai": "^6"
|
|
11
11
|
}
|
|
12
12
|
};
|
package/dist/metadata.mjs
CHANGED
package/dist/result.d.ts
CHANGED
|
@@ -105,6 +105,11 @@ declare class RunResultBase<TContext, TAgent extends Agent<TContext, any>> imple
|
|
|
105
105
|
* The last agent that was run
|
|
106
106
|
*/
|
|
107
107
|
get lastAgent(): TAgent | undefined;
|
|
108
|
+
/**
|
|
109
|
+
* The agent that should handle the next turn.
|
|
110
|
+
* This is an alias for the last agent that completed a turn.
|
|
111
|
+
*/
|
|
112
|
+
get activeAgent(): TAgent | undefined;
|
|
108
113
|
/**
|
|
109
114
|
* Guardrail results for the input messages.
|
|
110
115
|
*/
|
package/dist/result.js
CHANGED
|
@@ -8,6 +8,13 @@ const _shims_1 = require("@openai/agents-core/_shims");
|
|
|
8
8
|
const items_1 = require("./runner/items.js");
|
|
9
9
|
const logger_1 = __importDefault(require("./logger.js"));
|
|
10
10
|
const protocol_1 = require("./types/protocol.js");
|
|
11
|
+
function createAbortHandlerRef() {
|
|
12
|
+
const ref = {};
|
|
13
|
+
const handler = () => {
|
|
14
|
+
ref.current?.();
|
|
15
|
+
};
|
|
16
|
+
return { ref, handler };
|
|
17
|
+
}
|
|
11
18
|
function combineAbortSignals(...signals) {
|
|
12
19
|
const active = signals.filter(Boolean);
|
|
13
20
|
if (active.length === 0) {
|
|
@@ -99,6 +106,13 @@ class RunResultBase {
|
|
|
99
106
|
get lastAgent() {
|
|
100
107
|
return this.state._currentAgent;
|
|
101
108
|
}
|
|
109
|
+
/**
|
|
110
|
+
* The agent that should handle the next turn.
|
|
111
|
+
* This is an alias for the last agent that completed a turn.
|
|
112
|
+
*/
|
|
113
|
+
get activeAgent() {
|
|
114
|
+
return this.lastAgent;
|
|
115
|
+
}
|
|
102
116
|
/**
|
|
103
117
|
* Guardrail results for the input messages.
|
|
104
118
|
*/
|
|
@@ -173,6 +187,7 @@ class StreamedRunResult extends RunResultBase {
|
|
|
173
187
|
maxTurns;
|
|
174
188
|
#error = null;
|
|
175
189
|
#combinedSignal;
|
|
190
|
+
#abortSignalSnapshot;
|
|
176
191
|
#abortController;
|
|
177
192
|
#readableController;
|
|
178
193
|
#readableStream;
|
|
@@ -181,10 +196,13 @@ class StreamedRunResult extends RunResultBase {
|
|
|
181
196
|
#completedPromiseReject;
|
|
182
197
|
#cancelled = false;
|
|
183
198
|
#streamLoopPromise;
|
|
199
|
+
#abortHandler;
|
|
200
|
+
#abortHandlerRef;
|
|
184
201
|
constructor(result = {}) {
|
|
185
202
|
super(result.state);
|
|
186
203
|
this.#abortController = new AbortController();
|
|
187
204
|
this.#combinedSignal = combineAbortSignals(result.signal, this.#abortController.signal);
|
|
205
|
+
this.#abortSignalSnapshot = this.#combinedSignal;
|
|
188
206
|
this.#readableStream = new _shims_1.ReadableStream({
|
|
189
207
|
start: (controller) => {
|
|
190
208
|
this.#readableController = controller;
|
|
@@ -200,23 +218,13 @@ class StreamedRunResult extends RunResultBase {
|
|
|
200
218
|
this.#completedPromiseReject = reject;
|
|
201
219
|
});
|
|
202
220
|
if (this.#combinedSignal) {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
this.#cancelled = true;
|
|
208
|
-
const controller = this.#readableController;
|
|
209
|
-
this.#readableController = undefined;
|
|
210
|
-
if (controller) {
|
|
211
|
-
try {
|
|
212
|
-
controller.close();
|
|
213
|
-
}
|
|
214
|
-
catch (err) {
|
|
215
|
-
logger_1.default.debug(`Failed to close readable stream on abort: ${err}`);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
this.#completedPromiseResolve?.();
|
|
221
|
+
// Create the handler outside this scope so it cannot capture the run via lexical this.
|
|
222
|
+
const { ref: abortRef, handler: handleAbort } = createAbortHandlerRef();
|
|
223
|
+
abortRef.current = () => {
|
|
224
|
+
this.#handleAbort();
|
|
219
225
|
};
|
|
226
|
+
this.#abortHandler = handleAbort;
|
|
227
|
+
this.#abortHandlerRef = abortRef;
|
|
220
228
|
if (this.#combinedSignal.aborted) {
|
|
221
229
|
handleAbort();
|
|
222
230
|
}
|
|
@@ -246,6 +254,7 @@ class StreamedRunResult extends RunResultBase {
|
|
|
246
254
|
this.#readableController = undefined;
|
|
247
255
|
this.#completedPromiseResolve?.();
|
|
248
256
|
}
|
|
257
|
+
this.#detachAbortHandler();
|
|
249
258
|
}
|
|
250
259
|
/**
|
|
251
260
|
* @internal
|
|
@@ -261,6 +270,7 @@ class StreamedRunResult extends RunResultBase {
|
|
|
261
270
|
this.#completedPromise.catch((e) => {
|
|
262
271
|
logger_1.default.debug(`Resulted in an error: ${e}`);
|
|
263
272
|
});
|
|
273
|
+
this.#detachAbortHandler();
|
|
264
274
|
}
|
|
265
275
|
/**
|
|
266
276
|
* Returns true if the stream has been cancelled.
|
|
@@ -327,7 +337,42 @@ class StreamedRunResult extends RunResultBase {
|
|
|
327
337
|
* Returns the abort signal that should be used to cancel the streaming run.
|
|
328
338
|
*/
|
|
329
339
|
_getAbortSignal() {
|
|
330
|
-
return this.#combinedSignal;
|
|
340
|
+
return this.#abortSignalSnapshot ?? this.#combinedSignal;
|
|
341
|
+
}
|
|
342
|
+
#handleAbort() {
|
|
343
|
+
if (this.#cancelled) {
|
|
344
|
+
this.#detachAbortHandler();
|
|
345
|
+
return;
|
|
346
|
+
}
|
|
347
|
+
this.#cancelled = true;
|
|
348
|
+
const controller = this.#readableController;
|
|
349
|
+
this.#readableController = undefined;
|
|
350
|
+
if (controller) {
|
|
351
|
+
try {
|
|
352
|
+
controller.close();
|
|
353
|
+
}
|
|
354
|
+
catch (err) {
|
|
355
|
+
logger_1.default.debug(`Failed to close readable stream on abort: ${err}`);
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
this.#completedPromiseResolve?.();
|
|
359
|
+
this.#detachAbortHandler();
|
|
360
|
+
}
|
|
361
|
+
#detachAbortHandler() {
|
|
362
|
+
// Clear the indirection first so a retained signal cannot keep this run alive.
|
|
363
|
+
if (this.#abortHandlerRef) {
|
|
364
|
+
this.#abortHandlerRef.current = undefined;
|
|
365
|
+
}
|
|
366
|
+
if (this.#combinedSignal && this.#abortHandler) {
|
|
367
|
+
try {
|
|
368
|
+
this.#combinedSignal.removeEventListener('abort', this.#abortHandler);
|
|
369
|
+
}
|
|
370
|
+
catch (err) {
|
|
371
|
+
logger_1.default.debug(`Failed to remove abort listener: ${err}`);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
this.#abortHandler = undefined;
|
|
375
|
+
this.#abortHandlerRef = undefined;
|
|
331
376
|
}
|
|
332
377
|
}
|
|
333
378
|
exports.StreamedRunResult = StreamedRunResult;
|