@paid-ai/paid-node 0.0.8-alpha1 → 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 +48 -46
  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 +44 -42
  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 {
@@ -97,22 +97,24 @@ class ResponsesWrapper {
97
97
  return __awaiter(this, void 0, void 0, function* () {
98
98
  const currentSpan = trace.getSpan(context.active());
99
99
  if (!currentSpan) {
100
- console.warn("No active span found, calling OpenAI directly without tracing.");
101
- 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().");
102
101
  }
103
- const externalCustomerId = getCustomerId();
102
+ const externalCustomerId = getCustomerIdStorage();
103
+ const externalAgentId = getAgentIdStorage();
104
104
  const token = getTokenStorage();
105
+ if (!token || !externalCustomerId) {
106
+ throw new Error("No token or externalCustomerId: This wrapper should be used inside a callback to paid.trace().");
107
+ }
105
108
  return this.tracer.startActiveSpan("trace.openai.responses", (span) => __awaiter(this, void 0, void 0, function* () {
106
109
  var _a, _b;
107
110
  const attributes = {
108
111
  "gen_ai.system": "openai",
109
112
  "gen_ai.operation.name": "chat", // Equivalent to chat.completions
110
113
  };
111
- if (externalCustomerId) {
112
- attributes["external_customer_id"] = externalCustomerId;
113
- }
114
- if (token) {
115
- attributes["token"] = token;
114
+ attributes["external_customer_id"] = externalCustomerId;
115
+ attributes["token"] = token;
116
+ if (externalAgentId) {
117
+ attributes["external_agent_id"] = externalAgentId;
116
118
  }
117
119
  span.setAttributes(attributes);
118
120
  try {
@@ -152,26 +154,25 @@ class EmbeddingsWrapper {
152
154
  }
153
155
  create(params) {
154
156
  return __awaiter(this, void 0, void 0, function* () {
155
- var _a;
156
157
  const currentSpan = trace.getSpan(context.active());
157
158
  if (!currentSpan) {
158
- console.warn("No active span found, calling OpenAI directly without tracing.");
159
- 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().");
160
160
  }
161
- const externalCustomerId = getCustomerId();
161
+ const externalCustomerId = getCustomerIdStorage();
162
+ const externalAgentId = getAgentIdStorage();
162
163
  const token = getTokenStorage();
163
- const model = (_a = params.model) !== null && _a !== void 0 ? _a : "unknown";
164
- const spanName = `trace.embeddings ${model}`;
165
- 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* () {
166
168
  const attributes = {
167
169
  "gen_ai.system": "openai",
168
170
  "gen_ai.operation.name": "embeddings",
169
171
  };
170
- if (externalCustomerId) {
171
- attributes["external_customer_id"] = externalCustomerId;
172
- }
173
- if (token) {
174
- attributes["token"] = token;
172
+ attributes["external_customer_id"] = externalCustomerId;
173
+ attributes["token"] = token;
174
+ if (externalAgentId) {
175
+ attributes["external_agent_id"] = externalAgentId;
175
176
  }
176
177
  span.setAttributes(attributes);
177
178
  try {
@@ -207,25 +208,26 @@ class ImagesWrapper {
207
208
  var _a;
208
209
  const currentSpan = trace.getSpan(context.active());
209
210
  if (!currentSpan) {
210
- console.warn("No active span found, calling OpenAI directly without tracing.");
211
- 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().");
212
212
  }
213
- const externalCustomerId = getCustomerId();
213
+ const externalCustomerId = getCustomerIdStorage();
214
+ const externalAgentId = getAgentIdStorage();
214
215
  const token = getTokenStorage();
215
216
  const model = (_a = params.model) !== null && _a !== void 0 ? _a : "dall-e-3";
216
- const spanName = `trace.images ${model}`;
217
- 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* () {
218
221
  var _a, _b, _c;
219
222
  const attributes = {
220
223
  "gen_ai.request.model": model,
221
224
  "gen_ai.system": "openai",
222
225
  "gen_ai.operation.name": "image_generation",
223
226
  };
224
- if (externalCustomerId) {
225
- attributes["external_customer_id"] = externalCustomerId;
226
- }
227
- if (token) {
228
- attributes["token"] = token;
227
+ attributes["external_customer_id"] = externalCustomerId;
228
+ attributes["token"] = token;
229
+ if (externalAgentId) {
230
+ attributes["external_agent_id"] = externalAgentId;
229
231
  }
230
232
  span.setAttributes(attributes);
231
233
  try {
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.0.8-alpha1";
1
+ export declare const SDK_VERSION = "0.0.8-alpha2";
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.0.8-alpha1";
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-alpha1",
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";