@openai/agents-core 0.0.15 → 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 +34 -22
- package/dist/agent.js.map +1 -1
- package/dist/agent.mjs +6 -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/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 -1
- package/dist/index.js +121 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/items.d.ts +0 -32
- 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 +14 -7
- package/dist/mcp.js +119 -96
- package/dist/mcp.js.map +1 -1
- package/dist/mcp.mjs +65 -57
- 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 -186
- 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 +68 -25
- package/dist/shims/mcp-server/node.js.map +1 -1
- package/dist/shims/mcp-server/node.mjs +1 -0
- package/dist/shims/mcp-server/node.mjs.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.d.ts +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 +12 -4
- 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 -221
- package/dist/types/protocol.js +188 -186
- package/dist/types/protocol.js.map +1 -1
- package/dist/types/protocol.mjs +1 -2
- package/dist/types/protocol.mjs.map +1 -1
- package/dist/types/providerData.js +2 -1
- package/dist/usage.d.ts +10 -3
- package/dist/usage.js +16 -10
- package/dist/usage.js.map +1 -1
- package/dist/usage.mjs +9 -7
- package/dist/usage.mjs.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 +23 -42
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,CAA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AAC;QAChB,WAAW,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;AACH,CAAC;AAED;;;;;;GAMG;AACH,SAAgB,mBAAmB,CAAC,OAAqB;IACvD,OAAO;QACL,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,KAAK,EAAE;QAC7B,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE;QAC3B,YAAY,EAAE,OAAO,CAAC,YAAY,EAAE,KAAK,EAAE;KAC5C,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,SAAgB,kBAAkB,CAAI,EAAoB;IACxD,MAAM,cAAc,GAAG,2BAA2B,EAAE,CAAC,QAAQ,EAAE,CAAC;IAChE,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC7C,CAAC;IAED,MAAM,aAAa,GAAG,mBAAmB,CAAC,cAAc,CAAC,CAAC;IAE1D,OAAO,2BAA2B,EAAE,CAAC,GAAG,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;AAC9D,CAAC"}
|
|
@@ -1,11 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withMCPListToolsSpan = exports.withSpeechGroupSpan = exports.withSpeechSpan = exports.withTranscriptionSpan = exports.withGuardrailSpan = exports.withCustomSpan = exports.withGenerationSpan = exports.withHandoffSpan = exports.withFunctionSpan = exports.withAgentSpan = exports.withResponseSpan = void 0;
|
|
4
|
+
exports.createResponseSpan = createResponseSpan;
|
|
5
|
+
exports.createAgentSpan = createAgentSpan;
|
|
6
|
+
exports.createFunctionSpan = createFunctionSpan;
|
|
7
|
+
exports.createHandoffSpan = createHandoffSpan;
|
|
8
|
+
exports.createGenerationSpan = createGenerationSpan;
|
|
9
|
+
exports.createCustomSpan = createCustomSpan;
|
|
10
|
+
exports.createGuardrailSpan = createGuardrailSpan;
|
|
11
|
+
exports.createTranscriptionSpan = createTranscriptionSpan;
|
|
12
|
+
exports.createSpeechSpan = createSpeechSpan;
|
|
13
|
+
exports.createSpeechGroupSpan = createSpeechGroupSpan;
|
|
14
|
+
exports.createMCPListToolsSpan = createMCPListToolsSpan;
|
|
15
|
+
const context_1 = require("./context.js");
|
|
16
|
+
const provider_1 = require("./provider.js");
|
|
3
17
|
function _withSpanFactory(createSpan) {
|
|
4
18
|
return async (fn, ...args) => {
|
|
5
19
|
// Creating a new span context to make sure that the previous span is correctly reset
|
|
6
|
-
return withNewSpanContext(async () => {
|
|
20
|
+
return (0, context_1.withNewSpanContext)(async () => {
|
|
7
21
|
const span = createSpan(...args);
|
|
8
|
-
setCurrentSpan(span);
|
|
22
|
+
(0, context_1.setCurrentSpan)(span);
|
|
9
23
|
try {
|
|
10
24
|
span.start();
|
|
11
25
|
return await fn(span);
|
|
@@ -19,7 +33,7 @@ function _withSpanFactory(createSpan) {
|
|
|
19
33
|
}
|
|
20
34
|
finally {
|
|
21
35
|
span.end();
|
|
22
|
-
resetCurrentSpan();
|
|
36
|
+
(0, context_1.resetCurrentSpan)();
|
|
23
37
|
}
|
|
24
38
|
});
|
|
25
39
|
};
|
|
@@ -38,9 +52,9 @@ function _withSpanFactory(createSpan) {
|
|
|
38
52
|
*
|
|
39
53
|
* @returns The newly created response span.
|
|
40
54
|
*/
|
|
41
|
-
|
|
55
|
+
function createResponseSpan(options, parent) {
|
|
42
56
|
options = {};
|
|
43
|
-
return getGlobalTraceProvider().createSpan({
|
|
57
|
+
return (0, provider_1.getGlobalTraceProvider)().createSpan({
|
|
44
58
|
...options,
|
|
45
59
|
data: {
|
|
46
60
|
type: 'response',
|
|
@@ -55,7 +69,7 @@ export function createResponseSpan(options, parent) {
|
|
|
55
69
|
* If you need to capture detailed generation information such as input/output messages,
|
|
56
70
|
* model configuration, or usage data, use `generationSpan()` instead.
|
|
57
71
|
*/
|
|
58
|
-
|
|
72
|
+
exports.withResponseSpan = _withSpanFactory(createResponseSpan);
|
|
59
73
|
/**
|
|
60
74
|
* Create a new agent span. The span will not be started automatically, you should either
|
|
61
75
|
* use `withAgentSpan()` or call `span.start()` and `span.end()` manually.
|
|
@@ -66,8 +80,8 @@ export const withResponseSpan = _withSpanFactory(createResponseSpan);
|
|
|
66
80
|
*
|
|
67
81
|
* @returns The newly created agent span.
|
|
68
82
|
*/
|
|
69
|
-
|
|
70
|
-
return getGlobalTraceProvider().createSpan({
|
|
83
|
+
function createAgentSpan(options, parent) {
|
|
84
|
+
return (0, provider_1.getGlobalTraceProvider)().createSpan({
|
|
71
85
|
...options,
|
|
72
86
|
data: {
|
|
73
87
|
type: 'agent',
|
|
@@ -79,7 +93,7 @@ export function createAgentSpan(options, parent) {
|
|
|
79
93
|
/**
|
|
80
94
|
* Create a new agent span and automatically start and end it.
|
|
81
95
|
*/
|
|
82
|
-
|
|
96
|
+
exports.withAgentSpan = _withSpanFactory(createAgentSpan);
|
|
83
97
|
/**
|
|
84
98
|
* Create a new function span. The span will not be started automatically, you should either
|
|
85
99
|
* use `withFunctionSpan()` or call `span.start()` and `span.end()` manually.
|
|
@@ -90,8 +104,8 @@ export const withAgentSpan = _withSpanFactory(createAgentSpan);
|
|
|
90
104
|
*
|
|
91
105
|
* @returns The newly created function span.
|
|
92
106
|
*/
|
|
93
|
-
|
|
94
|
-
return getGlobalTraceProvider().createSpan({
|
|
107
|
+
function createFunctionSpan(options, parent) {
|
|
108
|
+
return (0, provider_1.getGlobalTraceProvider)().createSpan({
|
|
95
109
|
...options,
|
|
96
110
|
data: {
|
|
97
111
|
type: 'function',
|
|
@@ -104,7 +118,7 @@ export function createFunctionSpan(options, parent) {
|
|
|
104
118
|
/**
|
|
105
119
|
* Create a new function span and automatically start and end it.
|
|
106
120
|
*/
|
|
107
|
-
|
|
121
|
+
exports.withFunctionSpan = _withSpanFactory(createFunctionSpan);
|
|
108
122
|
/**
|
|
109
123
|
* Create a new handoff span. The span will not be started automatically, you should either
|
|
110
124
|
* use `withHandoffSpan()` or call `span.start()` and `span.end()` manually.
|
|
@@ -115,8 +129,8 @@ export const withFunctionSpan = _withSpanFactory(createFunctionSpan);
|
|
|
115
129
|
*
|
|
116
130
|
* @returns The newly created handoff span.
|
|
117
131
|
*/
|
|
118
|
-
|
|
119
|
-
return getGlobalTraceProvider().createSpan({
|
|
132
|
+
function createHandoffSpan(options, parent) {
|
|
133
|
+
return (0, provider_1.getGlobalTraceProvider)().createSpan({
|
|
120
134
|
...options,
|
|
121
135
|
data: { type: 'handoff', ...options?.data },
|
|
122
136
|
}, parent);
|
|
@@ -124,7 +138,7 @@ export function createHandoffSpan(options, parent) {
|
|
|
124
138
|
/**
|
|
125
139
|
* Create a new handoff span and automatically start and end it.
|
|
126
140
|
*/
|
|
127
|
-
|
|
141
|
+
exports.withHandoffSpan = _withSpanFactory(createHandoffSpan);
|
|
128
142
|
/**
|
|
129
143
|
* Create a new generation span. The span will not be started automatically, you should either
|
|
130
144
|
* use `withGenerationSpan()` or call `span.start()` and `span.end()` manually.
|
|
@@ -133,8 +147,8 @@ export const withHandoffSpan = _withSpanFactory(createHandoffSpan);
|
|
|
133
147
|
* sequences, model information, and usage data. If you only need to capture a model response
|
|
134
148
|
* identifier, consider using `createResponseSpan()` instead.
|
|
135
149
|
*/
|
|
136
|
-
|
|
137
|
-
return getGlobalTraceProvider().createSpan({
|
|
150
|
+
function createGenerationSpan(options, parent) {
|
|
151
|
+
return (0, provider_1.getGlobalTraceProvider)().createSpan({
|
|
138
152
|
...options,
|
|
139
153
|
data: {
|
|
140
154
|
type: 'generation',
|
|
@@ -143,13 +157,13 @@ export function createGenerationSpan(options, parent) {
|
|
|
143
157
|
}, parent);
|
|
144
158
|
}
|
|
145
159
|
/** Automatically create a generation span, run fn and close the span */
|
|
146
|
-
|
|
160
|
+
exports.withGenerationSpan = _withSpanFactory(createGenerationSpan);
|
|
147
161
|
/**
|
|
148
162
|
* Create a new custom span. The span will not be started automatically, you should either use
|
|
149
163
|
* `withCustomSpan()` or call `span.start()` and `span.end()` manually.
|
|
150
164
|
*/
|
|
151
|
-
|
|
152
|
-
return getGlobalTraceProvider().createSpan({
|
|
165
|
+
function createCustomSpan(options, parent) {
|
|
166
|
+
return (0, provider_1.getGlobalTraceProvider)().createSpan({
|
|
153
167
|
...options,
|
|
154
168
|
data: {
|
|
155
169
|
type: 'custom',
|
|
@@ -158,13 +172,13 @@ export function createCustomSpan(options, parent) {
|
|
|
158
172
|
},
|
|
159
173
|
}, parent);
|
|
160
174
|
}
|
|
161
|
-
|
|
175
|
+
exports.withCustomSpan = _withSpanFactory(createCustomSpan);
|
|
162
176
|
/**
|
|
163
177
|
* Create a new guardrail span. The span will not be started automatically, you should either use
|
|
164
178
|
* `withGuardrailSpan()` or call `span.start()` and `span.end()` manually.
|
|
165
179
|
*/
|
|
166
|
-
|
|
167
|
-
return getGlobalTraceProvider().createSpan({
|
|
180
|
+
function createGuardrailSpan(options, parent) {
|
|
181
|
+
return (0, provider_1.getGlobalTraceProvider)().createSpan({
|
|
168
182
|
...options,
|
|
169
183
|
data: {
|
|
170
184
|
type: 'guardrail',
|
|
@@ -173,12 +187,12 @@ export function createGuardrailSpan(options, parent) {
|
|
|
173
187
|
},
|
|
174
188
|
}, parent);
|
|
175
189
|
}
|
|
176
|
-
|
|
190
|
+
exports.withGuardrailSpan = _withSpanFactory(createGuardrailSpan);
|
|
177
191
|
/**
|
|
178
192
|
* Create a new transcription span. The span will not be started automatically.
|
|
179
193
|
*/
|
|
180
|
-
|
|
181
|
-
return getGlobalTraceProvider().createSpan({
|
|
194
|
+
function createTranscriptionSpan(options, parent) {
|
|
195
|
+
return (0, provider_1.getGlobalTraceProvider)().createSpan({
|
|
182
196
|
...options,
|
|
183
197
|
data: {
|
|
184
198
|
type: 'transcription',
|
|
@@ -186,12 +200,12 @@ export function createTranscriptionSpan(options, parent) {
|
|
|
186
200
|
},
|
|
187
201
|
}, parent);
|
|
188
202
|
}
|
|
189
|
-
|
|
203
|
+
exports.withTranscriptionSpan = _withSpanFactory(createTranscriptionSpan);
|
|
190
204
|
/**
|
|
191
205
|
* Create a new speech span. The span will not be started automatically.
|
|
192
206
|
*/
|
|
193
|
-
|
|
194
|
-
return getGlobalTraceProvider().createSpan({
|
|
207
|
+
function createSpeechSpan(options, parent) {
|
|
208
|
+
return (0, provider_1.getGlobalTraceProvider)().createSpan({
|
|
195
209
|
...options,
|
|
196
210
|
data: {
|
|
197
211
|
type: 'speech',
|
|
@@ -199,12 +213,12 @@ export function createSpeechSpan(options, parent) {
|
|
|
199
213
|
},
|
|
200
214
|
}, parent);
|
|
201
215
|
}
|
|
202
|
-
|
|
216
|
+
exports.withSpeechSpan = _withSpanFactory(createSpeechSpan);
|
|
203
217
|
/**
|
|
204
218
|
* Create a new speech group span. The span will not be started automatically.
|
|
205
219
|
*/
|
|
206
|
-
|
|
207
|
-
return getGlobalTraceProvider().createSpan({
|
|
220
|
+
function createSpeechGroupSpan(options, parent) {
|
|
221
|
+
return (0, provider_1.getGlobalTraceProvider)().createSpan({
|
|
208
222
|
...options,
|
|
209
223
|
data: {
|
|
210
224
|
type: 'speech_group',
|
|
@@ -212,12 +226,12 @@ export function createSpeechGroupSpan(options, parent) {
|
|
|
212
226
|
},
|
|
213
227
|
}, parent);
|
|
214
228
|
}
|
|
215
|
-
|
|
229
|
+
exports.withSpeechGroupSpan = _withSpanFactory(createSpeechGroupSpan);
|
|
216
230
|
/**
|
|
217
231
|
* Create a new MCP list tools span. The span will not be started automatically.
|
|
218
232
|
*/
|
|
219
|
-
|
|
220
|
-
return getGlobalTraceProvider().createSpan({
|
|
233
|
+
function createMCPListToolsSpan(options, parent) {
|
|
234
|
+
return (0, provider_1.getGlobalTraceProvider)().createSpan({
|
|
221
235
|
...options,
|
|
222
236
|
data: {
|
|
223
237
|
type: 'mcp_tools',
|
|
@@ -225,5 +239,5 @@ export function createMCPListToolsSpan(options, parent) {
|
|
|
225
239
|
},
|
|
226
240
|
}, parent);
|
|
227
241
|
}
|
|
228
|
-
|
|
242
|
+
exports.withMCPListToolsSpan = _withSpanFactory(createMCPListToolsSpan);
|
|
229
243
|
//# sourceMappingURL=createSpans.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createSpans.js","sourceRoot":"","sources":["../../src/tracing/createSpans.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createSpans.js","sourceRoot":"","sources":["../../src/tracing/createSpans.ts"],"names":[],"mappings":";;;AAqEA,gDAeC;AAwBD,0CAeC;AAoBD,gDAgBC;AAoBD,8CAWC;AAkBD,oDAcC;AAYD,4CAeC;AAWD,kDAeC;AAUD,0DAgBC;AAUD,4CAgBC;AAUD,sDAcC;AAUD,wDAcC;AAtXD,0CAImB;AACnB,4CAAuE;AAoBvE,SAAS,gBAAgB,CAGvB,UAA+B;IAC/B,OAAO,KAAK,EACV,EAA2C,EAC3C,GAAG,IAAqC,EACxC,EAAE;QACF,qFAAqF;QACrF,OAAO,IAAA,4BAAkB,EAAC,KAAK,IAAI,EAAE;YACnC,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,IAAI,CAAC,CAAC;YACjC,IAAA,wBAAc,EAAC,IAAI,CAAC,CAAC;YACrB,IAAI,CAAC;gBACH,IAAI,CAAC,KAAK,EAAE,CAAC;gBACb,OAAO,MAAM,EAAE,CAAC,IAAI,CAAC,CAAC;YACxB,CAAC;YAAC,OAAO,KAAU,EAAE,CAAC;gBACpB,IAAI,CAAC,QAAQ,CAAC;oBACZ,OAAO,EAAE,KAAK,CAAC,OAAO;oBACtB,IAAI,EAAE,KAAK,CAAC,IAAI;iBACjB,CAAC,CAAC;gBACH,MAAM,KAAK,CAAC;YACd,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC,GAAG,EAAE,CAAC;gBACX,IAAA,0BAAgB,GAAE,CAAC;YACrB,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH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C,CAAC"}
|
package/dist/tracing/index.js
CHANGED
|
@@ -1,38 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
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
|
+
exports.generateTraceId = exports.generateSpanId = exports.generateGroupId = exports.Trace = exports.NoopTrace = exports.Span = exports.NoopSpan = exports.ConsoleSpanExporter = exports.BatchTraceProcessor = exports.withTrace = exports.setCurrentSpan = exports.resetCurrentSpan = exports.getOrCreateTrace = exports.getCurrentTrace = exports.getCurrentSpan = void 0;
|
|
18
|
+
exports.addTraceProcessor = addTraceProcessor;
|
|
19
|
+
exports.setTraceProcessors = setTraceProcessors;
|
|
20
|
+
exports.setTracingDisabled = setTracingDisabled;
|
|
21
|
+
exports.startTraceExportLoop = startTraceExportLoop;
|
|
22
|
+
const provider_1 = require("./provider.js");
|
|
23
|
+
var context_1 = require("./context.js");
|
|
24
|
+
Object.defineProperty(exports, "getCurrentSpan", { enumerable: true, get: function () { return context_1.getCurrentSpan; } });
|
|
25
|
+
Object.defineProperty(exports, "getCurrentTrace", { enumerable: true, get: function () { return context_1.getCurrentTrace; } });
|
|
26
|
+
Object.defineProperty(exports, "getOrCreateTrace", { enumerable: true, get: function () { return context_1.getOrCreateTrace; } });
|
|
27
|
+
Object.defineProperty(exports, "resetCurrentSpan", { enumerable: true, get: function () { return context_1.resetCurrentSpan; } });
|
|
28
|
+
Object.defineProperty(exports, "setCurrentSpan", { enumerable: true, get: function () { return context_1.setCurrentSpan; } });
|
|
29
|
+
Object.defineProperty(exports, "withTrace", { enumerable: true, get: function () { return context_1.withTrace; } });
|
|
30
|
+
__exportStar(require("./createSpans.js"), exports);
|
|
31
|
+
var processor_1 = require("./processor.js");
|
|
32
|
+
Object.defineProperty(exports, "BatchTraceProcessor", { enumerable: true, get: function () { return processor_1.BatchTraceProcessor; } });
|
|
33
|
+
Object.defineProperty(exports, "ConsoleSpanExporter", { enumerable: true, get: function () { return processor_1.ConsoleSpanExporter; } });
|
|
34
|
+
var spans_1 = require("./spans.js");
|
|
35
|
+
Object.defineProperty(exports, "NoopSpan", { enumerable: true, get: function () { return spans_1.NoopSpan; } });
|
|
36
|
+
Object.defineProperty(exports, "Span", { enumerable: true, get: function () { return spans_1.Span; } });
|
|
37
|
+
var traces_1 = require("./traces.js");
|
|
38
|
+
Object.defineProperty(exports, "NoopTrace", { enumerable: true, get: function () { return traces_1.NoopTrace; } });
|
|
39
|
+
Object.defineProperty(exports, "Trace", { enumerable: true, get: function () { return traces_1.Trace; } });
|
|
40
|
+
var utils_1 = require("./utils.js");
|
|
41
|
+
Object.defineProperty(exports, "generateGroupId", { enumerable: true, get: function () { return utils_1.generateGroupId; } });
|
|
42
|
+
Object.defineProperty(exports, "generateSpanId", { enumerable: true, get: function () { return utils_1.generateSpanId; } });
|
|
43
|
+
Object.defineProperty(exports, "generateTraceId", { enumerable: true, get: function () { return utils_1.generateTraceId; } });
|
|
8
44
|
/**
|
|
9
45
|
* Add a processor to the list of processors. Each processor will receive all traces/spans.
|
|
10
46
|
*
|
|
11
47
|
* @param processor - The processor to add.
|
|
12
48
|
*/
|
|
13
|
-
|
|
14
|
-
getGlobalTraceProvider().registerProcessor(processor);
|
|
49
|
+
function addTraceProcessor(processor) {
|
|
50
|
+
(0, provider_1.getGlobalTraceProvider)().registerProcessor(processor);
|
|
15
51
|
}
|
|
16
52
|
/**
|
|
17
53
|
* Set the list of processors. This will replace any existing processors.
|
|
18
54
|
*
|
|
19
55
|
* @param processors - The list of processors to set.
|
|
20
56
|
*/
|
|
21
|
-
|
|
22
|
-
getGlobalTraceProvider().setProcessors(processors);
|
|
57
|
+
function setTraceProcessors(processors) {
|
|
58
|
+
(0, provider_1.getGlobalTraceProvider)().setProcessors(processors);
|
|
23
59
|
}
|
|
24
60
|
/**
|
|
25
61
|
* Set the disabled state of the tracing provider.
|
|
26
62
|
*
|
|
27
63
|
* @param disabled - Whether to disable tracing.
|
|
28
64
|
*/
|
|
29
|
-
|
|
30
|
-
getGlobalTraceProvider().setDisabled(disabled);
|
|
65
|
+
function setTracingDisabled(disabled) {
|
|
66
|
+
(0, provider_1.getGlobalTraceProvider)().setDisabled(disabled);
|
|
31
67
|
}
|
|
32
68
|
/**
|
|
33
69
|
* Start the trace export loop.
|
|
34
70
|
*/
|
|
35
|
-
|
|
36
|
-
getGlobalTraceProvider().startExportLoop();
|
|
71
|
+
function startTraceExportLoop() {
|
|
72
|
+
(0, provider_1.getGlobalTraceProvider)().startExportLoop();
|
|
37
73
|
}
|
|
38
74
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tracing/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tracing/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AA2BA,8CAEC;AAOD,gDAEC;AAOD,gDAEC;AAKD,oDAEC;AArDD,4CAAoD;AAEpD,wCAOmB;AANjB,yGAAA,cAAc,OAAA;AACd,0GAAA,eAAe,OAAA;AACf,2GAAA,gBAAgB,OAAA;AAChB,2GAAA,gBAAgB,OAAA;AAChB,yGAAA,cAAc,OAAA;AACd,oGAAA,SAAS,OAAA;AAEX,mDAA8B;AAC9B,4CAKqB;AAJnB,gHAAA,mBAAmB,OAAA;AAGnB,gHAAA,mBAAmB,OAAA;AAErB,oCAAyC;AAAhC,iGAAA,QAAQ,OAAA;AAAE,6FAAA,IAAI,OAAA;AACvB,sCAA4C;AAAnC,mGAAA,SAAS,OAAA;AAAE,+FAAA,KAAK,OAAA;AACzB,oCAA2E;AAAlE,wGAAA,eAAe,OAAA;AAAE,uGAAA,cAAc,OAAA;AAAE,wGAAA,eAAe,OAAA;AAEzD;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,SAA2B;IAC3D,IAAA,iCAAsB,GAAE,CAAC,iBAAiB,CAAC,SAAS,CAAC,CAAC;AACxD,CAAC;AAED;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,UAA8B;IAC/D,IAAA,iCAAsB,GAAE,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;AACrD,CAAC;AAED;;;;GAIG;AACH,SAAgB,kBAAkB,CAAC,QAAiB;IAClD,IAAA,iCAAsB,GAAE,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;AACjD,CAAC;AAED;;GAEG;AACH,SAAgB,oBAAoB;IAClC,IAAA,iCAAsB,GAAE,CAAC,eAAe,EAAE,CAAC;AAC7C,CAAC"}
|
|
@@ -1,13 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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.MultiTracingProcessor = exports.BatchTraceProcessor = exports.ConsoleSpanExporter = void 0;
|
|
7
|
+
exports.defaultExporter = defaultExporter;
|
|
8
|
+
exports.defaultProcessor = defaultProcessor;
|
|
9
|
+
const logger_1 = __importDefault(require("../logger.js"));
|
|
10
|
+
const _shims_1 = require("@openai/agents-core/_shims");
|
|
11
|
+
const config_1 = require("../config.js");
|
|
4
12
|
/**
|
|
5
13
|
* Prints the traces and spans to the console
|
|
6
14
|
*/
|
|
7
|
-
|
|
15
|
+
class ConsoleSpanExporter {
|
|
8
16
|
async export(items) {
|
|
9
|
-
if (tracing.disabled) {
|
|
10
|
-
|
|
17
|
+
if (config_1.tracing.disabled) {
|
|
18
|
+
logger_1.default.debug('Tracing is disabled. Skipping export');
|
|
11
19
|
return;
|
|
12
20
|
}
|
|
13
21
|
for (const item of items) {
|
|
@@ -20,7 +28,8 @@ export class ConsoleSpanExporter {
|
|
|
20
28
|
}
|
|
21
29
|
}
|
|
22
30
|
}
|
|
23
|
-
|
|
31
|
+
exports.ConsoleSpanExporter = ConsoleSpanExporter;
|
|
32
|
+
class BatchTraceProcessor {
|
|
24
33
|
#maxQueueSize;
|
|
25
34
|
#maxBatchSize;
|
|
26
35
|
#scheduleDelay;
|
|
@@ -38,12 +47,12 @@ export class BatchTraceProcessor {
|
|
|
38
47
|
this.#scheduleDelay = scheduleDelay;
|
|
39
48
|
this.#exportTriggerSize = maxQueueSize * exportTriggerRatio;
|
|
40
49
|
this.#exporter = exporter;
|
|
41
|
-
this.#timer =
|
|
42
|
-
if (isTracingLoopRunningByDefault()) {
|
|
50
|
+
this.#timer = _shims_1.timer;
|
|
51
|
+
if ((0, _shims_1.isTracingLoopRunningByDefault)()) {
|
|
43
52
|
this.start();
|
|
44
53
|
}
|
|
45
54
|
else {
|
|
46
|
-
|
|
55
|
+
logger_1.default.debug('Automatic trace export loop is not supported in this environment. You need to manually call `getGlobalTraceProvider().forceFlush()` to export traces.');
|
|
47
56
|
}
|
|
48
57
|
}
|
|
49
58
|
start() {
|
|
@@ -52,7 +61,7 @@ export class BatchTraceProcessor {
|
|
|
52
61
|
}
|
|
53
62
|
async #safeAddItem(item) {
|
|
54
63
|
if (this.#buffer.length + 1 > this.#maxQueueSize) {
|
|
55
|
-
|
|
64
|
+
logger_1.default.error('Dropping trace because buffer is full');
|
|
56
65
|
return;
|
|
57
66
|
}
|
|
58
67
|
// add the item to the buffer
|
|
@@ -78,7 +87,7 @@ export class BatchTraceProcessor {
|
|
|
78
87
|
if (this.#buffer.length === 0) {
|
|
79
88
|
return;
|
|
80
89
|
}
|
|
81
|
-
|
|
90
|
+
logger_1.default.debug(`Exporting batches. Force: ${force}. Buffer size: ${this.#buffer.length}`);
|
|
82
91
|
if (force || this.#buffer.length < this.#maxBatchSize) {
|
|
83
92
|
const toExport = [...this.#buffer];
|
|
84
93
|
this.#buffer = [];
|
|
@@ -112,22 +121,22 @@ export class BatchTraceProcessor {
|
|
|
112
121
|
this.#timeoutAbortController?.abort();
|
|
113
122
|
}, timeout);
|
|
114
123
|
}
|
|
115
|
-
|
|
124
|
+
logger_1.default.debug('Shutting down gracefully');
|
|
116
125
|
while (this.#buffer.length > 0) {
|
|
117
|
-
|
|
126
|
+
logger_1.default.debug(`Waiting for buffer to empty. Items left: ${this.#buffer.length}`);
|
|
118
127
|
if (!this.#exportInProgress) {
|
|
119
128
|
// no current export in progress. Forcing all items to be exported
|
|
120
129
|
await this.#exportBatches(true);
|
|
121
130
|
}
|
|
122
131
|
if (this.#timeoutAbortController?.signal.aborted) {
|
|
123
|
-
|
|
132
|
+
logger_1.default.debug('Timeout reached, force flushing');
|
|
124
133
|
await this.#exportBatches(true);
|
|
125
134
|
break;
|
|
126
135
|
}
|
|
127
136
|
// using setTimeout to add to the event loop and keep this alive until done
|
|
128
137
|
await new Promise((resolve) => this.#timer.setTimeout(resolve, 500));
|
|
129
138
|
}
|
|
130
|
-
|
|
139
|
+
logger_1.default.debug('Buffer empty. Exiting');
|
|
131
140
|
if (this.#timer && this.#timeout) {
|
|
132
141
|
// making sure there are no more requests
|
|
133
142
|
this.#timer.clearTimeout(this.#timeout);
|
|
@@ -139,7 +148,8 @@ export class BatchTraceProcessor {
|
|
|
139
148
|
}
|
|
140
149
|
}
|
|
141
150
|
}
|
|
142
|
-
|
|
151
|
+
exports.BatchTraceProcessor = BatchTraceProcessor;
|
|
152
|
+
class MultiTracingProcessor {
|
|
143
153
|
#processors = [];
|
|
144
154
|
start() {
|
|
145
155
|
for (const processor of this.#processors) {
|
|
@@ -152,7 +162,7 @@ export class MultiTracingProcessor {
|
|
|
152
162
|
this.#processors.push(processor);
|
|
153
163
|
}
|
|
154
164
|
setProcessors(processors) {
|
|
155
|
-
|
|
165
|
+
logger_1.default.debug('Shutting down old processors');
|
|
156
166
|
for (const processor of this.#processors) {
|
|
157
167
|
processor.shutdown();
|
|
158
168
|
}
|
|
@@ -189,15 +199,16 @@ export class MultiTracingProcessor {
|
|
|
189
199
|
}
|
|
190
200
|
}
|
|
191
201
|
}
|
|
202
|
+
exports.MultiTracingProcessor = MultiTracingProcessor;
|
|
192
203
|
let _defaultExporter = null;
|
|
193
204
|
let _defaultProcessor = null;
|
|
194
|
-
|
|
205
|
+
function defaultExporter() {
|
|
195
206
|
if (!_defaultExporter) {
|
|
196
207
|
_defaultExporter = new ConsoleSpanExporter();
|
|
197
208
|
}
|
|
198
209
|
return _defaultExporter;
|
|
199
210
|
}
|
|
200
|
-
|
|
211
|
+
function defaultProcessor() {
|
|
201
212
|
if (!_defaultProcessor) {
|
|
202
213
|
_defaultProcessor = new BatchTraceProcessor(defaultExporter());
|
|
203
214
|
}
|