Skip to content

Commit 0f27ffb

Browse files
committed
chore(weave_ts): Use types provided by @openai/agents
1 parent e196bf7 commit 0f27ffb

2 files changed

Lines changed: 19 additions & 164 deletions

File tree

sdks/node/src/__tests__/integrations/openaiAgent.test.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {InMemoryTraceServer} from '../../inMemoryTraceServer';
22
import {createOpenAIAgentsTracingProcessor} from '../../integrations/openai.agent';
3+
import type { Trace, Span } from '../../integrations/openai.agent.types';
34
import {initWithCustomTraceServer} from '../clientMock';
45

56
describe('OpenAI Agents Integration', () => {
@@ -14,12 +15,12 @@ describe('OpenAI Agents Integration', () => {
1415
test('trace lifecycle creates and finishes call', async () => {
1516
const processor = createOpenAIAgentsTracingProcessor();
1617
const trace = {
17-
type: 'trace' as const,
18+
type: 'trace',
1819
traceId: 'test-trace-123',
1920
name: 'Agent Workflow',
2021
groupId: null,
2122
metadata: {},
22-
};
23+
} as Trace;
2324

2425
await processor.onTraceStart(trace);
2526
await processor.onTraceEnd(trace);
@@ -43,7 +44,7 @@ describe('OpenAI Agents Integration', () => {
4344
traceId: 'test-trace',
4445
name: 'Test',
4546
groupId: null,
46-
});
47+
} as Trace);
4748

4849
// Test key span types
4950
const spans = [
@@ -62,7 +63,7 @@ describe('OpenAI Agents Integration', () => {
6263
startedAt: null,
6364
endedAt: null,
6465
error: null,
65-
});
66+
} as Span);
6667
}
6768

6869
const calls = await inMemoryTraceServer.getCalls(testProjectName);
@@ -81,7 +82,7 @@ describe('OpenAI Agents Integration', () => {
8182
traceId: 'trace-123',
8283
name: 'Workflow',
8384
groupId: null,
84-
});
85+
} as Trace);
8586

8687
await processor.onSpanStart({
8788
type: 'trace.span',
@@ -92,7 +93,7 @@ describe('OpenAI Agents Integration', () => {
9293
startedAt: null,
9394
endedAt: null,
9495
error: null,
95-
});
96+
} as Span);
9697

9798
const calls = await inMemoryTraceServer.getCalls(testProjectName);
9899
expect(calls).toHaveLength(2);
Lines changed: 12 additions & 158 deletions
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,26 @@
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

Comments
 (0)