@openai/agents-core 0.0.16 → 0.0.17
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 +1 -1
- package/dist/agent.js +29 -22
- package/dist/agent.js.map +1 -1
- package/dist/computer.js +2 -1
- package/dist/config.js +12 -6
- package/dist/config.js.map +1 -1
- 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.js +121 -25
- package/dist/index.js.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 +7 -5
- package/dist/metadata.js.map +1 -1
- package/dist/metadata.mjs +2 -3
- package/dist/metadata.mjs.map +1 -1
- 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.js +106 -95
- package/dist/run.js.map +1 -1
- package/dist/runContext.js +13 -6
- package/dist/runContext.js.map +1 -1
- package/dist/runImplementation.d.ts +1 -1
- package/dist/runImplementation.js +106 -89
- package/dist/runImplementation.js.map +1 -1
- package/dist/runImplementation.mjs +1 -1
- 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 +1 -1
- package/dist/tool.js +37 -29
- package/dist/tool.js.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 +31 -20
- package/dist/tracing/processor.js.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.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 +22 -41
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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAcA,0BAkBC;AAWD,sEAEC;AAED,oDAEC;AAjDD,sDAAwC;AAIxC,2CAAkE;AAAzD,kHAAA,YAAY,OAAuB;AAQ5C,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;AACjB,uCAIyB;AAHvB,qGAAA,cAAc,OAAA;AAEd,sGAAA,eAAe,OAAA;AAEjB,qDAAqD;AAA5C,qHAAA,iBAAiB,OAAA;AAE1B,SAAgB,6BAA6B;IAC3C,OAAO,IAAI,CAAC;AACd,CAAC;AAED,SAAgB,oBAAoB;IAClC,OAAO,KAAK,CAAC;AACf,CAAC;AACD,6CAI2B;AAHzB,sGAAA,kBAAkB,OAAkB;AACpC,+GAAA,2BAA2B,OAA2B;AACtD,oGAAA,gBAAgB,OAAgB;AAGlC,2CAA2C;AAAlC,2GAAA,YAAY,OAAA;AAErB,MAAM,SAAS;IACb,gBAAe,CAAC;IAChB,UAAU,CAAC,QAAoB,EAAE,EAAU;QACzC,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"}
|
|
@@ -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,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,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;OAEM,EAAE,UAAU,EAAE,MAAM,aAAa;OACjC,EAAE,QAAQ,EAAE,MAAM,aAAa;OAC/B,EACL,cAAc,EAEd,eAAe,GAChB,MAAM,iBAAiB;OACjB,EAAE,iBAAiB,EAAE,MAAM,kBAAkB;AAEpD,MAAM,UAAU,6BAA6B;IAC3C,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,oBAAoB;IAClC,OAAO,KAAK,CAAC;AACf,CAAC;OACM,EACL,kBAAkB,IAAI,cAAc,EACpC,2BAA2B,IAAI,uBAAuB,EACtD,gBAAgB,IAAI,YAAY,GACjC;OAEM,EAAE,YAAY,EAAE,MAAM,aAAa;AAE1C,MAAM,SAAS;IACb,gBAAe,CAAC;IAChB,UAAU,CAAC,QAAoB,EAAE,EAAU;QACzC,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;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,s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AA;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,yDAA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AAC,OAAU;QAClB,+EAA+E;QAC/E,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;IAC/B,CAAC;CACF;AAED,MAAM,UAAU,oBAAoB;IAClC,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,UAAU,6BAA6B;IAC3C,uFAAuF;IACvF,qEAAqE;IACrE,OAAO,KAAK,CAAC;AACf,CAAC;OAKM,EACL,cAAc,EACd,uBAAuB,EACvB,YAAY,GACb;OAEM,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,aAAa;AAEtD,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;AAC9B,OAAO,EAAE,KAAK,EAAE,CAAC"}
|
package/dist/shims/shims.js
CHANGED
|
@@ -1,2 +1,18 @@
|
|
|
1
|
-
|
|
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';
|
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,7 +34,7 @@ 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
|
-
|
|
37
|
+
function hostedMcpTool(options) {
|
|
30
38
|
const providerData = typeof options.requireApproval === 'undefined' ||
|
|
31
39
|
options.requireApproval === 'never'
|
|
32
40
|
? {
|
|
@@ -72,10 +80,10 @@ function defaultToolErrorFunction(context, error) {
|
|
|
72
80
|
* @param options The options for the tool
|
|
73
81
|
* @returns A new tool
|
|
74
82
|
*/
|
|
75
|
-
|
|
83
|
+
function tool(options) {
|
|
76
84
|
const name = options.name
|
|
77
|
-
? toFunctionToolName(options.name)
|
|
78
|
-
: toFunctionToolName(options.execute.name);
|
|
85
|
+
? (0, tools_1.toFunctionToolName)(options.name)
|
|
86
|
+
: (0, tools_1.toFunctionToolName)(options.execute.name);
|
|
79
87
|
const toolErrorFunction = typeof options.errorFunction === 'undefined'
|
|
80
88
|
? defaultToolErrorFunction
|
|
81
89
|
: options.errorFunction;
|
|
@@ -83,41 +91,41 @@ export function tool(options) {
|
|
|
83
91
|
throw new Error('Tool name cannot be empty. Either name your function or provide a name in the options.');
|
|
84
92
|
}
|
|
85
93
|
const strictMode = options.strict ?? true;
|
|
86
|
-
if (!strictMode && isZodObject(options.parameters)) {
|
|
87
|
-
throw new UserError('Strict mode is required for Zod parameters');
|
|
94
|
+
if (!strictMode && (0, typeGuards_1.isZodObject)(options.parameters)) {
|
|
95
|
+
throw new errors_1.UserError('Strict mode is required for Zod parameters');
|
|
88
96
|
}
|
|
89
|
-
const { parser, schema: parameters } = getSchemaAndParserFromInputType(options.parameters, name);
|
|
97
|
+
const { parser, schema: parameters } = (0, tools_2.getSchemaAndParserFromInputType)(options.parameters, name);
|
|
90
98
|
async function _invoke(runContext, input) {
|
|
91
|
-
const [error, parsed] = await safeExecute(() => parser(input));
|
|
99
|
+
const [error, parsed] = await (0, safeExecute_1.safeExecute)(() => parser(input));
|
|
92
100
|
if (error !== null) {
|
|
93
|
-
if (
|
|
94
|
-
|
|
101
|
+
if (logger_1.default.dontLogToolData) {
|
|
102
|
+
logger_1.default.debug(`Invalid JSON input for tool ${name}`);
|
|
95
103
|
}
|
|
96
104
|
else {
|
|
97
|
-
|
|
105
|
+
logger_1.default.debug(`Invalid JSON input for tool ${name}: ${input}`);
|
|
98
106
|
}
|
|
99
|
-
throw new ModelBehaviorError('Invalid JSON input for tool');
|
|
107
|
+
throw new errors_1.ModelBehaviorError('Invalid JSON input for tool');
|
|
100
108
|
}
|
|
101
|
-
if (
|
|
102
|
-
|
|
109
|
+
if (logger_1.default.dontLogToolData) {
|
|
110
|
+
logger_1.default.debug(`Invoking tool ${name}`);
|
|
103
111
|
}
|
|
104
112
|
else {
|
|
105
|
-
|
|
113
|
+
logger_1.default.debug(`Invoking tool ${name} with input ${input}`);
|
|
106
114
|
}
|
|
107
115
|
const result = await options.execute(parsed, runContext);
|
|
108
|
-
const stringResult = toSmartString(result);
|
|
109
|
-
if (
|
|
110
|
-
|
|
116
|
+
const stringResult = (0, smartString_1.toSmartString)(result);
|
|
117
|
+
if (logger_1.default.dontLogToolData) {
|
|
118
|
+
logger_1.default.debug(`Tool ${name} completed`);
|
|
111
119
|
}
|
|
112
120
|
else {
|
|
113
|
-
|
|
121
|
+
logger_1.default.debug(`Tool ${name} returned: ${stringResult}`);
|
|
114
122
|
}
|
|
115
123
|
return result;
|
|
116
124
|
}
|
|
117
125
|
async function invoke(runContext, input) {
|
|
118
126
|
return _invoke(runContext, input).catch((error) => {
|
|
119
127
|
if (toolErrorFunction) {
|
|
120
|
-
const currentSpan = getCurrentSpan();
|
|
128
|
+
const currentSpan = (0, tracing_1.getCurrentSpan)();
|
|
121
129
|
currentSpan?.setError({
|
|
122
130
|
message: 'Error running tool (non-fatal)',
|
|
123
131
|
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,sCAgDC;AA+SD,oBAqGC;AAlkBD,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,OAiBC;IAED,MAAM,YAAY,GAChB,OAAO,OAAO,CAAC,eAAe,KAAK,WAAW;QAC9C,OAAO,CAAC,eAAe,KAAK,OAAO;QACjC,CAAC,CAAC;YACE,IAAI,EAAE,KAAK;YACX,YAAY,EAAE,OAAO,CAAC,WAAW;YACjC,UAAU,EAAE,OAAO,CAAC,SAAS;YAC7B,gBAAgB,EAAE,OAAO;YACzB,aAAa,EAA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C,eAG7B;IACC,MAAM,MAAM,GAGR,EAAE,CAAC;IACP,IAAI,eAAe,CAAC,MAAM,EAAE,CAAC;QAC3B,MAAM,CAAC,MAAM,GAAG,EAAE,UAAU,EAAE,eAAe,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;IACnE,CAAC;IACD,IAAI,eAAe,CAAC,KAAK,EAAE,CAAC;QAC1B,MAAM,CAAC,KAAK,GAAG,EAAE,UAAU,EAAE,eAAe,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;IACjE,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,SAAS,uBAAuB,CAC9B,YAA6D;IAE7D,IAAI,OAAO,YAAY,KAAK,WAAW,EAAE,CAAC;QACxC,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,IAAI,KAAK,CAAC,OAAO,CAAC,YAAY,CAAC,EAAE,CAAC;QAChC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC;IACtC,CAAC;IACD,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,SAAS,IAAI,EAAE,EAAE,CAAC;AACvD,CAAC"}
|
package/dist/tracing/context.js
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getCurrentTrace = getCurrentTrace;
|
|
4
|
+
exports.getCurrentSpan = getCurrentSpan;
|
|
5
|
+
exports.withTrace = withTrace;
|
|
6
|
+
exports.getOrCreateTrace = getOrCreateTrace;
|
|
7
|
+
exports.setCurrentSpan = setCurrentSpan;
|
|
8
|
+
exports.resetCurrentSpan = resetCurrentSpan;
|
|
9
|
+
exports.addErrorToCurrentSpan = addErrorToCurrentSpan;
|
|
10
|
+
exports.cloneCurrentContext = cloneCurrentContext;
|
|
11
|
+
exports.withNewSpanContext = withNewSpanContext;
|
|
12
|
+
const _shims_1 = require("@openai/agents-core/_shims");
|
|
13
|
+
const provider_1 = require("./provider.js");
|
|
3
14
|
let _contextAsyncLocalStorage;
|
|
4
15
|
function getContextAsyncLocalStorage() {
|
|
5
|
-
_contextAsyncLocalStorage ??= new AsyncLocalStorage();
|
|
16
|
+
_contextAsyncLocalStorage ??= new _shims_1.AsyncLocalStorage();
|
|
6
17
|
return _contextAsyncLocalStorage;
|
|
7
18
|
}
|
|
8
19
|
/**
|
|
@@ -10,7 +21,7 @@ function getContextAsyncLocalStorage() {
|
|
|
10
21
|
*
|
|
11
22
|
* @returns The current trace or null if there is no trace.
|
|
12
23
|
*/
|
|
13
|
-
|
|
24
|
+
function getCurrentTrace() {
|
|
14
25
|
const currentTrace = getContextAsyncLocalStorage().getStore();
|
|
15
26
|
if (currentTrace?.trace) {
|
|
16
27
|
return currentTrace.trace;
|
|
@@ -22,7 +33,7 @@ export function getCurrentTrace() {
|
|
|
22
33
|
*
|
|
23
34
|
* @returns The current span or null if there is no span.
|
|
24
35
|
*/
|
|
25
|
-
|
|
36
|
+
function getCurrentSpan() {
|
|
26
37
|
const currentSpan = getContextAsyncLocalStorage().getStore();
|
|
27
38
|
if (currentSpan?.span) {
|
|
28
39
|
return currentSpan.span;
|
|
@@ -54,9 +65,9 @@ function _wrapFunctionWithTraceLifecycle(fn) {
|
|
|
54
65
|
* @param fn - The function to run and assign the trace context to.
|
|
55
66
|
* @param options - Options for the creation of the trace
|
|
56
67
|
*/
|
|
57
|
-
|
|
68
|
+
async function withTrace(trace, fn, options = {}) {
|
|
58
69
|
const newTrace = typeof trace === 'string'
|
|
59
|
-
? getGlobalTraceProvider().createTrace({
|
|
70
|
+
? (0, provider_1.getGlobalTraceProvider)().createTrace({
|
|
60
71
|
...options,
|
|
61
72
|
name: trace,
|
|
62
73
|
})
|
|
@@ -71,13 +82,13 @@ export async function withTrace(trace, fn, options = {}) {
|
|
|
71
82
|
* @param fn - The fzunction to run and assign the trace context to.
|
|
72
83
|
* @param options - Options for the creation of the trace
|
|
73
84
|
*/
|
|
74
|
-
|
|
85
|
+
async function getOrCreateTrace(fn, options = {}) {
|
|
75
86
|
const currentTrace = getCurrentTrace();
|
|
76
87
|
if (currentTrace) {
|
|
77
88
|
// if this execution context already has a trace instance in it we just continue
|
|
78
89
|
return await fn();
|
|
79
90
|
}
|
|
80
|
-
const newTrace = getGlobalTraceProvider().createTrace(options);
|
|
91
|
+
const newTrace = (0, provider_1.getGlobalTraceProvider)().createTrace(options);
|
|
81
92
|
return getContextAsyncLocalStorage().run({ trace: newTrace }, _wrapFunctionWithTraceLifecycle(fn));
|
|
82
93
|
}
|
|
83
94
|
/**
|
|
@@ -85,7 +96,7 @@ export async function getOrCreateTrace(fn, options = {}) {
|
|
|
85
96
|
*
|
|
86
97
|
* @param span - The span to set as the current span.
|
|
87
98
|
*/
|
|
88
|
-
|
|
99
|
+
function setCurrentSpan(span) {
|
|
89
100
|
const context = getContextAsyncLocalStorage().getStore();
|
|
90
101
|
if (!context) {
|
|
91
102
|
throw new Error('No existing trace found');
|
|
@@ -97,7 +108,7 @@ export function setCurrentSpan(span) {
|
|
|
97
108
|
context.span = span;
|
|
98
109
|
getContextAsyncLocalStorage().enterWith(context);
|
|
99
110
|
}
|
|
100
|
-
|
|
111
|
+
function resetCurrentSpan() {
|
|
101
112
|
const context = getContextAsyncLocalStorage().getStore();
|
|
102
113
|
if (context) {
|
|
103
114
|
context.span = context.previousSpan;
|
|
@@ -110,7 +121,7 @@ export function resetCurrentSpan() {
|
|
|
110
121
|
*
|
|
111
122
|
* @param spanError - The error to add to the current span.
|
|
112
123
|
*/
|
|
113
|
-
|
|
124
|
+
function addErrorToCurrentSpan(spanError) {
|
|
114
125
|
const currentSpan = getCurrentSpan();
|
|
115
126
|
if (currentSpan) {
|
|
116
127
|
currentSpan.setError(spanError);
|
|
@@ -123,7 +134,7 @@ export function addErrorToCurrentSpan(spanError) {
|
|
|
123
134
|
* @param context - The context to clone.
|
|
124
135
|
* @returns A clone of the context.
|
|
125
136
|
*/
|
|
126
|
-
|
|
137
|
+
function cloneCurrentContext(context) {
|
|
127
138
|
return {
|
|
128
139
|
trace: context.trace?.clone(),
|
|
129
140
|
span: context.span?.clone(),
|
|
@@ -135,7 +146,7 @@ export function cloneCurrentContext(context) {
|
|
|
135
146
|
*
|
|
136
147
|
* @param fn - The function to run with the new span context.
|
|
137
148
|
*/
|
|
138
|
-
|
|
149
|
+
function withNewSpanContext(fn) {
|
|
139
150
|
const currentContext = getContextAsyncLocalStorage().getStore();
|
|
140
151
|
if (!currentContext) {
|
|
141
152
|
throw new Error('No existing trace found');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/tracing/context.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/tracing/context.ts"],"names":[],"mappings":";;AAuBA,0CAOC;AAOD,wCAMC;AA+BD,8BAiBC;AASD,4CAgBC;AAOD,wCAYC;AAED,4CAOC;AAOD,sDAKC;AASD,kDAMC;AAOD,gDASC;AA3LD,uDAA+D;AAE/D,4CAAoD;AASpD,IAAI,yBAAsE,CAAC;AAE3E,SAAS,2BAA2B;IAClC,yBAAyB,KAAK,IAAI,0BAAiB,EAAgB,CAAC;IACpE,OAAO,yBAAyB,CAAC;AACnC,CAAC;AAED;;;;GAIG;AACH,SAAgB,eAAe;IAC7B,MAAM,YAAY,GAAG,2BAA2B,EAAE,CAAC,QAAQ,EAAE,CAAC;IAC9D,IAAI,YAAY,EAAE,KAAK,EAAE,CAAC;QACxB,OAAO,YAAY,CAAC,KAAK,CAAC;IAC5B,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;GAIG;AACH,SAAgB,cAAc;IAC5B,MAAM,WAAW,GAAG,2BAA2B,EAAE,CAAC,QAAQ,EAAE,CAAC;IAC7D,IAAI,WAAW,EAAE,IAAI,EAAE,CAAC;QACtB,OAAO,WAAW,CAAC,IAAI,CAAC;IAC1B,CAAC;IACD,OAAO,IAAI,CAAC;A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