@openai/agents-core 0.0.16 → 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.
- package/dist/agent.d.ts +5 -3
- package/dist/agent.js +46 -23
- package/dist/agent.js.map +1 -1
- package/dist/agent.mjs +17 -1
- package/dist/agent.mjs.map +1 -1
- package/dist/computer.js +2 -1
- package/dist/config.js +12 -6
- package/dist/config.js.map +1 -1
- package/dist/defaultModel.d.ts +22 -0
- package/dist/defaultModel.js +56 -0
- package/dist/defaultModel.js.map +1 -0
- package/dist/defaultModel.mjs +49 -0
- package/dist/defaultModel.mjs.map +1 -0
- package/dist/errors.js +21 -9
- package/dist/errors.js.map +1 -1
- package/dist/events.js +9 -3
- package/dist/events.js.map +1 -1
- package/dist/extensions/handoffFilters.js +9 -6
- package/dist/extensions/handoffFilters.js.map +1 -1
- package/dist/extensions/handoffPrompt.js +7 -3
- package/dist/extensions/handoffPrompt.js.map +1 -1
- package/dist/extensions/index.js +8 -2
- package/dist/extensions/index.js.map +1 -1
- package/dist/guardrail.js +6 -2
- package/dist/guardrail.js.map +1 -1
- package/dist/handoff.js +28 -18
- package/dist/handoff.js.map +1 -1
- package/dist/helpers/message.js +8 -3
- package/dist/helpers/message.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +127 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/index.mjs.map +1 -1
- package/dist/items.js +23 -11
- package/dist/items.js.map +1 -1
- package/dist/lifecycle.js +12 -6
- package/dist/lifecycle.js.map +1 -1
- package/dist/logger.js +15 -8
- package/dist/logger.js.map +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +60 -45
- package/dist/mcp.js.map +1 -1
- package/dist/mcp.mjs +1 -1
- package/dist/mcp.mjs.map +1 -1
- package/dist/mcpUtil.js +4 -1
- package/dist/mcpUtil.js.map +1 -1
- package/dist/metadata.d.ts +0 -1
- package/dist/metadata.js +8 -6
- package/dist/metadata.js.map +1 -1
- package/dist/metadata.mjs +3 -4
- package/dist/metadata.mjs.map +1 -1
- package/dist/model.d.ts +7 -0
- package/dist/model.js +2 -1
- package/dist/providers.js +6 -2
- package/dist/providers.js.map +1 -1
- package/dist/result.js +22 -14
- package/dist/result.js.map +1 -1
- package/dist/run.d.ts +1 -0
- package/dist/run.js +145 -95
- package/dist/run.js.map +1 -1
- package/dist/run.mjs +39 -0
- package/dist/run.mjs.map +1 -1
- package/dist/runContext.d.ts +1 -1
- package/dist/runContext.js +14 -7
- package/dist/runContext.js.map +1 -1
- package/dist/runContext.mjs +1 -1
- package/dist/runImplementation.d.ts +1 -1
- package/dist/runImplementation.js +107 -90
- package/dist/runImplementation.js.map +1 -1
- package/dist/runImplementation.mjs +2 -2
- package/dist/runImplementation.mjs.map +1 -1
- package/dist/runState.d.ts +7 -1
- package/dist/runState.js +204 -151
- package/dist/runState.js.map +1 -1
- package/dist/runState.mjs +10 -1
- package/dist/runState.mjs.map +1 -1
- package/dist/shims/interface.js +2 -1
- package/dist/shims/mcp-server/browser.js +10 -4
- package/dist/shims/mcp-server/browser.js.map +1 -1
- package/dist/shims/mcp-server/node.js +67 -25
- package/dist/shims/mcp-server/node.js.map +1 -1
- package/dist/shims/shims-browser.js +25 -13
- package/dist/shims/shims-browser.js.map +1 -1
- package/dist/shims/shims-node.js +72 -15
- package/dist/shims/shims-node.js.map +1 -1
- package/dist/shims/shims-node.mjs +11 -3
- package/dist/shims/shims-node.mjs.map +1 -1
- package/dist/shims/shims-workerd.js +77 -18
- package/dist/shims/shims-workerd.js.map +1 -1
- package/dist/shims/shims-workerd.mjs +11 -3
- package/dist/shims/shims-workerd.mjs.map +1 -1
- package/dist/shims/shims.js +17 -1
- package/dist/shims/shims.js.map +1 -1
- package/dist/tool.d.ts +11 -4
- package/dist/tool.js +121 -54
- package/dist/tool.js.map +1 -1
- package/dist/tool.mjs +84 -25
- package/dist/tool.mjs.map +1 -1
- package/dist/tracing/context.js +25 -14
- package/dist/tracing/context.js.map +1 -1
- package/dist/tracing/createSpans.js +52 -38
- package/dist/tracing/createSpans.js.map +1 -1
- package/dist/tracing/index.js +51 -15
- package/dist/tracing/index.js.map +1 -1
- package/dist/tracing/processor.js +32 -21
- package/dist/tracing/processor.js.map +1 -1
- package/dist/tracing/processor.mjs +1 -1
- package/dist/tracing/processor.mjs.map +1 -1
- package/dist/tracing/provider.js +53 -45
- package/dist/tracing/provider.js.map +1 -1
- package/dist/tracing/spans.js +18 -10
- package/dist/tracing/spans.js.map +1 -1
- package/dist/tracing/traces.js +11 -6
- package/dist/tracing/traces.js.map +1 -1
- package/dist/tracing/utils.js +16 -9
- package/dist/tracing/utils.js.map +1 -1
- package/dist/types/aliases.js +2 -1
- package/dist/types/helpers.d.ts +1 -1
- package/dist/types/helpers.js +2 -1
- package/dist/types/index.js +44 -5
- package/dist/types/index.js.map +1 -1
- package/dist/types/protocol.d.ts +1 -1
- package/dist/types/protocol.js +188 -185
- package/dist/types/protocol.js.map +1 -1
- package/dist/types/protocol.mjs +1 -1
- package/dist/types/protocol.mjs.map +1 -1
- package/dist/types/providerData.d.ts +11 -3
- package/dist/types/providerData.js +2 -1
- package/dist/usage.js +7 -3
- package/dist/usage.js.map +1 -1
- package/dist/utils/index.js +9 -3
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/messages.js +6 -2
- package/dist/utils/messages.js.map +1 -1
- package/dist/utils/safeExecute.js +4 -1
- package/dist/utils/safeExecute.js.map +1 -1
- package/dist/utils/serialize.js +6 -2
- package/dist/utils/serialize.js.map +1 -1
- package/dist/utils/smartString.js +4 -1
- package/dist/utils/smartString.js.map +1 -1
- package/dist/utils/tools.js +16 -11
- package/dist/utils/tools.js.map +1 -1
- package/dist/utils/typeGuards.d.ts +1 -1
- package/dist/utils/typeGuards.js +6 -2
- package/dist/utils/typeGuards.js.map +1 -1
- package/package.json +24 -43
package/dist/shims/shims-node.js
CHANGED
|
@@ -1,29 +1,86 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.timer = exports.MCPServerSSE = exports.MCPServerStreamableHttp = exports.MCPServerStdio = exports.AsyncLocalStorage = exports.TransformStream = exports.ReadableStream = exports.Readable = exports.randomUUID = exports.RuntimeEventEmitter = void 0;
|
|
37
|
+
exports.loadEnv = loadEnv;
|
|
38
|
+
exports.isTracingLoopRunningByDefault = isTracingLoopRunningByDefault;
|
|
39
|
+
exports.isBrowserEnvironment = isBrowserEnvironment;
|
|
40
|
+
const process = __importStar(require("node:process"));
|
|
41
|
+
var node_events_1 = require("node:events");
|
|
42
|
+
Object.defineProperty(exports, "RuntimeEventEmitter", { enumerable: true, get: function () { return node_events_1.EventEmitter; } });
|
|
3
43
|
// Use function instead of exporting the value to prevent
|
|
4
44
|
// circular dependency resolution issues caused by other exports in '@openai/agents-core/_shims'
|
|
5
|
-
|
|
45
|
+
function loadEnv() {
|
|
6
46
|
if (typeof process === 'undefined' || typeof process.env === 'undefined') {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
47
|
+
// In CommonJS builds, import.meta is not available, so we return empty object
|
|
48
|
+
try {
|
|
49
|
+
// Use eval to avoid TypeScript compilation errors in CommonJS builds
|
|
50
|
+
const importMeta = (0, eval)('import.meta');
|
|
51
|
+
if (typeof importMeta === 'object' &&
|
|
52
|
+
typeof importMeta.env === 'object') {
|
|
53
|
+
return importMeta.env;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch {
|
|
57
|
+
// import.meta not available (CommonJS build)
|
|
10
58
|
}
|
|
11
59
|
return {};
|
|
12
60
|
}
|
|
13
61
|
return process.env;
|
|
14
62
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
63
|
+
var node_crypto_1 = require("node:crypto");
|
|
64
|
+
Object.defineProperty(exports, "randomUUID", { enumerable: true, get: function () { return node_crypto_1.randomUUID; } });
|
|
65
|
+
var node_stream_1 = require("node:stream");
|
|
66
|
+
Object.defineProperty(exports, "Readable", { enumerable: true, get: function () { return node_stream_1.Readable; } });
|
|
67
|
+
var web_1 = require("node:stream/web");
|
|
68
|
+
Object.defineProperty(exports, "ReadableStream", { enumerable: true, get: function () { return web_1.ReadableStream; } });
|
|
69
|
+
Object.defineProperty(exports, "TransformStream", { enumerable: true, get: function () { return web_1.TransformStream; } });
|
|
70
|
+
var node_async_hooks_1 = require("node:async_hooks");
|
|
71
|
+
Object.defineProperty(exports, "AsyncLocalStorage", { enumerable: true, get: function () { return node_async_hooks_1.AsyncLocalStorage; } });
|
|
72
|
+
function isTracingLoopRunningByDefault() {
|
|
20
73
|
return true;
|
|
21
74
|
}
|
|
22
|
-
|
|
75
|
+
function isBrowserEnvironment() {
|
|
23
76
|
return false;
|
|
24
77
|
}
|
|
25
|
-
|
|
26
|
-
|
|
78
|
+
var node_1 = require("./mcp-server/node.js");
|
|
79
|
+
Object.defineProperty(exports, "MCPServerStdio", { enumerable: true, get: function () { return node_1.NodeMCPServerStdio; } });
|
|
80
|
+
Object.defineProperty(exports, "MCPServerStreamableHttp", { enumerable: true, get: function () { return node_1.NodeMCPServerStreamableHttp; } });
|
|
81
|
+
Object.defineProperty(exports, "MCPServerSSE", { enumerable: true, get: function () { return node_1.NodeMCPServerSSE; } });
|
|
82
|
+
var node_timers_1 = require("node:timers");
|
|
83
|
+
Object.defineProperty(exports, "clearTimeout", { enumerable: true, get: function () { return node_timers_1.clearTimeout; } });
|
|
27
84
|
class NodeTimer {
|
|
28
85
|
constructor() { }
|
|
29
86
|
setTimeout(callback, ms) {
|
|
@@ -34,5 +91,5 @@ class NodeTimer {
|
|
|
34
91
|
}
|
|
35
92
|
}
|
|
36
93
|
const timer = new NodeTimer();
|
|
37
|
-
|
|
94
|
+
exports.timer = timer;
|
|
38
95
|
//# sourceMappingURL=shims-node.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shims-node.js","sourceRoot":"","sources":["../../src/shims/shims-node.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shims-node.js","sourceRoot":"","sources":["../../src/shims/shims-node.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;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C,CAAC;IAClC,CAAC;IACD,YAAY,CAAC,SAAgD;QAC3D,YAAY,CAAC,SAA2B,CAAC,CAAC;IAC5C,CAAC;CACF;AACD,MAAM,KAAK,GAAG,IAAI,SAAS,EAAE,CAAC;AACrB,sBAAK"}
|
|
@@ -4,9 +4,17 @@ export { EventEmitter as RuntimeEventEmitter } from 'node:events';
|
|
|
4
4
|
// circular dependency resolution issues caused by other exports in '@openai/agents-core/_shims'
|
|
5
5
|
export function loadEnv() {
|
|
6
6
|
if (typeof process === 'undefined' || typeof process.env === 'undefined') {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
// In CommonJS builds, import.meta is not available, so we return empty object
|
|
8
|
+
try {
|
|
9
|
+
// Use eval to avoid TypeScript compilation errors in CommonJS builds
|
|
10
|
+
const importMeta = (0, eval)('import.meta');
|
|
11
|
+
if (typeof importMeta === 'object' &&
|
|
12
|
+
typeof importMeta.env === 'object') {
|
|
13
|
+
return importMeta.env;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
catch {
|
|
17
|
+
// import.meta not available (CommonJS build)
|
|
10
18
|
}
|
|
11
19
|
return {};
|
|
12
20
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shims-node.mjs","sourceRoot":"","sources":["../../src/shims/shims-node.ts"],"names":[],"mappings":"OAAO,KAAK,OAAO,MAAM,cAAc;OAIhC,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,aAAa;AAQjE,yDAAyD;AACzD,gGAAgG;AAChG,MAAM,UAAU,OAAO;IACrB,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,OAAO,CAAC,GAAG,KAAK,WAAW,EAAE,CAAC;QACzE,
|
|
1
|
+
{"version":3,"file":"shims-node.mjs","sourceRoot":"","sources":["../../src/shims/shims-node.ts"],"names":[],"mappings":"OAAO,KAAK,OAAO,MAAM,cAAc;OAIhC,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,aAA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,CAAC;AAC9B,OAAO,EAAE,KAAK,EAAE,CAAC"}
|
|
@@ -1,39 +1,98 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.timer = exports.MCPServerSSE = exports.MCPServerStreamableHttp = exports.MCPServerStdio = exports.AsyncLocalStorage = exports.TransformStream = exports.ReadableStreamController = exports.ReadableStream = exports.Readable = exports.randomUUID = exports.RuntimeEventEmitter = void 0;
|
|
37
|
+
exports.loadEnv = loadEnv;
|
|
38
|
+
exports.isBrowserEnvironment = isBrowserEnvironment;
|
|
39
|
+
exports.isTracingLoopRunningByDefault = isTracingLoopRunningByDefault;
|
|
40
|
+
const process = __importStar(require("node:process"));
|
|
41
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
42
|
+
var node_events_1 = require("node:events");
|
|
43
|
+
Object.defineProperty(exports, "RuntimeEventEmitter", { enumerable: true, get: function () { return node_events_1.EventEmitter; } });
|
|
4
44
|
// Use function instead of exporting the value to prevent
|
|
5
45
|
// circular dependency resolution issues caused by other exports in '@openai/agents-core/_shims'
|
|
6
|
-
|
|
46
|
+
function loadEnv() {
|
|
7
47
|
if (typeof process === 'undefined' || typeof process.env === 'undefined') {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
48
|
+
// In CommonJS builds, import.meta is not available, so we return empty object
|
|
49
|
+
try {
|
|
50
|
+
// Use eval to avoid TypeScript compilation errors in CommonJS builds
|
|
51
|
+
const importMeta = (0, eval)('import.meta');
|
|
52
|
+
if (typeof importMeta === 'object' &&
|
|
53
|
+
typeof importMeta.env === 'object') {
|
|
54
|
+
return importMeta.env;
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch {
|
|
58
|
+
// import.meta not available (CommonJS build)
|
|
11
59
|
}
|
|
12
60
|
return {};
|
|
13
61
|
}
|
|
14
62
|
return process.env;
|
|
15
63
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
64
|
+
var node_crypto_1 = require("node:crypto");
|
|
65
|
+
Object.defineProperty(exports, "randomUUID", { enumerable: true, get: function () { return node_crypto_1.randomUUID; } });
|
|
66
|
+
var node_stream_1 = require("node:stream");
|
|
67
|
+
Object.defineProperty(exports, "Readable", { enumerable: true, get: function () { return node_stream_1.Readable; } });
|
|
68
|
+
exports.ReadableStream = globalThis.ReadableStream;
|
|
69
|
+
exports.ReadableStreamController = globalThis.ReadableStreamDefaultController;
|
|
70
|
+
exports.TransformStream = globalThis.TransformStream;
|
|
71
|
+
class AsyncLocalStorage extends node_async_hooks_1.AsyncLocalStorage {
|
|
22
72
|
enterWith(context) {
|
|
23
73
|
// Cloudflare workers does not support enterWith, so we need to use run instead
|
|
24
74
|
super.run(context, () => { });
|
|
25
75
|
}
|
|
26
76
|
}
|
|
27
|
-
|
|
77
|
+
exports.AsyncLocalStorage = AsyncLocalStorage;
|
|
78
|
+
function isBrowserEnvironment() {
|
|
28
79
|
return false;
|
|
29
80
|
}
|
|
30
|
-
|
|
81
|
+
function isTracingLoopRunningByDefault() {
|
|
31
82
|
// Cloudflare workers does not support triggering things like setTimeout outside of the
|
|
32
83
|
// request context. So we don't run the trace export loop by default.
|
|
33
84
|
return false;
|
|
34
85
|
}
|
|
35
|
-
|
|
36
|
-
|
|
86
|
+
/**
|
|
87
|
+
* Right now Cloudflare Workers does not support MCP
|
|
88
|
+
*/
|
|
89
|
+
var browser_1 = require("./mcp-server/browser.js");
|
|
90
|
+
Object.defineProperty(exports, "MCPServerStdio", { enumerable: true, get: function () { return browser_1.MCPServerStdio; } });
|
|
91
|
+
Object.defineProperty(exports, "MCPServerStreamableHttp", { enumerable: true, get: function () { return browser_1.MCPServerStreamableHttp; } });
|
|
92
|
+
Object.defineProperty(exports, "MCPServerSSE", { enumerable: true, get: function () { return browser_1.MCPServerSSE; } });
|
|
93
|
+
var node_timers_1 = require("node:timers");
|
|
94
|
+
Object.defineProperty(exports, "clearTimeout", { enumerable: true, get: function () { return node_timers_1.clearTimeout; } });
|
|
95
|
+
Object.defineProperty(exports, "setTimeout", { enumerable: true, get: function () { return node_timers_1.setTimeout; } });
|
|
37
96
|
class NodeTimer {
|
|
38
97
|
constructor() { }
|
|
39
98
|
setTimeout(callback, ms) {
|
|
@@ -44,5 +103,5 @@ class NodeTimer {
|
|
|
44
103
|
}
|
|
45
104
|
}
|
|
46
105
|
const timer = new NodeTimer();
|
|
47
|
-
|
|
106
|
+
exports.timer = timer;
|
|
48
107
|
//# sourceMappingURL=shims-workerd.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shims-workerd.js","sourceRoot":"","sources":["../../src/shims/shims-workerd.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"shims-workerd.js","sourceRoot":"","sources":["../../src/shims/shims-workerd.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAeA,0BAkBC;AAiBD,oDAEC;AAED,sEAIC;AA1DD,sDAAwC;AACxC,uDAAiF;AACjF,2CAAkE;AAAzD,kHAAA,YAAY,OAAuB;AAW5C,yDAAyD;AACzD,gGAAgG;AAChG,SAAgB,OAAO;IACrB,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,OAAO,CAAC,GAAG,KAAK,WAAW,EAAE,CAAC;QACzE,8EAA8E;QAC9E,IAAI,CAAC;YACH,qEAAqE;YACrE,MAAM,UAAU,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,aAAa,CAAC,CAAC;YAC5C,IACE,OAAO,UAAU,KAAK,QAAQ;gBAC9B,OAAO,UAAU,CAAC,GAAG,KAAK,QAAQ,EAClC,CAAC;gBACD,OAAO,UAAU,CAAC,GAAoD,CAAC;YACzE,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,6CAA6C;QAC/C,CAAC;QACD,OAAO,EAAE,CAAC;IACZ,CAAC;IACD,OAAO,OAAO,CAAC,GAAG,CAAC;AACrB,CAAC;AAED,2CAAyC;AAAhC,yGAAA,UAAU,OAAA;AACnB,2CAAuC;AAA9B,uGAAA,QAAQ,OAAA;AAEJ,QAAA,cAAc,GAAG,UAAU,CAAC,cAAc,CAAC;AAC3C,QAAA,wBAAwB,GACnC,UAAU,CAAC,+BAA+B,CAAC;AAChC,QAAA,eAAe,GAAG,UAAU,CAAC,eAAe,CAAC;AAE1D,MAAa,iBAAqB,SAAQ,oCAA2B;IACnE,SAAS,CAAC,OAAU;QAClB,+EAA+E;QAC/E,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAC/B,CAAC;CACF;AALD,8CAKC;AAED,SAAgB,oBAAoB;IAClC,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAgB,6BAA6B;IAC3C,uFAAuF;IACvF,qEAAqE;IACrE,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;GAEG;AACH,mDAI8B;AAH5B,yGAAA,cAAc,OAAA;AACd,kHAAA,uBAAuB,OAAA;AACvB,uGAAA,YAAY,OAAA;AAGd,2CAAuD;AAA9C,2GAAA,YAAY,OAAA;AAAE,yGAAA,UAAU,OAAA;AAEjC,MAAM,SAAS;IACb,gBAAe,CAAC;IAChB,UAAU,CAAC,QAAmB,EAAE,EAAU;QACxC,OAAO,UAAU,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC;IAClC,CAAC;IACD,YAAY,CAAC,SAAgD;QAC3D,YAAY,CAAC,SAA2B,CAAC,CAAC;IAC5C,CAAC;CACF;AACD,MAAM,KAAK,GAAG,IAAI,SAAS,EAAE,CAAC;AACrB,sBAAK"}
|
|
@@ -5,9 +5,17 @@ export { EventEmitter as RuntimeEventEmitter } from 'node:events';
|
|
|
5
5
|
// circular dependency resolution issues caused by other exports in '@openai/agents-core/_shims'
|
|
6
6
|
export function loadEnv() {
|
|
7
7
|
if (typeof process === 'undefined' || typeof process.env === 'undefined') {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
// In CommonJS builds, import.meta is not available, so we return empty object
|
|
9
|
+
try {
|
|
10
|
+
// Use eval to avoid TypeScript compilation errors in CommonJS builds
|
|
11
|
+
const importMeta = (0, eval)('import.meta');
|
|
12
|
+
if (typeof importMeta === 'object' &&
|
|
13
|
+
typeof importMeta.env === 'object') {
|
|
14
|
+
return importMeta.env;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
catch {
|
|
18
|
+
// import.meta not available (CommonJS build)
|
|
11
19
|
}
|
|
12
20
|
return {};
|
|
13
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shims-workerd.mjs","sourceRoot":"","sources":["../../src/shims/shims-workerd.ts"],"names":[],"mappings":"OAAO,KAAK,OAAO,MAAM,cAAc;OAChC,EAAE,iBAAiB,IAAI,wBAAwB,EAAE,MAAM,kBAAkB;OACzE,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,aAAa;AAWjE,yDAAyD;AACzD,gGAAgG;AAChG,MAAM,UAAU,OAAO;IACrB,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,OAAO,CAAC,GAAG,KAAK,WAAW,EAAE,CAAC;QACzE,
|
|
1
|
+
{"version":3,"file":"shims-workerd.mjs","sourceRoot":"","sources":["../../src/shims/shims-workerd.ts"],"names":[],"mappings":"OAAO,KAAK,OAAO,MAAM,cAAc;OAChC,EAAE,iBAAiB,IAAI,wBAAwB,EAAE,MAAM,kBAAkB;OACzE,EAAE,YAAY,IAAI,mBAAmB,EAAE,MAAM,aAAa;AAWjE,yDAAyD;AACzD,gGAAgG;AAChG,MAAM,UAAU,OAAO;IACrB,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,OAAO,CAAC,GAAG,KAAK,WAAW,EAAE,CAAC;QACzE,8EAA8E;QAC9E,IAAI,CAAC;YACH,qEAAqE;YACrE,MAAM,UAAU,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,aAAa,CAAC,CAAC;YAC5C,IACE,OAAO,UAAU,KAAK,QAAQ;gBAC9B,OAAO,UAAU,CAAC,GAAG,KAAK,QAAQ,EAClC,CAAC;gBACD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
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./shims-node.js"), exports);
|
|
2
18
|
//# sourceMappingURL=shims.js.map
|
package/dist/shims/shims.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shims.js","sourceRoot":"","sources":["../../src/shims/shims.ts"],"names":[],"mappings":""}
|
|
1
|
+
{"version":3,"file":"shims.js","sourceRoot":"","sources":["../../src/shims/shims.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,kDAA6B"}
|
package/dist/tool.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Computer } from './computer';
|
|
2
|
-
import type { infer as zInfer, ZodObject } from 'zod
|
|
2
|
+
import type { infer as zInfer, ZodObject } from 'zod';
|
|
3
3
|
import { JsonObjectSchema, JsonObjectSchemaNonStrict, JsonObjectSchemaStrict, UnknownContext } from './types';
|
|
4
4
|
import { RunContext } from './runContext';
|
|
5
5
|
import { RunToolApprovalItem, RunToolCallOutputItem } from './items';
|
|
@@ -93,13 +93,20 @@ export type HostedMCPTool<Context = UnknownContext> = HostedTool & {
|
|
|
93
93
|
* @param requireApproval - Whether tool calls require approval.
|
|
94
94
|
*/
|
|
95
95
|
export declare function hostedMcpTool<Context = UnknownContext>(options: {
|
|
96
|
-
serverLabel: string;
|
|
97
|
-
serverUrl: string;
|
|
98
96
|
allowedTools?: string[] | {
|
|
99
97
|
toolNames?: string[];
|
|
100
98
|
};
|
|
101
|
-
headers?: Record<string, string>;
|
|
102
99
|
} & ({
|
|
100
|
+
serverLabel: string;
|
|
101
|
+
serverUrl?: string;
|
|
102
|
+
authorization?: string;
|
|
103
|
+
headers?: Record<string, string>;
|
|
104
|
+
} | {
|
|
105
|
+
serverLabel: string;
|
|
106
|
+
connectorId: string;
|
|
107
|
+
authorization?: string;
|
|
108
|
+
headers?: Record<string, string>;
|
|
109
|
+
}) & ({
|
|
103
110
|
requireApproval?: never;
|
|
104
111
|
} | {
|
|
105
112
|
requireApproval: 'never';
|
package/dist/tool.js
CHANGED
|
@@ -1,18 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.computerTool = computerTool;
|
|
7
|
+
exports.hostedMcpTool = hostedMcpTool;
|
|
8
|
+
exports.tool = tool;
|
|
9
|
+
const safeExecute_1 = require("./utils/safeExecute.js");
|
|
10
|
+
const tools_1 = require("./utils/tools.js");
|
|
11
|
+
const tools_2 = require("./utils/tools.js");
|
|
12
|
+
const typeGuards_1 = require("./utils/typeGuards.js");
|
|
13
|
+
const errors_1 = require("./errors.js");
|
|
14
|
+
const logger_1 = __importDefault(require("./logger.js"));
|
|
15
|
+
const tracing_1 = require("./tracing/index.js");
|
|
16
|
+
const smartString_1 = require("./utils/smartString.js");
|
|
9
17
|
/**
|
|
10
18
|
* Exposes a computer to the agent as a tool to be called
|
|
11
19
|
*
|
|
12
20
|
* @param options Additional configuration for the computer tool like specifying the location of your agent
|
|
13
21
|
* @returns a computer tool definition
|
|
14
22
|
*/
|
|
15
|
-
|
|
23
|
+
function computerTool(options) {
|
|
16
24
|
return {
|
|
17
25
|
type: 'computer',
|
|
18
26
|
name: options.name ?? 'computer_use_preview',
|
|
@@ -26,33 +34,92 @@ export function computerTool(options) {
|
|
|
26
34
|
* @param serverUrl - The URL of the MCP server.
|
|
27
35
|
* @param requireApproval - Whether tool calls require approval.
|
|
28
36
|
*/
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
:
|
|
49
|
-
|
|
37
|
+
function hostedMcpTool(options) {
|
|
38
|
+
if ('serverUrl' in options) {
|
|
39
|
+
// the MCP servers comaptible with the specification
|
|
40
|
+
const providerData = typeof options.requireApproval === 'undefined' ||
|
|
41
|
+
options.requireApproval === 'never'
|
|
42
|
+
? {
|
|
43
|
+
type: 'mcp',
|
|
44
|
+
server_label: options.serverLabel,
|
|
45
|
+
server_url: options.serverUrl,
|
|
46
|
+
require_approval: 'never',
|
|
47
|
+
allowed_tools: toMcpAllowedToolsFilter(options.allowedTools),
|
|
48
|
+
headers: options.headers,
|
|
49
|
+
}
|
|
50
|
+
: {
|
|
51
|
+
type: 'mcp',
|
|
52
|
+
server_label: options.serverLabel,
|
|
53
|
+
server_url: options.serverUrl,
|
|
54
|
+
allowed_tools: toMcpAllowedToolsFilter(options.allowedTools),
|
|
55
|
+
headers: options.headers,
|
|
56
|
+
require_approval: typeof options.requireApproval === 'string'
|
|
57
|
+
? 'always'
|
|
58
|
+
: buildRequireApproval(options.requireApproval),
|
|
59
|
+
on_approval: options.onApproval,
|
|
60
|
+
};
|
|
61
|
+
return {
|
|
62
|
+
type: 'hosted_tool',
|
|
63
|
+
name: 'hosted_mcp',
|
|
64
|
+
providerData,
|
|
50
65
|
};
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
providerData
|
|
55
|
-
|
|
66
|
+
}
|
|
67
|
+
else if ('connectorId' in options) {
|
|
68
|
+
// OpenAI's connectors
|
|
69
|
+
const providerData = typeof options.requireApproval === 'undefined' ||
|
|
70
|
+
options.requireApproval === 'never'
|
|
71
|
+
? {
|
|
72
|
+
type: 'mcp',
|
|
73
|
+
server_label: options.serverLabel,
|
|
74
|
+
connector_id: options.connectorId,
|
|
75
|
+
authorization: options.authorization,
|
|
76
|
+
require_approval: 'never',
|
|
77
|
+
allowed_tools: toMcpAllowedToolsFilter(options.allowedTools),
|
|
78
|
+
headers: options.headers,
|
|
79
|
+
}
|
|
80
|
+
: {
|
|
81
|
+
type: 'mcp',
|
|
82
|
+
server_label: options.serverLabel,
|
|
83
|
+
connector_id: options.connectorId,
|
|
84
|
+
authorization: options.authorization,
|
|
85
|
+
allowed_tools: toMcpAllowedToolsFilter(options.allowedTools),
|
|
86
|
+
headers: options.headers,
|
|
87
|
+
require_approval: typeof options.requireApproval === 'string'
|
|
88
|
+
? 'always'
|
|
89
|
+
: buildRequireApproval(options.requireApproval),
|
|
90
|
+
on_approval: options.onApproval,
|
|
91
|
+
};
|
|
92
|
+
return {
|
|
93
|
+
type: 'hosted_tool',
|
|
94
|
+
name: 'hosted_mcp',
|
|
95
|
+
providerData,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
else {
|
|
99
|
+
// the MCP servers comaptible with the specification
|
|
100
|
+
const providerData = typeof options.requireApproval === 'undefined' ||
|
|
101
|
+
options.requireApproval === 'never'
|
|
102
|
+
? {
|
|
103
|
+
type: 'mcp',
|
|
104
|
+
server_label: options.serverLabel,
|
|
105
|
+
require_approval: 'never',
|
|
106
|
+
allowed_tools: toMcpAllowedToolsFilter(options.allowedTools),
|
|
107
|
+
}
|
|
108
|
+
: {
|
|
109
|
+
type: 'mcp',
|
|
110
|
+
server_label: options.serverLabel,
|
|
111
|
+
allowed_tools: toMcpAllowedToolsFilter(options.allowedTools),
|
|
112
|
+
require_approval: typeof options.requireApproval === 'string'
|
|
113
|
+
? 'always'
|
|
114
|
+
: buildRequireApproval(options.requireApproval),
|
|
115
|
+
on_approval: options.onApproval,
|
|
116
|
+
};
|
|
117
|
+
return {
|
|
118
|
+
type: 'hosted_tool',
|
|
119
|
+
name: 'hosted_mcp',
|
|
120
|
+
providerData,
|
|
121
|
+
};
|
|
122
|
+
}
|
|
56
123
|
}
|
|
57
124
|
/**
|
|
58
125
|
* The default function to invoke when an error occurs while running the tool.
|
|
@@ -72,10 +139,10 @@ function defaultToolErrorFunction(context, error) {
|
|
|
72
139
|
* @param options The options for the tool
|
|
73
140
|
* @returns A new tool
|
|
74
141
|
*/
|
|
75
|
-
|
|
142
|
+
function tool(options) {
|
|
76
143
|
const name = options.name
|
|
77
|
-
? toFunctionToolName(options.name)
|
|
78
|
-
: toFunctionToolName(options.execute.name);
|
|
144
|
+
? (0, tools_1.toFunctionToolName)(options.name)
|
|
145
|
+
: (0, tools_1.toFunctionToolName)(options.execute.name);
|
|
79
146
|
const toolErrorFunction = typeof options.errorFunction === 'undefined'
|
|
80
147
|
? defaultToolErrorFunction
|
|
81
148
|
: options.errorFunction;
|
|
@@ -83,41 +150,41 @@ export function tool(options) {
|
|
|
83
150
|
throw new Error('Tool name cannot be empty. Either name your function or provide a name in the options.');
|
|
84
151
|
}
|
|
85
152
|
const strictMode = options.strict ?? true;
|
|
86
|
-
if (!strictMode && isZodObject(options.parameters)) {
|
|
87
|
-
throw new UserError('Strict mode is required for Zod parameters');
|
|
153
|
+
if (!strictMode && (0, typeGuards_1.isZodObject)(options.parameters)) {
|
|
154
|
+
throw new errors_1.UserError('Strict mode is required for Zod parameters');
|
|
88
155
|
}
|
|
89
|
-
const { parser, schema: parameters } = getSchemaAndParserFromInputType(options.parameters, name);
|
|
156
|
+
const { parser, schema: parameters } = (0, tools_2.getSchemaAndParserFromInputType)(options.parameters, name);
|
|
90
157
|
async function _invoke(runContext, input) {
|
|
91
|
-
const [error, parsed] = await safeExecute(() => parser(input));
|
|
158
|
+
const [error, parsed] = await (0, safeExecute_1.safeExecute)(() => parser(input));
|
|
92
159
|
if (error !== null) {
|
|
93
|
-
if (
|
|
94
|
-
|
|
160
|
+
if (logger_1.default.dontLogToolData) {
|
|
161
|
+
logger_1.default.debug(`Invalid JSON input for tool ${name}`);
|
|
95
162
|
}
|
|
96
163
|
else {
|
|
97
|
-
|
|
164
|
+
logger_1.default.debug(`Invalid JSON input for tool ${name}: ${input}`);
|
|
98
165
|
}
|
|
99
|
-
throw new ModelBehaviorError('Invalid JSON input for tool');
|
|
166
|
+
throw new errors_1.ModelBehaviorError('Invalid JSON input for tool');
|
|
100
167
|
}
|
|
101
|
-
if (
|
|
102
|
-
|
|
168
|
+
if (logger_1.default.dontLogToolData) {
|
|
169
|
+
logger_1.default.debug(`Invoking tool ${name}`);
|
|
103
170
|
}
|
|
104
171
|
else {
|
|
105
|
-
|
|
172
|
+
logger_1.default.debug(`Invoking tool ${name} with input ${input}`);
|
|
106
173
|
}
|
|
107
174
|
const result = await options.execute(parsed, runContext);
|
|
108
|
-
const stringResult = toSmartString(result);
|
|
109
|
-
if (
|
|
110
|
-
|
|
175
|
+
const stringResult = (0, smartString_1.toSmartString)(result);
|
|
176
|
+
if (logger_1.default.dontLogToolData) {
|
|
177
|
+
logger_1.default.debug(`Tool ${name} completed`);
|
|
111
178
|
}
|
|
112
179
|
else {
|
|
113
|
-
|
|
180
|
+
logger_1.default.debug(`Tool ${name} returned: ${stringResult}`);
|
|
114
181
|
}
|
|
115
182
|
return result;
|
|
116
183
|
}
|
|
117
184
|
async function invoke(runContext, input) {
|
|
118
185
|
return _invoke(runContext, input).catch((error) => {
|
|
119
186
|
if (toolErrorFunction) {
|
|
120
|
-
const currentSpan = getCurrentSpan();
|
|
187
|
+
const currentSpan = (0, tracing_1.getCurrentSpan)();
|
|
121
188
|
currentSpan?.setError({
|
|
122
189
|
message: 'Error running tool (non-fatal)',
|
|
123
190
|
data: {
|
package/dist/tool.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../src/tool.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tool.js","sourceRoot":"","sources":["../src/tool.ts"],"names":[],"mappings":";;;;;AAuGA,oCAQC;AAuBD,sCA0HC;AA+SD,oBAqGC;AA5oBD,wDAAkD;AAClD,4CAAmD;AACnD,4CAAgE;AAChE,sDAAiD;AAEjD,wCAAyD;AACzD,yDAA8B;AAC9B,gDAA2C;AAE3C,wDAAoD;AAgFpD;;;;;GAKG;AACH,SAAgB,YAAY,CAC1B,OAAqE;IAErE,OAAO;QACL,IAAI,EAAE,UAAU;QAChB,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,sBAAsB;QAC5C,QAAQ,EAAE,OAAO,CAAC,QAAQ;KAC3B,CAAC;AACJ,CAAC;AAgBD;;;;;;GAMG;AACH,SAAgB,aAAa,CAC3B,OA8BG;IAEH,IAAI,WAAW,IAAI,OAAO,EAAE,CAAC;QAC3B,oDAAoD;QACpD,MAAM,YAAY,GAChB,OAAO,OAAO,CAAC,eAAe,KAAK,WAAW;YAC9C,OAAO,CAAC,eAAe,KAAK,OAAO;YACjC,CAAC,CAAC;gBACE,IAAI,EAAE,KAAK;gBACX,YAAY,EAAE,OAAO,CAAC,WAAW;gBACjC,UAAU,EAAE,OAAO,CAAC,SAAS;gBAC7B,gBAAgB,EAAE,OAAO;gBACzB,aAAa,EAAE,uBAAuB,CAAC,OAAO,CAAC,YAAY,CAAC;gBAC5D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