@paid-ai/paid-node 0.0.8 → 0.2.1

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 (116) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +263 -11
  3. package/dist/cjs/Client.d.ts +22 -0
  4. package/dist/cjs/Client.js +45 -2
  5. package/dist/cjs/anthropic-wrapper/index.d.ts +1 -0
  6. package/dist/cjs/anthropic-wrapper/index.js +5 -0
  7. package/dist/cjs/api/resources/agents/client/Client.d.ts +52 -4
  8. package/dist/cjs/api/resources/agents/client/Client.js +52 -4
  9. package/dist/cjs/api/resources/agents/client/requests/AgentCreate.d.ts +4 -2
  10. package/dist/cjs/api/resources/contacts/client/Client.d.ts +4 -7
  11. package/dist/cjs/api/resources/contacts/client/Client.js +4 -7
  12. package/dist/cjs/api/resources/contacts/client/requests/ContactCreate.d.ts +8 -11
  13. package/dist/cjs/api/resources/customers/client/Client.d.ts +8 -2
  14. package/dist/cjs/api/resources/customers/client/Client.js +8 -2
  15. package/dist/cjs/api/resources/customers/client/requests/CustomerCreate.d.ts +2 -1
  16. package/dist/cjs/api/resources/orders/client/Client.d.ts +6 -5
  17. package/dist/cjs/api/resources/orders/client/Client.js +6 -5
  18. package/dist/cjs/api/resources/orders/client/requests/OrderCreate.d.ts +8 -7
  19. package/dist/cjs/api/resources/orders/resources/lines/client/Client.d.ts +11 -1
  20. package/dist/cjs/api/resources/orders/resources/lines/client/Client.js +11 -1
  21. package/dist/cjs/api/resources/orders/resources/lines/client/requests/LinesUpdateRequest.d.ts +11 -1
  22. package/dist/cjs/api/resources/usage/client/Client.d.ts +4 -2
  23. package/dist/cjs/api/resources/usage/client/Client.js +4 -2
  24. package/dist/cjs/api/resources/usage/client/requests/UsageRecordBulkRequest.d.ts +3 -1
  25. package/dist/cjs/api/types/BillingFrequency.d.ts +4 -4
  26. package/dist/cjs/api/types/BillingFrequency.js +3 -3
  27. package/dist/cjs/api/types/Pricing.d.ts +1 -0
  28. package/dist/cjs/api/types/PricingModelType.d.ts +2 -1
  29. package/dist/cjs/api/types/PricingModelType.js +1 -0
  30. package/dist/cjs/api/types/Signal.d.ts +1 -0
  31. package/dist/cjs/index.d.ts +1 -1
  32. package/dist/cjs/index.js +3 -3
  33. package/dist/cjs/langchain-wrapper/index.d.ts +1 -0
  34. package/dist/cjs/langchain-wrapper/index.js +5 -0
  35. package/dist/cjs/mistral-wrapper/index.d.ts +1 -0
  36. package/dist/cjs/mistral-wrapper/index.js +5 -0
  37. package/dist/cjs/openai-wrapper/index.d.ts +1 -0
  38. package/dist/cjs/openai-wrapper/index.js +5 -0
  39. package/dist/cjs/tracing/signal.d.ts +1 -0
  40. package/dist/cjs/tracing/signal.js +54 -0
  41. package/dist/cjs/tracing/tracing.d.ts +8 -0
  42. package/dist/cjs/tracing/tracing.js +127 -0
  43. package/dist/cjs/tracing/wrappers/anthropicWrapper.d.ts +16 -0
  44. package/dist/cjs/tracing/wrappers/anthropicWrapper.js +84 -0
  45. package/dist/cjs/tracing/wrappers/langchainCallback.d.ts +21 -0
  46. package/dist/cjs/tracing/wrappers/langchainCallback.js +142 -0
  47. package/dist/cjs/tracing/wrappers/mistralWrapper.d.ts +17 -0
  48. package/dist/cjs/tracing/wrappers/mistralWrapper.js +81 -0
  49. package/dist/cjs/tracing/wrappers/openAiWrapper.d.ts +48 -0
  50. package/dist/cjs/tracing/wrappers/openAiWrapper.js +241 -0
  51. package/dist/cjs/tracing/wrappers/vercelAIWrapper.d.ts +22 -0
  52. package/dist/cjs/tracing/wrappers/vercelAIWrapper.js +327 -0
  53. package/dist/cjs/vercel-wrapper/index.d.ts +1 -0
  54. package/dist/cjs/vercel-wrapper/index.js +10 -0
  55. package/dist/cjs/version.d.ts +1 -1
  56. package/dist/cjs/version.js +1 -1
  57. package/dist/cjs/wrapper/BatchUsage.d.ts +3 -3
  58. package/dist/cjs/wrapper/BatchUsage.js +4 -4
  59. package/dist/esm/Client.d.mts +22 -0
  60. package/dist/esm/Client.mjs +45 -2
  61. package/dist/esm/anthropic-wrapper/index.d.mts +1 -0
  62. package/dist/esm/anthropic-wrapper/index.mjs +1 -0
  63. package/dist/esm/api/resources/agents/client/Client.d.mts +52 -4
  64. package/dist/esm/api/resources/agents/client/Client.mjs +52 -4
  65. package/dist/esm/api/resources/agents/client/requests/AgentCreate.d.mts +4 -2
  66. package/dist/esm/api/resources/contacts/client/Client.d.mts +4 -7
  67. package/dist/esm/api/resources/contacts/client/Client.mjs +4 -7
  68. package/dist/esm/api/resources/contacts/client/requests/ContactCreate.d.mts +8 -11
  69. package/dist/esm/api/resources/customers/client/Client.d.mts +8 -2
  70. package/dist/esm/api/resources/customers/client/Client.mjs +8 -2
  71. package/dist/esm/api/resources/customers/client/requests/CustomerCreate.d.mts +2 -1
  72. package/dist/esm/api/resources/orders/client/Client.d.mts +6 -5
  73. package/dist/esm/api/resources/orders/client/Client.mjs +6 -5
  74. package/dist/esm/api/resources/orders/client/requests/OrderCreate.d.mts +8 -7
  75. package/dist/esm/api/resources/orders/resources/lines/client/Client.d.mts +11 -1
  76. package/dist/esm/api/resources/orders/resources/lines/client/Client.mjs +11 -1
  77. package/dist/esm/api/resources/orders/resources/lines/client/requests/LinesUpdateRequest.d.mts +11 -1
  78. package/dist/esm/api/resources/usage/client/Client.d.mts +4 -2
  79. package/dist/esm/api/resources/usage/client/Client.mjs +4 -2
  80. package/dist/esm/api/resources/usage/client/requests/UsageRecordBulkRequest.d.mts +3 -1
  81. package/dist/esm/api/types/BillingFrequency.d.mts +4 -4
  82. package/dist/esm/api/types/BillingFrequency.mjs +3 -3
  83. package/dist/esm/api/types/Pricing.d.mts +1 -0
  84. package/dist/esm/api/types/PricingModelType.d.mts +2 -1
  85. package/dist/esm/api/types/PricingModelType.mjs +1 -0
  86. package/dist/esm/api/types/Signal.d.mts +1 -0
  87. package/dist/esm/index.d.mts +1 -1
  88. package/dist/esm/index.mjs +1 -1
  89. package/dist/esm/langchain-wrapper/index.d.mts +1 -0
  90. package/dist/esm/langchain-wrapper/index.mjs +1 -0
  91. package/dist/esm/mistral-wrapper/index.d.mts +1 -0
  92. package/dist/esm/mistral-wrapper/index.mjs +1 -0
  93. package/dist/esm/openai-wrapper/index.d.mts +1 -0
  94. package/dist/esm/openai-wrapper/index.mjs +1 -0
  95. package/dist/esm/tracing/signal.d.mts +1 -0
  96. package/dist/esm/tracing/signal.mjs +51 -0
  97. package/dist/esm/tracing/tracing.d.mts +8 -0
  98. package/dist/esm/tracing/tracing.mjs +116 -0
  99. package/dist/esm/tracing/wrappers/anthropicWrapper.d.mts +16 -0
  100. package/dist/esm/tracing/wrappers/anthropicWrapper.mjs +80 -0
  101. package/dist/esm/tracing/wrappers/langchainCallback.d.mts +21 -0
  102. package/dist/esm/tracing/wrappers/langchainCallback.mjs +138 -0
  103. package/dist/esm/tracing/wrappers/mistralWrapper.d.mts +17 -0
  104. package/dist/esm/tracing/wrappers/mistralWrapper.mjs +77 -0
  105. package/dist/esm/tracing/wrappers/openAiWrapper.d.mts +48 -0
  106. package/dist/esm/tracing/wrappers/openAiWrapper.mjs +237 -0
  107. package/dist/esm/tracing/wrappers/vercelAIWrapper.d.mts +22 -0
  108. package/dist/esm/tracing/wrappers/vercelAIWrapper.mjs +319 -0
  109. package/dist/esm/vercel-wrapper/index.d.mts +1 -0
  110. package/dist/esm/vercel-wrapper/index.mjs +1 -0
  111. package/dist/esm/version.d.mts +1 -1
  112. package/dist/esm/version.mjs +1 -1
  113. package/dist/esm/wrapper/BatchUsage.d.mts +3 -3
  114. package/dist/esm/wrapper/BatchUsage.mjs +3 -3
  115. package/package.json +102 -4
  116. package/reference.md +96 -21
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Agent Paid Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,28 +1,45 @@
1
- # Paid TypeScript Library
2
-
3
- [![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen)](https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2FAgentPaid%2Fpaid-node)
4
- [![npm shield](https://img.shields.io/npm/v/@paid-ai/paid-node)](https://www.npmjs.com/package/@paid-ai/paid-node)
5
1
 
2
+ <div align="center">
3
+ <picture>
4
+ <source media="(prefers-color-scheme: dark)" srcset="./assets/paid_light.svg" width=600>
5
+ <source media="(prefers-color-scheme: light)" srcset="./assets/paid_dark.svg" width=600>
6
+ <img alt="Fallback image description" src="./assets/paid_light.svg" width=600>
7
+ </picture>
8
+ </div>
9
+
10
+ #
11
+
12
+ <div align="center">
13
+ <a href="https://buildwithfern.com?utm_source=github&utm_medium=github&utm_campaign=readme&utm_source=https%3A%2F%2Fgithub.com%2FAgentPaid%2Fpaid-node">
14
+ <img src="https://img.shields.io/badge/%F0%9F%8C%BF-Built%20with%20Fern-brightgreen" alt="fern shield">
15
+ </a>
16
+ <a href="https://www.npmjs.com/package/@paid-ai/paid-node">
17
+ <img src="https://img.shields.io/npm/v/@paid-ai/paid-node" alt="npm shield">
18
+ </a>
19
+ </div>
20
+
21
+ Paid is the all-in-one, drop-in Business Engine for AI Agents that handles your pricing, subscriptions, margins, billing, and renewals with just 5 lines of code.
6
22
  The Paid TypeScript library provides convenient access to the Paid API from TypeScript.
7
23
 
24
+ ## Documentation
25
+
26
+ See the full API docs [here](https://paid.docs.buildwithfern.com/api-reference/api-reference/customers/list)
27
+
8
28
  ## Installation
9
29
 
10
30
  ```sh
11
- npm i -s @paid-ai/paid-node
31
+ npm install -s @paid-ai/paid-node
12
32
  ```
13
33
 
14
- ## Reference
15
-
16
- A full reference for this library is available [here](https://github.com/AgentPaid/paid-node/blob/HEAD/./reference.md).
17
-
18
34
  ## Usage
19
35
 
20
- Instantiate and use the client with the following:
36
+ The client needs to be configured with your account's API key, which is available in the [Paid dashboard](https://app.paid.ai/agent-integration/api-keys).
21
37
 
22
38
  ```typescript
23
39
  import { PaidClient } from "@paid-ai/paid-node";
24
40
 
25
- const client = new PaidClient({ token: "YOUR_TOKEN" });
41
+ const client = new PaidClient({ token: "API_KEY" });
42
+
26
43
  await client.customers.create({
27
44
  name: "name",
28
45
  });
@@ -61,6 +78,241 @@ try {
61
78
  }
62
79
  ```
63
80
 
81
+ ## Logging
82
+ Logs are silent by default.
83
+
84
+ To enable logs, set the `PAID_LOG_LEVEL` environment variable. Available levels include:
85
+ `error`, `warn`, `info`, `http`, `verbose`, `debug`, and `silly`.
86
+
87
+ Example: `PAID_LOG_LEVEL=debug node your-app.js`
88
+
89
+ ## Cost Tracking via OTEL tracing
90
+
91
+ You can track usage costs by using Paid wrappers around your AI provider's SDK.
92
+ As of now, the following SDKs' APIs are wrapped:
93
+
94
+ ```
95
+ openai
96
+ anthropic
97
+ mistral
98
+ langchain (as a callback)
99
+ vercel (Vercel AI SDK)
100
+ ```
101
+
102
+ ### Using the Paid wrappers
103
+
104
+ Example usage with OpenAI:
105
+
106
+ ```typescript
107
+ import { PaidClient } from "@paid-ai/paid-node";
108
+ import { PaidOpenAI } from "@paid-ai/paid-node/openai";
109
+ import OpenAI from "openai";
110
+
111
+ async function main() {
112
+ const client = new PaidClient({ token: "<your_paid_api_key>" });
113
+
114
+ // Initialize cost tracking
115
+ await client.initializeTracing();
116
+
117
+ // Wrap OpenAI in paid wrapper
118
+ const openaiClient = new OpenAI({ apiKey: "<your_openai_api_key>" });
119
+ const paidOpenAI = new PaidOpenAI(openaiClient);
120
+
121
+ // Trace the call
122
+ await client.trace("<your_external_customer_id>", async () => {
123
+ const response = await paidOpenAI.images.generate({
124
+ prompt: "A beautiful sunset over the mountains",
125
+ n: 1,
126
+ size: "256x256"
127
+ });
128
+ if (response.data) {
129
+ console.log("Image generation:", response.data[0].url);
130
+ }
131
+ }, "<optional_external_agent_id>");
132
+ }
133
+ ```
134
+
135
+ ## Signaling via OTEL tracing
136
+
137
+ A more reliable and user-friendly way to send signals is to send them via OTEL tracing.
138
+ This allows you to send signals with less arguments and boilerplate as the information is available in the tracing context `Paid.trace()`.
139
+ The interface is `Paid.signal()`, which takes in signal name, optional data, and a flag that attaches costs from the same trace.
140
+ `Paid.signal()` has to be called within a trace - meaning inside of a callback to `Paid.trace()`.
141
+ In contrast to `Paid.usage.recordBulk()`, `Paid.signal()` is using OpenTelemetry to provide reliable delivery.
142
+
143
+ Here's an example of how to use it:
144
+
145
+ ```typescript
146
+ import { PaidClient } from "@paid-ai/paid-node";
147
+
148
+ async function main() {
149
+ const client = new PaidClient({ token: "<your_paid_api_key>" });
150
+
151
+ // Initialize tracing
152
+ await client.initializeTracing();
153
+
154
+ // Trace the call
155
+ await client.trace("<your_external_customer_id>", async () => {
156
+ // ...do some work...
157
+ client.signal("<your_signal_name>", { /* optional data */ });
158
+ }, "<your_external_agent_id>"); // external_agent_id is required for signals
159
+ }
160
+ ```
161
+
162
+ ### Signal-costs - Attaching cost traces to a signal
163
+
164
+ If you want a signal to carry information about costs,
165
+ then the signal should be sent from the same tracing context
166
+ as the wrappers that recorded those costs.
167
+
168
+ This will look something like this:
169
+
170
+ ```typescript
171
+ import { PaidClient } from "@paid-ai/paid-node";
172
+ import { PaidOpenAI } from "@paid-ai/paid-node/openai";
173
+ import OpenAI from "openai";
174
+
175
+ async function main() {
176
+ const client = new PaidClient({ token: "<your_paid_api_key>" });
177
+ await client.initializeTracing();
178
+
179
+ const openaiClient = new OpenAI({ apiKey: "<your_openai_api_key>" });
180
+ const paidOpenAI = new PaidOpenAI(openaiClient);
181
+
182
+ await client.trace("<your_external_customer_id>", async () => {
183
+ // ... your workflow logic
184
+ // ... your AI calls made through Paid wrappers
185
+ const response = await paidOpenAI.chat.completions.create({
186
+ model: "gpt-4",
187
+ messages: [{ role: "user", content: "Hello!" }]
188
+ });
189
+
190
+ // Send signal with cost tracing enabled
191
+ client.signal(
192
+ "<your_signal_name>",
193
+ true, // enableCostTracing - set this flag to associate it with costs
194
+ { /* optional data */ }
195
+ );
196
+
197
+ // ... your workflow logic
198
+ // ... your AI calls made through Paid wrappers (can be sent after the signal too)
199
+ }, "<your_external_agent_id>");
200
+ }
201
+ ```
202
+
203
+ Then, all of the costs traced in `client.trace()` context are related to that signal.
204
+
205
+ ## Manual Cost Tracking
206
+
207
+ If you would prefer to not use Paid to track your costs automatically but you want to send us the costs yourself,
208
+ then you can use manual cost tracking mechanism. Just attach the cost information in the following format to a signal payload:
209
+
210
+ ```typescript
211
+ import { PaidClient, Paid } from "@paid-ai/paid-node";
212
+
213
+ const client = new PaidClient({ token: "<your_paid_api_key>" });
214
+
215
+ const signal: Paid.Signal = {
216
+ event_name: "<your_signal_name>",
217
+ agent_id: "<your_agent_id>",
218
+ customer_id: "<your_external_customer_id>",
219
+ data: {
220
+ costData: {
221
+ vendor: "<any_vendor_name>", // can be anything, traces are grouped by vendors in the UI
222
+ cost: {
223
+ amount: 0.002,
224
+ currency: "USD"
225
+ },
226
+ "gen_ai.response.model": "<ai_model_name>",
227
+ }
228
+ }
229
+ };
230
+
231
+ await client.usage.recordBulk({ signals: [signal] });
232
+ await client.usage.flush(); // need to flush to send usage immediately
233
+ ```
234
+
235
+ Alternatively the same `costData` payload can be passed to OTLP signaling mechanism:
236
+
237
+ ```typescript
238
+ import { PaidClient } from "@paid-ai/paid-node";
239
+
240
+ async function main() {
241
+ const client = new PaidClient({ token: "<your_paid_api_key>" });
242
+ await client.initializeTracing();
243
+
244
+ await client.trace("<your_external_customer_id>", async () => {
245
+ // ...do some work...
246
+ client.signal("<your_signal_name>", {
247
+ costData: {
248
+ vendor: "<any_vendor_name>", // can be anything, traces are grouped by vendors in the UI
249
+ cost: {
250
+ amount: 0.002,
251
+ currency: "USD"
252
+ },
253
+ "gen_ai.response.model": "<ai_model_name>",
254
+ }
255
+ });
256
+ }, "<your_external_agent_id>");
257
+ }
258
+ ```
259
+
260
+ ### Manual Usage Tracking
261
+
262
+ If you would prefer to send us raw usage manually (without wrappers) and have us compute the cost, you can attach usage data in the following format:
263
+
264
+ ```typescript
265
+ import { PaidClient, Paid } from "@paid-ai/paid-node";
266
+
267
+ const client = new PaidClient({ token: "<your_paid_api_key>" });
268
+
269
+ const signal: Paid.Signal = {
270
+ event_name: "<your_signal_name>",
271
+ agent_id: "<your_agent_id>",
272
+ customer_id: "<your_external_customer_id>",
273
+ data: {
274
+ costData: {
275
+ vendor: "<any_vendor_name>", // can be anything, traces are grouped by vendors in the UI
276
+ attributes: {
277
+ "gen_ai.response.model": "gpt-4-turbo",
278
+ "gen_ai.usage.input_tokens": 100,
279
+ "gen_ai.usage.output_tokens": 300,
280
+ "gen_ai.usage.cached_input_tokens": 600,
281
+ },
282
+ }
283
+ }
284
+ };
285
+
286
+ await client.usage.recordBulk({ signals: [signal] });
287
+ await client.usage.flush();
288
+ ```
289
+
290
+ Same but via OTEL signaling:
291
+
292
+ ```typescript
293
+ import { PaidClient } from "@paid-ai/paid-node";
294
+
295
+ async function main() {
296
+ const client = new PaidClient({ token: "<your_paid_api_key>" });
297
+ await client.initializeTracing();
298
+
299
+ await client.trace("<your_external_customer_id>", async () => {
300
+ // ...do some work...
301
+ client.signal("<your_signal_name>", {
302
+ costData: {
303
+ vendor: "<any_vendor_name>", // can be anything, traces are grouped by vendors in the UI
304
+ attributes: {
305
+ "gen_ai.response.model": "gpt-4-turbo",
306
+ "gen_ai.usage.input_tokens": 100,
307
+ "gen_ai.usage.output_tokens": 300,
308
+ "gen_ai.usage.cached_input_tokens": 600,
309
+ },
310
+ }
311
+ });
312
+ }, "<your_external_agent_id>");
313
+ }
314
+ ```
315
+
64
316
  ## Advanced
65
317
 
66
318
  ### Additional Headers
@@ -41,4 +41,26 @@ export declare class PaidClient {
41
41
  get contacts(): Contacts;
42
42
  get orders(): Orders;
43
43
  get usage(): Usage;
44
+ initializeTracing(collectorEndpoint?: string): Promise<void>;
45
+ trace<T extends (...args: any[]) => any>(externalCustomerId: string, fn: T, externalAgentId?: string, ...args: Parameters<T>): Promise<ReturnType<T>>;
46
+ /**
47
+ * Sends Paid signal. Needs to be called as part of callback to Paid.trace().
48
+ * When enableCostTracing flag is on, signal is associated
49
+ * with cost traces from the same Paid.trace() context.
50
+ *
51
+ * @param eventName - The name of the signal.
52
+ * @param enableCostTracing - Whether to associate this signal with cost traces
53
+ * from the current Paid.trace() context (default: false)
54
+ * @param data - Optional additional data to include with the signal
55
+ *
56
+ * @remarks
57
+ * When enableCostTracing is on, the signal will be associated with cost
58
+ * traces within the same Paid.trace() context.
59
+ * It is advised to only make one call to this function
60
+ * with enableCostTracing per Paid.trace() context.
61
+ * Otherwise, there will be multiple signals that refer to the same costs.
62
+ */
63
+ signal(eventName: string): void;
64
+ signal(eventName: string, data: Record<string, any>): void;
65
+ signal(eventName: string, enableCostTracing: boolean, data?: Record<string, any>): void;
44
66
  }
@@ -35,6 +35,15 @@ var __importStar = (this && this.__importStar) || (function () {
35
35
  return result;
36
36
  };
37
37
  })();
38
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
39
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
40
+ return new (P || (P = Promise))(function (resolve, reject) {
41
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
42
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
43
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
44
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
45
+ });
46
+ };
38
47
  Object.defineProperty(exports, "__esModule", { value: true });
39
48
  exports.PaidClient = void 0;
40
49
  const core = __importStar(require("./core/index.js"));
@@ -44,13 +53,15 @@ const Client_js_2 = require("./api/resources/agents/client/Client.js");
44
53
  const Client_js_3 = require("./api/resources/contacts/client/Client.js");
45
54
  const Client_js_4 = require("./api/resources/orders/client/Client.js");
46
55
  const BatchUsage_js_1 = require("./wrapper/BatchUsage.js");
56
+ const tracing_js_1 = require("./tracing/tracing.js");
57
+ const signal_js_1 = require("./tracing/signal.js");
47
58
  class PaidClient {
48
59
  constructor(_options) {
49
60
  this._options = Object.assign(Object.assign({}, _options), { headers: (0, headers_js_1.mergeHeaders)({
50
61
  "X-Fern-Language": "JavaScript",
51
62
  "X-Fern-SDK-Name": "@paid-ai/paid-node",
52
- "X-Fern-SDK-Version": "0.0.6",
53
- "User-Agent": "@paid-ai/paid-node/0.0.6",
63
+ "X-Fern-SDK-Version": "0.2.1",
64
+ "User-Agent": "@paid-ai/paid-node/0.2.1",
54
65
  "X-Fern-Runtime": core.RUNTIME.type,
55
66
  "X-Fern-Runtime-Version": core.RUNTIME.version,
56
67
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
@@ -75,5 +86,37 @@ class PaidClient {
75
86
  var _a;
76
87
  return ((_a = this._usage) !== null && _a !== void 0 ? _a : (this._usage = new BatchUsage_js_1.Usage(this._options)));
77
88
  }
89
+ // Need to call this method before using tracing or creating wrappers.
90
+ initializeTracing(collectorEndpoint) {
91
+ return __awaiter(this, void 0, void 0, function* () {
92
+ const tokenSupplier = this._options.token;
93
+ const token = typeof tokenSupplier === "function" ? yield tokenSupplier() : tokenSupplier;
94
+ const resolvedToken = yield Promise.resolve(token);
95
+ (0, tracing_js_1._initializeTracing)(resolvedToken, collectorEndpoint);
96
+ });
97
+ }
98
+ // Use this method to track actions like LLM costs and sending signals.
99
+ // The callback to this function is the work that you want to trace.
100
+ trace(externalCustomerId, fn, externalAgentId, ...args) {
101
+ return __awaiter(this, void 0, void 0, function* () {
102
+ return yield (0, tracing_js_1._trace)(externalCustomerId, fn, externalAgentId, ...args);
103
+ });
104
+ }
105
+ signal(eventName, enableCostTracingOrData, data) {
106
+ let enableCostTracing = false;
107
+ let finalData;
108
+ if (typeof enableCostTracingOrData === 'boolean') {
109
+ // Case: signal(eventName, boolean, data?)
110
+ enableCostTracing = enableCostTracingOrData;
111
+ finalData = data;
112
+ }
113
+ else if (typeof enableCostTracingOrData === 'object') {
114
+ // Case: signal(eventName, data)
115
+ enableCostTracing = false;
116
+ finalData = enableCostTracingOrData;
117
+ }
118
+ // Case: signal(eventName) - both remain default/undefined
119
+ return (0, signal_js_1._signal)(eventName, enableCostTracing, finalData);
120
+ }
78
121
  }
79
122
  exports.PaidClient = PaidClient;
@@ -0,0 +1 @@
1
+ export { PaidAnthropic } from "../tracing/wrappers/anthropicWrapper.js";
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PaidAnthropic = void 0;
4
+ var anthropicWrapper_js_1 = require("../tracing/wrappers/anthropicWrapper.js");
5
+ Object.defineProperty(exports, "PaidAnthropic", { enumerable: true, get: function () { return anthropicWrapper_js_1.PaidAnthropic; } });
@@ -41,8 +41,9 @@ export declare class Agents {
41
41
  *
42
42
  * @example
43
43
  * await client.agents.create({
44
- * name: "name",
45
- * description: "description"
44
+ * name: "Acme Agent",
45
+ * description: "Acme Agent is an AI agent that does things.",
46
+ * externalId: "acme-agent"
46
47
  * })
47
48
  */
48
49
  create(request: Paid.AgentCreate, requestOptions?: Agents.RequestOptions): core.HttpResponsePromise<Paid.Agent>;
@@ -62,7 +63,36 @@ export declare class Agents {
62
63
  * @param {Agents.RequestOptions} requestOptions - Request-specific configuration.
63
64
  *
64
65
  * @example
65
- * await client.agents.update("agentId", {})
66
+ * await client.agents.update("agentId", {
67
+ * name: "Acme Agent (Updated)",
68
+ * agentAttributes: [{
69
+ * name: "Emails sent signal",
70
+ * active: true,
71
+ * pricing: {
72
+ * eventName: "emails_sent",
73
+ * taxable: true,
74
+ * chargeType: "usage",
75
+ * pricingModel: "PerUnit",
76
+ * billingFrequency: "monthly",
77
+ * pricePoints: {
78
+ * "USD": {
79
+ * tiers: [{
80
+ * minQuantity: 0,
81
+ * maxQuantity: 10,
82
+ * unitPrice: 100
83
+ * }, {
84
+ * minQuantity: 11,
85
+ * maxQuantity: 100,
86
+ * unitPrice: 90
87
+ * }, {
88
+ * minQuantity: 101,
89
+ * unitPrice: 80
90
+ * }]
91
+ * }
92
+ * }
93
+ * }
94
+ * }]
95
+ * })
66
96
  */
67
97
  update(agentId: string, request: Paid.AgentUpdate, requestOptions?: Agents.RequestOptions): core.HttpResponsePromise<Paid.Agent>;
68
98
  private __update;
@@ -90,7 +120,25 @@ export declare class Agents {
90
120
  * @param {Agents.RequestOptions} requestOptions - Request-specific configuration.
91
121
  *
92
122
  * @example
93
- * await client.agents.updateByExternalId("externalId", {})
123
+ * await client.agents.updateByExternalId("externalId", {
124
+ * name: "Acme Agent (Updated)",
125
+ * agentAttributes: [{
126
+ * name: "Emails sent signal",
127
+ * active: true,
128
+ * pricing: {
129
+ * eventName: "emails_sent",
130
+ * taxable: true,
131
+ * chargeType: "usage",
132
+ * pricingModel: "PerUnit",
133
+ * billingFrequency: "monthly",
134
+ * pricePoints: {
135
+ * "USD": {
136
+ * unitPrice: 150
137
+ * }
138
+ * }
139
+ * }
140
+ * }]
141
+ * })
94
142
  */
95
143
  updateByExternalId(externalId: string, request: Paid.AgentUpdate, requestOptions?: Agents.RequestOptions): core.HttpResponsePromise<Paid.Agent>;
96
144
  private __updateByExternalId;
@@ -111,8 +111,9 @@ class Agents {
111
111
  *
112
112
  * @example
113
113
  * await client.agents.create({
114
- * name: "name",
115
- * description: "description"
114
+ * name: "Acme Agent",
115
+ * description: "Acme Agent is an AI agent that does things.",
116
+ * externalId: "acme-agent"
116
117
  * })
117
118
  */
118
119
  create(request, requestOptions) {
@@ -213,7 +214,36 @@ class Agents {
213
214
  * @param {Agents.RequestOptions} requestOptions - Request-specific configuration.
214
215
  *
215
216
  * @example
216
- * await client.agents.update("agentId", {})
217
+ * await client.agents.update("agentId", {
218
+ * name: "Acme Agent (Updated)",
219
+ * agentAttributes: [{
220
+ * name: "Emails sent signal",
221
+ * active: true,
222
+ * pricing: {
223
+ * eventName: "emails_sent",
224
+ * taxable: true,
225
+ * chargeType: "usage",
226
+ * pricingModel: "PerUnit",
227
+ * billingFrequency: "monthly",
228
+ * pricePoints: {
229
+ * "USD": {
230
+ * tiers: [{
231
+ * minQuantity: 0,
232
+ * maxQuantity: 10,
233
+ * unitPrice: 100
234
+ * }, {
235
+ * minQuantity: 11,
236
+ * maxQuantity: 100,
237
+ * unitPrice: 90
238
+ * }, {
239
+ * minQuantity: 101,
240
+ * unitPrice: 80
241
+ * }]
242
+ * }
243
+ * }
244
+ * }
245
+ * }]
246
+ * })
217
247
  */
218
248
  update(agentId, request, requestOptions) {
219
249
  return core.HttpResponsePromise.fromPromise(this.__update(agentId, request, requestOptions));
@@ -361,7 +391,25 @@ class Agents {
361
391
  * @param {Agents.RequestOptions} requestOptions - Request-specific configuration.
362
392
  *
363
393
  * @example
364
- * await client.agents.updateByExternalId("externalId", {})
394
+ * await client.agents.updateByExternalId("externalId", {
395
+ * name: "Acme Agent (Updated)",
396
+ * agentAttributes: [{
397
+ * name: "Emails sent signal",
398
+ * active: true,
399
+ * pricing: {
400
+ * eventName: "emails_sent",
401
+ * taxable: true,
402
+ * chargeType: "usage",
403
+ * pricingModel: "PerUnit",
404
+ * billingFrequency: "monthly",
405
+ * pricePoints: {
406
+ * "USD": {
407
+ * unitPrice: 150
408
+ * }
409
+ * }
410
+ * }
411
+ * }]
412
+ * })
365
413
  */
366
414
  updateByExternalId(externalId, request, requestOptions) {
367
415
  return core.HttpResponsePromise.fromPromise(this.__updateByExternalId(externalId, request, requestOptions));
@@ -4,8 +4,9 @@
4
4
  /**
5
5
  * @example
6
6
  * {
7
- * name: "name",
8
- * description: "description"
7
+ * name: "Acme Agent",
8
+ * description: "Acme Agent is an AI agent that does things.",
9
+ * externalId: "acme-agent"
9
10
  * }
10
11
  */
11
12
  export interface AgentCreate {
@@ -13,4 +14,5 @@ export interface AgentCreate {
13
14
  description: string;
14
15
  agentCode?: string;
15
16
  externalId?: string;
17
+ active?: boolean;
16
18
  }
@@ -41,14 +41,11 @@ export declare class Contacts {
41
41
  *
42
42
  * @example
43
43
  * await client.contacts.create({
44
+ * customerExternalId: "acme-inc",
44
45
  * salutation: "Mr.",
45
- * firstName: "firstName",
46
- * lastName: "lastName",
47
- * email: "email",
48
- * billingStreet: "billingStreet",
49
- * billingCity: "billingCity",
50
- * billingCountry: "billingCountry",
51
- * billingPostalCode: "billingPostalCode"
46
+ * firstName: "John",
47
+ * lastName: "Doe",
48
+ * email: "john.doe@example.com"
52
49
  * })
53
50
  */
54
51
  create(request: Paid.ContactCreate, requestOptions?: Contacts.RequestOptions): core.HttpResponsePromise<Paid.Contact>;
@@ -111,14 +111,11 @@ class Contacts {
111
111
  *
112
112
  * @example
113
113
  * await client.contacts.create({
114
+ * customerExternalId: "acme-inc",
114
115
  * salutation: "Mr.",
115
- * firstName: "firstName",
116
- * lastName: "lastName",
117
- * email: "email",
118
- * billingStreet: "billingStreet",
119
- * billingCity: "billingCity",
120
- * billingCountry: "billingCountry",
121
- * billingPostalCode: "billingPostalCode"
116
+ * firstName: "John",
117
+ * lastName: "Doe",
118
+ * email: "john.doe@example.com"
122
119
  * })
123
120
  */
124
121
  create(request, requestOptions) {
@@ -5,14 +5,11 @@ import * as Paid from "../../../../index.js";
5
5
  /**
6
6
  * @example
7
7
  * {
8
+ * customerExternalId: "acme-inc",
8
9
  * salutation: "Mr.",
9
- * firstName: "firstName",
10
- * lastName: "lastName",
11
- * email: "email",
12
- * billingStreet: "billingStreet",
13
- * billingCity: "billingCity",
14
- * billingCountry: "billingCountry",
15
- * billingPostalCode: "billingPostalCode"
10
+ * firstName: "John",
11
+ * lastName: "Doe",
12
+ * email: "john.doe@example.com"
16
13
  * }
17
14
  */
18
15
  export interface ContactCreate {
@@ -24,9 +21,9 @@ export interface ContactCreate {
24
21
  lastName: string;
25
22
  email: string;
26
23
  phone?: string;
27
- billingStreet: string;
28
- billingCity: string;
24
+ billingStreet?: string;
25
+ billingCity?: string;
29
26
  billingStateProvince?: string;
30
- billingCountry: string;
31
- billingPostalCode: string;
27
+ billingCountry?: string;
28
+ billingPostalCode?: string;
32
29
  }