@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.
Files changed (44) hide show
  1. package/README.md +17 -16
  2. package/dist/cjs/Client.d.ts +4 -2
  3. package/dist/cjs/Client.js +21 -4
  4. package/dist/cjs/index.d.ts +3 -1
  5. package/dist/cjs/index.js +7 -4
  6. package/dist/cjs/tracing/signal.d.ts +1 -0
  7. package/dist/cjs/tracing/signal.js +49 -0
  8. package/dist/cjs/tracing/tracing.d.ts +8 -3
  9. package/dist/cjs/tracing/tracing.js +100 -28
  10. package/dist/cjs/tracing/wrappers/anthropicWrapper.d.ts +16 -0
  11. package/dist/cjs/tracing/wrappers/anthropicWrapper.js +88 -0
  12. package/dist/cjs/tracing/wrappers/langchainCallback.d.ts +21 -0
  13. package/dist/cjs/tracing/wrappers/langchainCallback.js +146 -0
  14. package/dist/cjs/tracing/wrappers/mistralWrapper.d.ts +17 -0
  15. package/dist/cjs/tracing/wrappers/mistralWrapper.js +85 -0
  16. package/dist/cjs/tracing/wrappers/openAiWrapper.js +58 -52
  17. package/dist/cjs/version.d.ts +1 -1
  18. package/dist/cjs/version.js +1 -1
  19. package/dist/cjs/wrapper/BatchUsage.d.ts +1 -1
  20. package/dist/cjs/wrapper/BatchUsage.js +2 -2
  21. package/dist/esm/Client.d.mts +4 -2
  22. package/dist/esm/Client.mjs +22 -5
  23. package/dist/esm/index.d.mts +3 -1
  24. package/dist/esm/index.mjs +3 -1
  25. package/dist/esm/tracing/signal.d.mts +1 -0
  26. package/dist/esm/tracing/signal.mjs +46 -0
  27. package/dist/esm/tracing/tracing.d.mts +8 -3
  28. package/dist/esm/tracing/tracing.mjs +94 -27
  29. package/dist/esm/tracing/wrappers/anthropicWrapper.d.mts +16 -0
  30. package/dist/esm/tracing/wrappers/anthropicWrapper.mjs +84 -0
  31. package/dist/esm/tracing/wrappers/langchainCallback.d.mts +21 -0
  32. package/dist/esm/tracing/wrappers/langchainCallback.mjs +142 -0
  33. package/dist/esm/tracing/wrappers/mistralWrapper.d.mts +17 -0
  34. package/dist/esm/tracing/wrappers/mistralWrapper.mjs +81 -0
  35. package/dist/esm/tracing/wrappers/openAiWrapper.mjs +54 -48
  36. package/dist/esm/version.d.mts +1 -1
  37. package/dist/esm/version.mjs +1 -1
  38. package/dist/esm/wrapper/BatchUsage.d.mts +1 -1
  39. package/dist/esm/wrapper/BatchUsage.mjs +1 -1
  40. package/package.json +7 -3
  41. package/dist/cjs/tracing/index.d.ts +0 -1
  42. package/dist/cjs/tracing/index.js +0 -17
  43. package/dist/esm/tracing/index.d.mts +0 -1
  44. 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 { getCustomerId, getTokenStorage } from "../tracing";
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
- console.warn("No active span found, calling OpenAI directly without tracing.");
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 = getCustomerId();
50
+ const externalCustomerId = getCustomerIdStorage();
51
+ const externalAgentId = getAgentIdStorage();
52
52
  const token = getTokenStorage();
53
- const model = params.model;
54
- const spanName = `trace.chat ${model}`;
55
- return this.tracer.startActiveSpan(spanName, (span) => __awaiter(this, void 0, void 0, function* () {
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
- if (externalCustomerId) {
61
- attributes["external_customer_id"] = externalCustomerId;
62
- }
63
- if (token) {
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
- console.warn("No active span found, calling OpenAI directly without tracing.");
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 = getCustomerId();
102
+ const externalCustomerId = getCustomerIdStorage();
103
+ const externalAgentId = getAgentIdStorage();
105
104
  const token = getTokenStorage();
106
- const model = (_a = params.model) !== null && _a !== void 0 ? _a : "unknown";
107
- const spanName = `trace.responses ${model}`;
108
- return this.tracer.startActiveSpan(spanName, (span) => __awaiter(this, void 0, void 0, function* () {
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
- if (externalCustomerId) {
114
- attributes["external_customer_id"] = externalCustomerId;
115
- }
116
- if (token) {
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.prompt_tokens,
125
- "gen_ai.usage.output_tokens": response.usage.completion_tokens,
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
- console.warn("No active span found, calling OpenAI directly without tracing.");
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 = getCustomerId();
161
+ const externalCustomerId = getCustomerIdStorage();
162
+ const externalAgentId = getAgentIdStorage();
158
163
  const token = getTokenStorage();
159
- const model = (_a = params.model) !== null && _a !== void 0 ? _a : "unknown";
160
- const spanName = `trace.embeddings ${model}`;
161
- return this.tracer.startActiveSpan(spanName, (span) => __awaiter(this, void 0, void 0, function* () {
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
- if (externalCustomerId) {
167
- attributes["external_customer_id"] = externalCustomerId;
168
- }
169
- if (token) {
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
- console.warn("No active span found, calling OpenAI directly without tracing.");
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 = getCustomerId();
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
- const spanName = `trace.images ${model}`;
213
- return this.tracer.startActiveSpan(spanName, (span) => __awaiter(this, void 0, void 0, function* () {
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
- if (externalCustomerId) {
221
- attributes["external_customer_id"] = externalCustomerId;
222
- }
223
- if (token) {
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 {
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.0.8-alpha0";
1
+ export declare const SDK_VERSION = "0.0.8-alpha2";
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.0.8-alpha0";
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-alpha0",
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";