@paid-ai/paid-node 0.0.8-alpha0 → 0.0.8-alpha2
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 +17 -16
- package/dist/cjs/Client.d.ts +4 -2
- package/dist/cjs/Client.js +21 -4
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/index.js +7 -4
- package/dist/cjs/tracing/signal.d.ts +1 -0
- package/dist/cjs/tracing/signal.js +49 -0
- package/dist/cjs/tracing/tracing.d.ts +8 -3
- package/dist/cjs/tracing/tracing.js +100 -28
- package/dist/cjs/tracing/wrappers/anthropicWrapper.d.ts +16 -0
- package/dist/cjs/tracing/wrappers/anthropicWrapper.js +88 -0
- package/dist/cjs/tracing/wrappers/langchainCallback.d.ts +21 -0
- package/dist/cjs/tracing/wrappers/langchainCallback.js +146 -0
- package/dist/cjs/tracing/wrappers/mistralWrapper.d.ts +17 -0
- package/dist/cjs/tracing/wrappers/mistralWrapper.js +85 -0
- package/dist/cjs/tracing/wrappers/openAiWrapper.js +58 -52
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wrapper/BatchUsage.d.ts +1 -1
- package/dist/cjs/wrapper/BatchUsage.js +2 -2
- package/dist/esm/Client.d.mts +4 -2
- package/dist/esm/Client.mjs +22 -5
- package/dist/esm/index.d.mts +3 -1
- package/dist/esm/index.mjs +3 -1
- package/dist/esm/tracing/signal.d.mts +1 -0
- package/dist/esm/tracing/signal.mjs +46 -0
- package/dist/esm/tracing/tracing.d.mts +8 -3
- package/dist/esm/tracing/tracing.mjs +94 -27
- package/dist/esm/tracing/wrappers/anthropicWrapper.d.mts +16 -0
- package/dist/esm/tracing/wrappers/anthropicWrapper.mjs +84 -0
- package/dist/esm/tracing/wrappers/langchainCallback.d.mts +21 -0
- package/dist/esm/tracing/wrappers/langchainCallback.mjs +142 -0
- package/dist/esm/tracing/wrappers/mistralWrapper.d.mts +17 -0
- package/dist/esm/tracing/wrappers/mistralWrapper.mjs +81 -0
- package/dist/esm/tracing/wrappers/openAiWrapper.mjs +54 -48
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/dist/esm/wrapper/BatchUsage.d.mts +1 -1
- package/dist/esm/wrapper/BatchUsage.mjs +1 -1
- package/package.json +7 -3
- package/dist/cjs/tracing/index.d.ts +0 -1
- package/dist/cjs/tracing/index.js +0 -17
- package/dist/esm/tracing/index.d.mts +0 -1
- package/dist/esm/tracing/index.mjs +0 -1
|
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { trace, SpanStatusCode, context } from "@opentelemetry/api";
|
|
11
|
-
import {
|
|
11
|
+
import { getCustomerIdStorage, getAgentIdStorage, getTokenStorage } from "../tracing.mjs";
|
|
12
12
|
export class PaidOpenAI {
|
|
13
13
|
constructor(openaiClient) {
|
|
14
14
|
this.openai = openaiClient;
|
|
@@ -45,23 +45,23 @@ class ChatCompletionsWrapper {
|
|
|
45
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
46
|
const currentSpan = trace.getSpan(context.active());
|
|
47
47
|
if (!currentSpan) {
|
|
48
|
-
|
|
49
|
-
return this.openai.chat.completions.create(params);
|
|
48
|
+
throw new Error("No active span found, make sure to call this inside of a callback to paid.trace().");
|
|
50
49
|
}
|
|
51
|
-
const externalCustomerId =
|
|
50
|
+
const externalCustomerId = getCustomerIdStorage();
|
|
51
|
+
const externalAgentId = getAgentIdStorage();
|
|
52
52
|
const token = getTokenStorage();
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
if (!token || !externalCustomerId) {
|
|
54
|
+
throw new Error("No token or externalCustomerId: This wrapper should be used inside a callback to paid.trace().");
|
|
55
|
+
}
|
|
56
|
+
return this.tracer.startActiveSpan("trace.openai.chat", (span) => __awaiter(this, void 0, void 0, function* () {
|
|
56
57
|
const attributes = {
|
|
57
58
|
"gen_ai.system": "openai",
|
|
58
59
|
"gen_ai.operation.name": "chat",
|
|
59
60
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
attributes["token"] = token;
|
|
61
|
+
attributes["external_customer_id"] = externalCustomerId;
|
|
62
|
+
attributes["token"] = token;
|
|
63
|
+
if (externalAgentId) {
|
|
64
|
+
attributes["external_agent_id"] = externalAgentId;
|
|
65
65
|
}
|
|
66
66
|
span.setAttributes(attributes);
|
|
67
67
|
try {
|
|
@@ -95,36 +95,42 @@ class ResponsesWrapper {
|
|
|
95
95
|
}
|
|
96
96
|
create(params) {
|
|
97
97
|
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
var _a;
|
|
99
98
|
const currentSpan = trace.getSpan(context.active());
|
|
100
99
|
if (!currentSpan) {
|
|
101
|
-
|
|
102
|
-
return this.openai.responses.create(params);
|
|
100
|
+
throw new Error("No active span found, make sure to call this inside of a callback to paid.trace().");
|
|
103
101
|
}
|
|
104
|
-
const externalCustomerId =
|
|
102
|
+
const externalCustomerId = getCustomerIdStorage();
|
|
103
|
+
const externalAgentId = getAgentIdStorage();
|
|
105
104
|
const token = getTokenStorage();
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
if (!token || !externalCustomerId) {
|
|
106
|
+
throw new Error("No token or externalCustomerId: This wrapper should be used inside a callback to paid.trace().");
|
|
107
|
+
}
|
|
108
|
+
return this.tracer.startActiveSpan("trace.openai.responses", (span) => __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
var _a, _b;
|
|
109
110
|
const attributes = {
|
|
110
111
|
"gen_ai.system": "openai",
|
|
111
112
|
"gen_ai.operation.name": "chat", // Equivalent to chat.completions
|
|
112
113
|
};
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
attributes["token"] = token;
|
|
114
|
+
attributes["external_customer_id"] = externalCustomerId;
|
|
115
|
+
attributes["token"] = token;
|
|
116
|
+
if (externalAgentId) {
|
|
117
|
+
attributes["external_agent_id"] = externalAgentId;
|
|
118
118
|
}
|
|
119
119
|
span.setAttributes(attributes);
|
|
120
120
|
try {
|
|
121
121
|
const response = yield this.openai.responses.create(params);
|
|
122
122
|
if (response.usage) {
|
|
123
123
|
span.setAttributes({
|
|
124
|
-
"gen_ai.usage.input_tokens": response.usage.
|
|
125
|
-
"gen_ai.usage.output_tokens": response.usage.
|
|
124
|
+
"gen_ai.usage.input_tokens": response.usage.input_tokens,
|
|
125
|
+
"gen_ai.usage.output_tokens": response.usage.output_tokens,
|
|
126
126
|
"gen_ai.response.model": response.model,
|
|
127
127
|
});
|
|
128
|
+
if ((_a = response.usage.input_tokens_details) === null || _a === void 0 ? void 0 : _a.cached_tokens) {
|
|
129
|
+
span.setAttribute("gen_ai.usage.cached_input_tokens", response.usage.input_tokens_details.cached_tokens);
|
|
130
|
+
}
|
|
131
|
+
if ((_b = response.usage.output_tokens_details) === null || _b === void 0 ? void 0 : _b.reasoning_tokens) {
|
|
132
|
+
span.setAttribute("gen_ai.usage.reasoning_output_tokens", response.usage.output_tokens_details.reasoning_tokens);
|
|
133
|
+
}
|
|
128
134
|
}
|
|
129
135
|
span.setStatus({ code: SpanStatusCode.OK });
|
|
130
136
|
return response;
|
|
@@ -148,26 +154,25 @@ class EmbeddingsWrapper {
|
|
|
148
154
|
}
|
|
149
155
|
create(params) {
|
|
150
156
|
return __awaiter(this, void 0, void 0, function* () {
|
|
151
|
-
var _a;
|
|
152
157
|
const currentSpan = trace.getSpan(context.active());
|
|
153
158
|
if (!currentSpan) {
|
|
154
|
-
|
|
155
|
-
return this.openai.embeddings.create(params);
|
|
159
|
+
throw new Error("No active span found, make sure to call this inside of a callback to paid.trace().");
|
|
156
160
|
}
|
|
157
|
-
const externalCustomerId =
|
|
161
|
+
const externalCustomerId = getCustomerIdStorage();
|
|
162
|
+
const externalAgentId = getAgentIdStorage();
|
|
158
163
|
const token = getTokenStorage();
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
164
|
+
if (!token || !externalCustomerId) {
|
|
165
|
+
throw new Error("No token or externalCustomerId: This wrapper should be used inside a callback to paid.trace().");
|
|
166
|
+
}
|
|
167
|
+
return this.tracer.startActiveSpan("trace.openai.embeddings", (span) => __awaiter(this, void 0, void 0, function* () {
|
|
162
168
|
const attributes = {
|
|
163
169
|
"gen_ai.system": "openai",
|
|
164
170
|
"gen_ai.operation.name": "embeddings",
|
|
165
171
|
};
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
attributes["token"] = token;
|
|
172
|
+
attributes["external_customer_id"] = externalCustomerId;
|
|
173
|
+
attributes["token"] = token;
|
|
174
|
+
if (externalAgentId) {
|
|
175
|
+
attributes["external_agent_id"] = externalAgentId;
|
|
171
176
|
}
|
|
172
177
|
span.setAttributes(attributes);
|
|
173
178
|
try {
|
|
@@ -203,25 +208,26 @@ class ImagesWrapper {
|
|
|
203
208
|
var _a;
|
|
204
209
|
const currentSpan = trace.getSpan(context.active());
|
|
205
210
|
if (!currentSpan) {
|
|
206
|
-
|
|
207
|
-
return this.openai.images.generate(params);
|
|
211
|
+
throw new Error("No active span found, make sure to call this inside of a callback to paid.trace().");
|
|
208
212
|
}
|
|
209
|
-
const externalCustomerId =
|
|
213
|
+
const externalCustomerId = getCustomerIdStorage();
|
|
214
|
+
const externalAgentId = getAgentIdStorage();
|
|
210
215
|
const token = getTokenStorage();
|
|
211
216
|
const model = (_a = params.model) !== null && _a !== void 0 ? _a : "dall-e-3";
|
|
212
|
-
|
|
213
|
-
|
|
217
|
+
if (!token || !externalCustomerId) {
|
|
218
|
+
throw new Error("No token or externalCustomerId: This wrapper should be used inside a callback to paid.trace().");
|
|
219
|
+
}
|
|
220
|
+
return this.tracer.startActiveSpan("trace.openai.images", (span) => __awaiter(this, void 0, void 0, function* () {
|
|
214
221
|
var _a, _b, _c;
|
|
215
222
|
const attributes = {
|
|
216
223
|
"gen_ai.request.model": model,
|
|
217
224
|
"gen_ai.system": "openai",
|
|
218
225
|
"gen_ai.operation.name": "image_generation",
|
|
219
226
|
};
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
attributes["token"] = token;
|
|
227
|
+
attributes["external_customer_id"] = externalCustomerId;
|
|
228
|
+
attributes["token"] = token;
|
|
229
|
+
if (externalAgentId) {
|
|
230
|
+
attributes["external_agent_id"] = externalAgentId;
|
|
225
231
|
}
|
|
226
232
|
span.setAttributes(attributes);
|
|
227
233
|
try {
|
package/dist/esm/version.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.0.8-
|
|
1
|
+
export declare const SDK_VERSION = "0.0.8-alpha2";
|
package/dist/esm/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.0.8-
|
|
1
|
+
export const SDK_VERSION = "0.0.8-alpha2";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as core from "../core/index.mjs";
|
|
2
|
-
import { Usage as UsageClient } from "../api/resources/usage/client/Client";
|
|
2
|
+
import { Usage as UsageClient } from "../api/resources/usage/client/Client.mjs";
|
|
3
3
|
import * as Paid from "../api/types/Signal.mjs";
|
|
4
4
|
export declare class Usage extends UsageClient {
|
|
5
5
|
private signals;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as core from "../core/index.mjs";
|
|
2
|
-
import { Usage as UsageClient } from "../api/resources/usage/client/Client";
|
|
2
|
+
import { Usage as UsageClient } from "../api/resources/usage/client/Client.mjs";
|
|
3
3
|
export class Usage extends UsageClient {
|
|
4
4
|
constructor() {
|
|
5
5
|
super(...arguments);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paid-ai/paid-node",
|
|
3
|
-
"version": "0.0.8-
|
|
3
|
+
"version": "0.0.8-alpha2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"repository": "https://github.com/AgentPaid/paid-node",
|
|
6
6
|
"type": "commonjs",
|
|
@@ -36,17 +36,21 @@
|
|
|
36
36
|
"wire:test": "yarn test:wire"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
+
"@anthropic-ai/sdk": "^0.56.0",
|
|
40
|
+
"@langchain/core": "^0.3.64",
|
|
41
|
+
"@mistralai/mistralai": "^1.7.4",
|
|
39
42
|
"@opentelemetry/api": "^1.9.0",
|
|
40
43
|
"@opentelemetry/exporter-trace-otlp-http": "^0.202.0",
|
|
41
44
|
"@opentelemetry/sdk-node": "^0.202.0",
|
|
42
|
-
"openai": "^5.5.1",
|
|
43
45
|
"form-data": "^4.0.0",
|
|
44
46
|
"formdata-node": "^6.0.3",
|
|
45
47
|
"js-base64": "3.7.7",
|
|
46
48
|
"node-fetch": "^2.7.0",
|
|
49
|
+
"openai": "^5.5.1",
|
|
47
50
|
"qs": "^6.13.1",
|
|
48
51
|
"readable-stream": "^4.5.2",
|
|
49
|
-
"url-join": "4.0.1"
|
|
52
|
+
"url-join": "4.0.1",
|
|
53
|
+
"winston": "^3.17.0"
|
|
50
54
|
},
|
|
51
55
|
"devDependencies": {
|
|
52
56
|
"@jest/globals": "^29.7.0",
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./wrappers/openAiWrapper";
|
|
@@ -1,17 +0,0 @@
|
|
|
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("./wrappers/openAiWrapper"), exports);
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./wrappers/openAiWrapper";
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from "./wrappers/openAiWrapper";
|