@countly/ai-sdk-openai 0.0.3
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/README.md +94 -0
- package/dist/adapter.d.ts +25 -0
- package/dist/adapter.d.ts.map +1 -0
- package/dist/adapter.js +356 -0
- package/dist/adapter.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -0
- package/package.json +39 -0
package/README.md
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
# @countly/ai-sdk-openai
|
|
2
|
+
|
|
3
|
+
> Countly AI observability adapter for the [OpenAI Node.js SDK](https://github.com/openai/openai-node).
|
|
4
|
+
|
|
5
|
+
Part of the [Countly AI SDK](https://github.com/Countly/countly-ai-sdk) — provider-agnostic LLM observability for every AI stack.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @countly/ai-sdk-openai
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
`@countly/ai-sdk-core` is pulled in automatically.
|
|
14
|
+
|
|
15
|
+
## Peer dependency
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
openai >= 4.68.0
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Quick Start
|
|
22
|
+
|
|
23
|
+
```typescript
|
|
24
|
+
import OpenAI from "openai";
|
|
25
|
+
import { observeOpenAI } from "@countly/ai-sdk-openai";
|
|
26
|
+
|
|
27
|
+
// Per-user attribution via AsyncLocalStorage (Node.js)
|
|
28
|
+
import { AsyncLocalStorage } from "node:async_hooks";
|
|
29
|
+
const userStore = new AsyncLocalStorage<{ userId: string }>();
|
|
30
|
+
|
|
31
|
+
// In your middleware — run once per request
|
|
32
|
+
app.use((req, res, next) => {
|
|
33
|
+
userStore.run({ userId: req.user.id }, next);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
// Wrap your client — getDeviceId is called per event at enqueue time
|
|
37
|
+
const openai = observeOpenAI(new OpenAI(), {
|
|
38
|
+
appKey: "YOUR_APP_KEY",
|
|
39
|
+
url: "https://your-countly-server.com",
|
|
40
|
+
getDeviceId: () => userStore.getStore()?.userId,
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Use exactly as before — observability is automatic
|
|
44
|
+
const response = await openai.chat.completions.create({
|
|
45
|
+
model: "gpt-4o",
|
|
46
|
+
messages: [{ role: "user", content: "Explain quantum computing" }],
|
|
47
|
+
});
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Streaming
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
const stream = await openai.chat.completions.create({
|
|
54
|
+
model: "gpt-4o",
|
|
55
|
+
messages: [{ role: "user", content: "Hello" }],
|
|
56
|
+
stream: true,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
for await (const chunk of stream) {
|
|
60
|
+
process.stdout.write(chunk.choices[0]?.delta?.content || "");
|
|
61
|
+
}
|
|
62
|
+
// Events reported automatically after stream completes
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## What's captured
|
|
66
|
+
|
|
67
|
+
- Token usage (input, output, reasoning, cached)
|
|
68
|
+
- Cost (computed from model pricing)
|
|
69
|
+
- Latency (total + time to first token for streaming)
|
|
70
|
+
- Model config (temperature, top_p, max_tokens, frequency/presence penalties)
|
|
71
|
+
- Tool calls and their parameters
|
|
72
|
+
- Error tracking with categorization (rate_limit, context_length, content_filter, timeout, auth_error)
|
|
73
|
+
- APM traces for performance monitoring
|
|
74
|
+
- Per-user usage aggregation
|
|
75
|
+
|
|
76
|
+
## Browser
|
|
77
|
+
|
|
78
|
+
In the browser there is no multi-user request mixing — each user runs in their own tab. Use a static device ID:
|
|
79
|
+
|
|
80
|
+
```typescript
|
|
81
|
+
const openai = observeOpenAI(new OpenAI(), {
|
|
82
|
+
appKey: "YOUR_APP_KEY",
|
|
83
|
+
url: "https://your-countly-server.com",
|
|
84
|
+
deviceId: loggedInUser.id,
|
|
85
|
+
});
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Full documentation
|
|
89
|
+
|
|
90
|
+
See the [Countly AI SDK repository](https://github.com/Countly/countly-ai-sdk) for the unified data model, observability levels (0/1/2), cost calculation, privacy controls, and Countly plugin integration (Drill, Funnels, Cohorts, APM, Crash Analytics).
|
|
91
|
+
|
|
92
|
+
## License
|
|
93
|
+
|
|
94
|
+
MIT
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { type CountlyAIConfig } from "@countly/ai-sdk-core";
|
|
2
|
+
export interface CountlyOpenAIOptions extends CountlyAIConfig {
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* Wraps an OpenAI client with Countly AI observability.
|
|
6
|
+
*
|
|
7
|
+
* Uses JS Proxy to intercept `client.chat.completions.create()` calls
|
|
8
|
+
* and automatically track LLM interactions, token usage, costs, and latency.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import OpenAI from "openai";
|
|
13
|
+
* import { observeOpenAI } from "@countly/ai-sdk-openai";
|
|
14
|
+
*
|
|
15
|
+
* const client = observeOpenAI(new OpenAI(), {
|
|
16
|
+
* appKey: "YOUR_APP_KEY",
|
|
17
|
+
* url: "https://your-countly-server.com",
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* // Use client as normal — all calls are automatically tracked
|
|
21
|
+
* const response = await client.chat.completions.create({ ... });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export declare function observeOpenAI<T>(client: T, options: CountlyAIConfig): T;
|
|
25
|
+
//# sourceMappingURL=adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"adapter.d.ts","sourceRoot":"","sources":["../src/adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,eAAe,EAKrB,MAAM,sBAAsB,CAAC;AAM9B,MAAM,WAAW,oBAAqB,SAAQ,eAAe;CAAG;AA6WhE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,OAAO,EAAE,eAAe,GAAG,CAAC,CAyBvE"}
|
package/dist/adapter.js
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
import { resolveConfig, createTransport, buildAllEvents, generatePromptId, } from "@countly/ai-sdk-core";
|
|
2
|
+
function extractTextInput(args) {
|
|
3
|
+
const params = args[0];
|
|
4
|
+
if (!params?.messages)
|
|
5
|
+
return undefined;
|
|
6
|
+
const messages = params.messages;
|
|
7
|
+
const last = messages[messages.length - 1];
|
|
8
|
+
if (!last)
|
|
9
|
+
return undefined;
|
|
10
|
+
if (typeof last.content === "string")
|
|
11
|
+
return last.content;
|
|
12
|
+
if (Array.isArray(last.content)) {
|
|
13
|
+
return last.content
|
|
14
|
+
.filter((p) => p.type === "text")
|
|
15
|
+
.map((p) => p.text)
|
|
16
|
+
.join("");
|
|
17
|
+
}
|
|
18
|
+
return undefined;
|
|
19
|
+
}
|
|
20
|
+
function extractFromResponse(response) {
|
|
21
|
+
const choice = response.choices?.[0];
|
|
22
|
+
const tools = (choice?.message?.tool_calls ?? []).map((tc) => ({
|
|
23
|
+
name: tc.function?.name ?? "unknown",
|
|
24
|
+
type: "function_call",
|
|
25
|
+
arguments: tc.function?.arguments
|
|
26
|
+
? safeParseJSON(tc.function.arguments)
|
|
27
|
+
: undefined,
|
|
28
|
+
}));
|
|
29
|
+
// Collect provider-specific orphan fields into the open metadata bag.
|
|
30
|
+
const meta = {};
|
|
31
|
+
const r = response;
|
|
32
|
+
if (r.system_fingerprint)
|
|
33
|
+
meta.system_fingerprint = r.system_fingerprint;
|
|
34
|
+
if (r.service_tier)
|
|
35
|
+
meta.service_tier = r.service_tier;
|
|
36
|
+
const ctd = response.usage?.completion_tokens_details;
|
|
37
|
+
if (ctd?.accepted_prediction_tokens != null)
|
|
38
|
+
meta.accepted_prediction_tokens = ctd.accepted_prediction_tokens;
|
|
39
|
+
if (ctd?.rejected_prediction_tokens != null)
|
|
40
|
+
meta.rejected_prediction_tokens = ctd.rejected_prediction_tokens;
|
|
41
|
+
if (ctd?.audio_tokens != null)
|
|
42
|
+
meta.audio_tokens_completion = ctd.audio_tokens;
|
|
43
|
+
const ptd = response.usage?.prompt_tokens_details;
|
|
44
|
+
if (ptd?.audio_tokens != null)
|
|
45
|
+
meta.audio_tokens_prompt = ptd.audio_tokens;
|
|
46
|
+
if (choice && choice.logprobs)
|
|
47
|
+
meta.logprobs = choice.logprobs;
|
|
48
|
+
return {
|
|
49
|
+
model: response.model ?? "unknown",
|
|
50
|
+
provider: "openai",
|
|
51
|
+
usage_input: response.usage?.prompt_tokens ?? 0,
|
|
52
|
+
usage_output: response.usage?.completion_tokens ?? 0,
|
|
53
|
+
usage_total: response.usage?.total_tokens ?? 0,
|
|
54
|
+
usage_reasoning: response.usage?.completion_tokens_details?.reasoning_tokens,
|
|
55
|
+
usage_cache_read: response.usage?.prompt_tokens_details?.cached_tokens,
|
|
56
|
+
finish_reason: choice?.finish_reason ?? undefined,
|
|
57
|
+
tools: tools.length > 0 ? tools : undefined,
|
|
58
|
+
text_output: choice?.message?.content ?? undefined,
|
|
59
|
+
latency_total: 0, // filled by caller
|
|
60
|
+
status: "success",
|
|
61
|
+
...(r.id && { response_id: String(r.id) }),
|
|
62
|
+
...(response.model && { response_model: String(response.model) }),
|
|
63
|
+
...(Object.keys(meta).length > 0 && { provider_metadata: meta }),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
function extractFromChunks(chunks) {
|
|
67
|
+
if (chunks.length === 0) {
|
|
68
|
+
return {
|
|
69
|
+
model: "unknown",
|
|
70
|
+
provider: "openai",
|
|
71
|
+
usage_input: 0,
|
|
72
|
+
usage_output: 0,
|
|
73
|
+
usage_total: 0,
|
|
74
|
+
latency_total: 0,
|
|
75
|
+
status: "error",
|
|
76
|
+
error: "No chunks received",
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
// Collect text content from all chunks
|
|
80
|
+
const textParts = [];
|
|
81
|
+
const toolCallMap = new Map();
|
|
82
|
+
let model = "unknown";
|
|
83
|
+
let finishReason;
|
|
84
|
+
for (const chunk of chunks) {
|
|
85
|
+
if (chunk.model)
|
|
86
|
+
model = chunk.model;
|
|
87
|
+
const delta = chunk.choices?.[0]?.delta;
|
|
88
|
+
if (!delta)
|
|
89
|
+
continue;
|
|
90
|
+
if (chunk.choices?.[0]?.finish_reason) {
|
|
91
|
+
finishReason = chunk.choices[0].finish_reason;
|
|
92
|
+
}
|
|
93
|
+
if (delta.content) {
|
|
94
|
+
textParts.push(delta.content);
|
|
95
|
+
}
|
|
96
|
+
if (delta.tool_calls) {
|
|
97
|
+
for (const tc of delta.tool_calls) {
|
|
98
|
+
const idx = tc.index ?? 0;
|
|
99
|
+
const existing = toolCallMap.get(idx);
|
|
100
|
+
if (!existing) {
|
|
101
|
+
toolCallMap.set(idx, {
|
|
102
|
+
name: tc.function?.name ?? "",
|
|
103
|
+
arguments: tc.function?.arguments ?? "",
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
if (tc.function?.name)
|
|
108
|
+
existing.name = tc.function.name;
|
|
109
|
+
if (tc.function?.arguments)
|
|
110
|
+
existing.arguments += tc.function.arguments;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// Extract usage from the final chunk (OpenAI includes usage in last chunk when stream_options.include_usage is true)
|
|
116
|
+
const lastChunk = chunks[chunks.length - 1];
|
|
117
|
+
const usage = lastChunk?.usage;
|
|
118
|
+
const tools = Array.from(toolCallMap.values()).map((tc) => ({
|
|
119
|
+
name: tc.name || "unknown",
|
|
120
|
+
type: "function_call",
|
|
121
|
+
arguments: tc.arguments ? safeParseJSON(tc.arguments) : undefined,
|
|
122
|
+
}));
|
|
123
|
+
return {
|
|
124
|
+
model: model,
|
|
125
|
+
provider: "openai",
|
|
126
|
+
usage_input: usage?.prompt_tokens ?? 0,
|
|
127
|
+
usage_output: usage?.completion_tokens ?? 0,
|
|
128
|
+
usage_total: usage?.total_tokens ?? 0,
|
|
129
|
+
usage_reasoning: usage?.completion_tokens_details?.reasoning_tokens,
|
|
130
|
+
usage_cache_read: usage?.prompt_tokens_details?.cached_tokens,
|
|
131
|
+
finish_reason: finishReason,
|
|
132
|
+
tools: tools.length > 0 ? tools : undefined,
|
|
133
|
+
text_output: textParts.join("") || undefined,
|
|
134
|
+
latency_total: 0, // filled by caller
|
|
135
|
+
status: "success",
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
function safeParseJSON(value) {
|
|
139
|
+
try {
|
|
140
|
+
return JSON.parse(value);
|
|
141
|
+
}
|
|
142
|
+
catch {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
function isAsyncIterable(value) {
|
|
147
|
+
return value != null && typeof value[Symbol.asyncIterator] === "function";
|
|
148
|
+
}
|
|
149
|
+
function createCompletionsProxy(completions, config, transport) {
|
|
150
|
+
return new Proxy(completions, {
|
|
151
|
+
get(target, prop, receiver) {
|
|
152
|
+
if (prop === "create") {
|
|
153
|
+
return createInterceptedCreate(target, config, transport);
|
|
154
|
+
}
|
|
155
|
+
return Reflect.get(target, prop, receiver);
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
function createInterceptedCreate(completions, config, transport) {
|
|
160
|
+
const originalCreate = completions.create.bind(completions);
|
|
161
|
+
return async function interceptedCreate(...args) {
|
|
162
|
+
if (config.disabled) {
|
|
163
|
+
return originalCreate(...args);
|
|
164
|
+
}
|
|
165
|
+
const promptId = generatePromptId();
|
|
166
|
+
const textInput = extractTextInput(args);
|
|
167
|
+
const params = args[0] ?? {};
|
|
168
|
+
const isStream = params.stream === true;
|
|
169
|
+
const startTime = performance.now();
|
|
170
|
+
try {
|
|
171
|
+
const result = await originalCreate(...args);
|
|
172
|
+
if (isStream && isAsyncIterable(result)) {
|
|
173
|
+
return wrapStreamResponse(result, config, transport, promptId, textInput, startTime);
|
|
174
|
+
}
|
|
175
|
+
// Non-streaming response
|
|
176
|
+
const endTime = performance.now();
|
|
177
|
+
const raw = extractFromResponse(result);
|
|
178
|
+
raw.latency_total = Math.round(endTime - startTime);
|
|
179
|
+
raw.model_requested = params.model;
|
|
180
|
+
raw.config_temperature = params.temperature;
|
|
181
|
+
raw.config_top_p = params.top_p;
|
|
182
|
+
raw.config_max_tokens = params.max_tokens ?? params.max_completion_tokens;
|
|
183
|
+
raw.config_frequency_penalty = params.frequency_penalty;
|
|
184
|
+
raw.config_presence_penalty = params.presence_penalty;
|
|
185
|
+
raw.config_stream = isStream;
|
|
186
|
+
if (config.observabilityLevel === 2 && textInput) {
|
|
187
|
+
raw.text_input = textInput;
|
|
188
|
+
}
|
|
189
|
+
const eventContext = { prompt_id: promptId, sdk_adapter: "openai" };
|
|
190
|
+
const events = buildAllEvents(raw, config, eventContext);
|
|
191
|
+
transport.enqueue(events);
|
|
192
|
+
transport.reportTrace(raw, eventContext);
|
|
193
|
+
transport.reportUserData(raw);
|
|
194
|
+
return result;
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
const endTime = performance.now();
|
|
198
|
+
const raw = {
|
|
199
|
+
model: params.model ?? "unknown",
|
|
200
|
+
model_requested: params.model,
|
|
201
|
+
provider: "openai",
|
|
202
|
+
usage_input: 0,
|
|
203
|
+
usage_output: 0,
|
|
204
|
+
usage_total: 0,
|
|
205
|
+
latency_total: Math.round(endTime - startTime),
|
|
206
|
+
config_temperature: params.temperature,
|
|
207
|
+
config_top_p: params.top_p,
|
|
208
|
+
config_max_tokens: params.max_tokens ?? params.max_completion_tokens,
|
|
209
|
+
config_frequency_penalty: params.frequency_penalty,
|
|
210
|
+
config_presence_penalty: params.presence_penalty,
|
|
211
|
+
config_stream: isStream,
|
|
212
|
+
status: "error",
|
|
213
|
+
error: error?.message ?? String(error),
|
|
214
|
+
};
|
|
215
|
+
if (config.observabilityLevel === 2 && textInput) {
|
|
216
|
+
raw.text_input = textInput;
|
|
217
|
+
}
|
|
218
|
+
const eventContext = { prompt_id: promptId, sdk_adapter: "openai" };
|
|
219
|
+
const events = buildAllEvents(raw, config, eventContext);
|
|
220
|
+
transport.enqueue(events);
|
|
221
|
+
transport.reportError(error, raw);
|
|
222
|
+
throw error;
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function wrapStreamResponse(stream, config, transport, promptId, textInput, startTime) {
|
|
227
|
+
const chunks = [];
|
|
228
|
+
let firstChunkTime;
|
|
229
|
+
function reportSuccess() {
|
|
230
|
+
const endTime = performance.now();
|
|
231
|
+
const raw = extractFromChunks(chunks);
|
|
232
|
+
raw.latency_total = Math.round(endTime - startTime);
|
|
233
|
+
if (firstChunkTime !== undefined) {
|
|
234
|
+
raw.latency_ttft = Math.round(firstChunkTime - startTime);
|
|
235
|
+
}
|
|
236
|
+
raw.config_stream = true;
|
|
237
|
+
if (config.observabilityLevel === 2 && textInput) {
|
|
238
|
+
raw.text_input = textInput;
|
|
239
|
+
}
|
|
240
|
+
const eventContext = { prompt_id: promptId, sdk_adapter: "openai" };
|
|
241
|
+
const events = buildAllEvents(raw, config, eventContext);
|
|
242
|
+
transport.enqueue(events);
|
|
243
|
+
transport.reportTrace(raw, eventContext);
|
|
244
|
+
transport.reportUserData(raw);
|
|
245
|
+
}
|
|
246
|
+
function reportError(error) {
|
|
247
|
+
const endTime = performance.now();
|
|
248
|
+
const raw = {
|
|
249
|
+
model: chunks[0]?.model ?? "unknown",
|
|
250
|
+
provider: "openai",
|
|
251
|
+
usage_input: 0,
|
|
252
|
+
usage_output: 0,
|
|
253
|
+
usage_total: 0,
|
|
254
|
+
latency_total: Math.round(endTime - startTime),
|
|
255
|
+
config_stream: true,
|
|
256
|
+
status: "error",
|
|
257
|
+
error: error?.message ?? String(error),
|
|
258
|
+
};
|
|
259
|
+
if (firstChunkTime !== undefined) {
|
|
260
|
+
raw.latency_ttft = Math.round(firstChunkTime - startTime);
|
|
261
|
+
}
|
|
262
|
+
if (config.observabilityLevel === 2 && textInput) {
|
|
263
|
+
raw.text_input = textInput;
|
|
264
|
+
}
|
|
265
|
+
const eventContext = { prompt_id: promptId, sdk_adapter: "openai" };
|
|
266
|
+
const events = buildAllEvents(raw, config, eventContext);
|
|
267
|
+
transport.enqueue(events);
|
|
268
|
+
transport.reportError(error, raw);
|
|
269
|
+
}
|
|
270
|
+
// Use a Proxy to preserve the original Stream class interface (controller, tee,
|
|
271
|
+
// toReadableStream) while intercepting only async iteration to collect metrics.
|
|
272
|
+
return new Proxy(stream, {
|
|
273
|
+
get(target, prop, receiver) {
|
|
274
|
+
if (prop === Symbol.asyncIterator) {
|
|
275
|
+
return function () {
|
|
276
|
+
const originalIterator = target[Symbol.asyncIterator]();
|
|
277
|
+
return {
|
|
278
|
+
async next() {
|
|
279
|
+
try {
|
|
280
|
+
const result = await originalIterator.next();
|
|
281
|
+
if (result.done) {
|
|
282
|
+
reportSuccess();
|
|
283
|
+
return result;
|
|
284
|
+
}
|
|
285
|
+
if (firstChunkTime === undefined) {
|
|
286
|
+
firstChunkTime = performance.now();
|
|
287
|
+
}
|
|
288
|
+
chunks.push(result.value);
|
|
289
|
+
return result;
|
|
290
|
+
}
|
|
291
|
+
catch (error) {
|
|
292
|
+
reportError(error);
|
|
293
|
+
throw error;
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
async return(value) {
|
|
297
|
+
if (originalIterator.return) {
|
|
298
|
+
return originalIterator.return(value);
|
|
299
|
+
}
|
|
300
|
+
return { done: true, value: undefined };
|
|
301
|
+
},
|
|
302
|
+
async throw(error) {
|
|
303
|
+
if (originalIterator.throw) {
|
|
304
|
+
return originalIterator.throw(error);
|
|
305
|
+
}
|
|
306
|
+
throw error;
|
|
307
|
+
},
|
|
308
|
+
};
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
return Reflect.get(target, prop, receiver);
|
|
312
|
+
},
|
|
313
|
+
});
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Wraps an OpenAI client with Countly AI observability.
|
|
317
|
+
*
|
|
318
|
+
* Uses JS Proxy to intercept `client.chat.completions.create()` calls
|
|
319
|
+
* and automatically track LLM interactions, token usage, costs, and latency.
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* ```ts
|
|
323
|
+
* import OpenAI from "openai";
|
|
324
|
+
* import { observeOpenAI } from "@countly/ai-sdk-openai";
|
|
325
|
+
*
|
|
326
|
+
* const client = observeOpenAI(new OpenAI(), {
|
|
327
|
+
* appKey: "YOUR_APP_KEY",
|
|
328
|
+
* url: "https://your-countly-server.com",
|
|
329
|
+
* });
|
|
330
|
+
*
|
|
331
|
+
* // Use client as normal — all calls are automatically tracked
|
|
332
|
+
* const response = await client.chat.completions.create({ ... });
|
|
333
|
+
* ```
|
|
334
|
+
*/
|
|
335
|
+
export function observeOpenAI(client, options) {
|
|
336
|
+
const config = resolveConfig(options);
|
|
337
|
+
const transport = createTransport(config);
|
|
338
|
+
return new Proxy(client, {
|
|
339
|
+
get(target, prop, receiver) {
|
|
340
|
+
if (prop === "chat") {
|
|
341
|
+
const chat = Reflect.get(target, prop, receiver);
|
|
342
|
+
return new Proxy(chat, {
|
|
343
|
+
get(chatTarget, chatProp, chatReceiver) {
|
|
344
|
+
if (chatProp === "completions") {
|
|
345
|
+
const completions = Reflect.get(chatTarget, chatProp, chatReceiver);
|
|
346
|
+
return createCompletionsProxy(completions, config, transport);
|
|
347
|
+
}
|
|
348
|
+
return Reflect.get(chatTarget, chatProp, chatReceiver);
|
|
349
|
+
},
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
return Reflect.get(target, prop, receiver);
|
|
353
|
+
},
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
//# sourceMappingURL=adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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,MAAM,GAAG,aAAa,CAAC,OAAO,CAAC,CAAC;IACtC,MAAM,SAAS,GAAG,eAAe,CAAC,MAAM,CAAC,CAAC;IAE1C,OAAO,IAAI,KAAK,CAAC,MAAa,EAAE;QAC9B,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ;YACxB,IAAI,IAAI,KAAK,MAAM,EAAE,CAAC;gBACpB,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;gBACjD,OAAO,IAAI,KAAK,CAAC,IAAI,EAAE;oBACrB,GAAG,CAAC,UAAU,EAAE,QAAQ,EAAE,YAAY;wBACpC,IAAI,QAAQ,KAAK,aAAa,EAAE,CAAC;4BAC/B,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAC7B,UAAU,EACV,QAAQ,EACR,YAAY,CACb,CAAC;4BACF,OAAO,sBAAsB,CAAC,WAAW,EAAE,MAAM,EAAE,SAAS,CAAC,CAAC;wBAChE,CAAC;wBACD,OAAO,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;oBACzD,CAAC;iBACF,CAAC,CAAC;YACL,CAAC;YACD,OAAO,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC;QAC7C,CAAC;KACF,CAAM,CAAC;AACV,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAC1C,YAAY,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@countly/ai-sdk-openai",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"description": "Countly AI observability adapter for OpenAI SDK",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"exports": {
|
|
7
|
+
".": {
|
|
8
|
+
"import": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts"
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"peerDependencies": {
|
|
19
|
+
"openai": ">=4.68.0"
|
|
20
|
+
},
|
|
21
|
+
"peerDependenciesMeta": {
|
|
22
|
+
"openai": {
|
|
23
|
+
"optional": false
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@countly/ai-sdk-core": "0.0.3"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"typescript": "^5.8.3",
|
|
31
|
+
"@countly/ai-sdk-tsconfig": "0.0.0"
|
|
32
|
+
},
|
|
33
|
+
"scripts": {
|
|
34
|
+
"build": "tsc --project tsconfig.build.json",
|
|
35
|
+
"dev": "tsc --project tsconfig.build.json --watch",
|
|
36
|
+
"lint": "tsc --noEmit",
|
|
37
|
+
"test": "vitest run"
|
|
38
|
+
}
|
|
39
|
+
}
|