11/**
22 * Type definitions for OpenAI Agents integration
33 *
4- * These types are duck-typed to match @openai/agents without importing from that package.
5- * This allows users to use the integration without forcing a dependency on @openai/agents.
64 */
75
86// ============================================================================
97// Span Data Types
108// ============================================================================
119
12- /**
13- * Base span data structure
14- */
15- type SpanDataBase = {
16- type : string ;
17- } ;
18-
19- /**
20- * Agent execution span data
21- */
22- type AgentSpanData = SpanDataBase & {
23- type : 'agent' ;
24- name : string ;
25- handoffs ?: string [ ] ;
26- tools ?: string [ ] ;
27- output_type ?: string ;
28- } ;
29-
30- /**
31- * Function/tool execution span data
32- */
33- type FunctionSpanData = SpanDataBase & {
34- type : 'function' ;
35- name : string ;
36- input : string ;
37- output : string ;
38- mcp_data ?: string ;
39- } ;
40-
41- /**
42- * LLM generation span data
43- */
44- type GenerationSpanData = SpanDataBase & {
45- type : 'generation' ;
46- input ?: Array < Record < string , any > > ;
47- output ?: Array < Record < string , any > > ;
48- model ?: string ;
49- model_config ?: Record < string , any > ;
50- usage ?: {
51- input_tokens ?: number ;
52- output_tokens ?: number ;
53- details ?: Record < string , unknown > | null ;
54- [ key : string ] : unknown ;
55- } ;
56- } ;
10+ import type {
11+ AgentSpanData ,
12+ CustomSpanData ,
13+ FunctionSpanData ,
14+ GenerationSpanData ,
15+ GuardrailSpanData ,
16+ HandoffSpanData ,
17+ ResponseSpanData ,
18+ Span as OpenAIAgentsSpan ,
19+ } from '@openai/agents' ;
5720
58- /**
59- * Response span data
60- */
61- type ResponseSpanData = SpanDataBase & {
62- type : 'response' ;
63- response_id ?: string ;
64- _input ?: string | Record < string , any > [ ] ;
65- _response ?: Record < string , any > ;
66- } ;
67-
68- /**
69- * Agent handoff span data
70- */
71- type HandoffSpanData = SpanDataBase & {
72- type : 'handoff' ;
73- from_agent ?: string ;
74- to_agent ?: string ;
75- } ;
21+ export type { CustomSpanData , Trace , TracingProcessor } from '@openai/agents' ;
7622
77- /**
78- * Custom span data
79- */
80- export type CustomSpanData = SpanDataBase & {
81- type : 'custom' ;
82- name : string ;
83- data : Record < string , any > ;
84- } ;
85-
86- /**
87- * Guardrail span data
88- */
89- type GuardrailSpanData = SpanDataBase & {
90- type : 'guardrail' ;
91- name : string ;
92- triggered : boolean ;
93- } ;
23+ export type Span < TData extends SpanData = SpanData > = OpenAIAgentsSpan < TData > ;
9424
9525/**
9626 * Union of all span data types
@@ -103,79 +33,3 @@ export type SpanData =
10333 | HandoffSpanData
10434 | CustomSpanData
10535 | GuardrailSpanData ;
106-
107- /**
108- * Span error structure
109- */
110- export type SpanError = {
111- message : string ;
112- data ?: Record < string , any > ;
113- } ;
114-
115- /**
116- * Span structure (duck typed to match @openai/agents Span class)
117- */
118- export type Span < TData extends SpanData = SpanData > = {
119- readonly type : 'trace.span' ;
120- readonly traceId : string ;
121- readonly spanId : string ;
122- readonly parentId : string | null ;
123- readonly spanData : TData ;
124- readonly traceMetadata ?: Record < string , any > ;
125- readonly startedAt : string | null ;
126- readonly endedAt : string | null ;
127- readonly error : SpanError | null ;
128- readonly tracingApiKey ?: string ;
129- } ;
130-
131- /**
132- * Trace structure (duck typed to match @openai/agents Trace class)
133- */
134- export type Trace = {
135- readonly type : 'trace' ;
136- traceId : string ;
137- name : string ;
138- groupId : string | null ;
139- metadata ?: Record < string , any > ;
140- tracingApiKey ?: string ;
141- } ;
142-
143- /**
144- * TracingProcessor interface (duck typed to match @openai/agents)
145- */
146- export interface TracingProcessor {
147- /**
148- * Optional start method for processors that need initialization
149- */
150- start ?( ) : void ;
151-
152- /**
153- * Called when a trace starts
154- */
155- onTraceStart ( trace : Trace ) : Promise < void > ;
156-
157- /**
158- * Called when a trace ends
159- */
160- onTraceEnd ( trace : Trace ) : Promise < void > ;
161-
162- /**
163- * Called when a span starts
164- */
165- onSpanStart ( span : Span ) : Promise < void > ;
166-
167- /**
168- * Called when a span ends
169- */
170- onSpanEnd ( span : Span ) : Promise < void > ;
171-
172- /**
173- * Called when the processor should shut down
174- */
175- shutdown ( timeout ?: number ) : Promise < void > ;
176-
177- /**
178- * Called to force flush any pending traces
179- */
180- forceFlush ( ) : Promise < void > ;
181- }
0 commit comments