@paid-ai/paid-node 0.0.8 → 0.2.0
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/LICENSE +21 -0
- package/README.md +122 -11
- package/dist/cjs/Client.d.ts +22 -0
- package/dist/cjs/Client.js +45 -2
- package/dist/cjs/anthropic-wrapper/index.d.ts +1 -0
- package/dist/cjs/anthropic-wrapper/index.js +5 -0
- package/dist/cjs/api/resources/agents/client/Client.d.ts +52 -4
- package/dist/cjs/api/resources/agents/client/Client.js +52 -4
- package/dist/cjs/api/resources/agents/client/requests/AgentCreate.d.ts +4 -2
- package/dist/cjs/api/resources/contacts/client/Client.d.ts +4 -7
- package/dist/cjs/api/resources/contacts/client/Client.js +4 -7
- package/dist/cjs/api/resources/contacts/client/requests/ContactCreate.d.ts +8 -11
- package/dist/cjs/api/resources/customers/client/Client.d.ts +8 -2
- package/dist/cjs/api/resources/customers/client/Client.js +8 -2
- package/dist/cjs/api/resources/customers/client/requests/CustomerCreate.d.ts +2 -1
- package/dist/cjs/api/resources/orders/client/Client.d.ts +6 -5
- package/dist/cjs/api/resources/orders/client/Client.js +6 -5
- package/dist/cjs/api/resources/orders/client/requests/OrderCreate.d.ts +8 -7
- package/dist/cjs/api/resources/orders/resources/lines/client/Client.d.ts +11 -1
- package/dist/cjs/api/resources/orders/resources/lines/client/Client.js +11 -1
- package/dist/cjs/api/resources/orders/resources/lines/client/requests/LinesUpdateRequest.d.ts +11 -1
- package/dist/cjs/api/resources/usage/client/Client.d.ts +4 -2
- package/dist/cjs/api/resources/usage/client/Client.js +4 -2
- package/dist/cjs/api/resources/usage/client/requests/UsageRecordBulkRequest.d.ts +3 -1
- package/dist/cjs/api/types/BillingFrequency.d.ts +4 -4
- package/dist/cjs/api/types/BillingFrequency.js +3 -3
- package/dist/cjs/api/types/Pricing.d.ts +1 -0
- package/dist/cjs/api/types/PricingModelType.d.ts +2 -1
- package/dist/cjs/api/types/PricingModelType.js +1 -0
- package/dist/cjs/api/types/Signal.d.ts +1 -0
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +3 -3
- package/dist/cjs/langchain-wrapper/index.d.ts +1 -0
- package/dist/cjs/langchain-wrapper/index.js +5 -0
- package/dist/cjs/mistral-wrapper/index.d.ts +1 -0
- package/dist/cjs/mistral-wrapper/index.js +5 -0
- package/dist/cjs/openai-wrapper/index.d.ts +1 -0
- package/dist/cjs/openai-wrapper/index.js +5 -0
- package/dist/cjs/tracing/signal.d.ts +1 -0
- package/dist/cjs/tracing/signal.js +54 -0
- package/dist/cjs/tracing/tracing.d.ts +8 -0
- package/dist/cjs/tracing/tracing.js +127 -0
- package/dist/cjs/tracing/wrappers/anthropicWrapper.d.ts +16 -0
- package/dist/cjs/tracing/wrappers/anthropicWrapper.js +84 -0
- package/dist/cjs/tracing/wrappers/langchainCallback.d.ts +21 -0
- package/dist/cjs/tracing/wrappers/langchainCallback.js +142 -0
- package/dist/cjs/tracing/wrappers/mistralWrapper.d.ts +17 -0
- package/dist/cjs/tracing/wrappers/mistralWrapper.js +81 -0
- package/dist/cjs/tracing/wrappers/openAiWrapper.d.ts +48 -0
- package/dist/cjs/tracing/wrappers/openAiWrapper.js +241 -0
- package/dist/cjs/tracing/wrappers/vercelAIWrapper.d.ts +22 -0
- package/dist/cjs/tracing/wrappers/vercelAIWrapper.js +327 -0
- package/dist/cjs/vercel-wrapper/index.d.ts +1 -0
- package/dist/cjs/vercel-wrapper/index.js +10 -0
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wrapper/BatchUsage.d.ts +3 -3
- package/dist/cjs/wrapper/BatchUsage.js +4 -4
- package/dist/esm/Client.d.mts +22 -0
- package/dist/esm/Client.mjs +45 -2
- package/dist/esm/anthropic-wrapper/index.d.mts +1 -0
- package/dist/esm/anthropic-wrapper/index.mjs +1 -0
- package/dist/esm/api/resources/agents/client/Client.d.mts +52 -4
- package/dist/esm/api/resources/agents/client/Client.mjs +52 -4
- package/dist/esm/api/resources/agents/client/requests/AgentCreate.d.mts +4 -2
- package/dist/esm/api/resources/contacts/client/Client.d.mts +4 -7
- package/dist/esm/api/resources/contacts/client/Client.mjs +4 -7
- package/dist/esm/api/resources/contacts/client/requests/ContactCreate.d.mts +8 -11
- package/dist/esm/api/resources/customers/client/Client.d.mts +8 -2
- package/dist/esm/api/resources/customers/client/Client.mjs +8 -2
- package/dist/esm/api/resources/customers/client/requests/CustomerCreate.d.mts +2 -1
- package/dist/esm/api/resources/orders/client/Client.d.mts +6 -5
- package/dist/esm/api/resources/orders/client/Client.mjs +6 -5
- package/dist/esm/api/resources/orders/client/requests/OrderCreate.d.mts +8 -7
- package/dist/esm/api/resources/orders/resources/lines/client/Client.d.mts +11 -1
- package/dist/esm/api/resources/orders/resources/lines/client/Client.mjs +11 -1
- package/dist/esm/api/resources/orders/resources/lines/client/requests/LinesUpdateRequest.d.mts +11 -1
- package/dist/esm/api/resources/usage/client/Client.d.mts +4 -2
- package/dist/esm/api/resources/usage/client/Client.mjs +4 -2
- package/dist/esm/api/resources/usage/client/requests/UsageRecordBulkRequest.d.mts +3 -1
- package/dist/esm/api/types/BillingFrequency.d.mts +4 -4
- package/dist/esm/api/types/BillingFrequency.mjs +3 -3
- package/dist/esm/api/types/Pricing.d.mts +1 -0
- package/dist/esm/api/types/PricingModelType.d.mts +2 -1
- package/dist/esm/api/types/PricingModelType.mjs +1 -0
- package/dist/esm/api/types/Signal.d.mts +1 -0
- package/dist/esm/index.d.mts +1 -1
- package/dist/esm/index.mjs +1 -1
- package/dist/esm/langchain-wrapper/index.d.mts +1 -0
- package/dist/esm/langchain-wrapper/index.mjs +1 -0
- package/dist/esm/mistral-wrapper/index.d.mts +1 -0
- package/dist/esm/mistral-wrapper/index.mjs +1 -0
- package/dist/esm/openai-wrapper/index.d.mts +1 -0
- package/dist/esm/openai-wrapper/index.mjs +1 -0
- package/dist/esm/tracing/signal.d.mts +1 -0
- package/dist/esm/tracing/signal.mjs +51 -0
- package/dist/esm/tracing/tracing.d.mts +8 -0
- package/dist/esm/tracing/tracing.mjs +116 -0
- package/dist/esm/tracing/wrappers/anthropicWrapper.d.mts +16 -0
- package/dist/esm/tracing/wrappers/anthropicWrapper.mjs +80 -0
- package/dist/esm/tracing/wrappers/langchainCallback.d.mts +21 -0
- package/dist/esm/tracing/wrappers/langchainCallback.mjs +138 -0
- package/dist/esm/tracing/wrappers/mistralWrapper.d.mts +17 -0
- package/dist/esm/tracing/wrappers/mistralWrapper.mjs +77 -0
- package/dist/esm/tracing/wrappers/openAiWrapper.d.mts +48 -0
- package/dist/esm/tracing/wrappers/openAiWrapper.mjs +237 -0
- package/dist/esm/tracing/wrappers/vercelAIWrapper.d.mts +22 -0
- package/dist/esm/tracing/wrappers/vercelAIWrapper.mjs +319 -0
- package/dist/esm/vercel-wrapper/index.d.mts +1 -0
- package/dist/esm/vercel-wrapper/index.mjs +1 -0
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/dist/esm/wrapper/BatchUsage.d.mts +3 -3
- package/dist/esm/wrapper/BatchUsage.mjs +3 -3
- package/package.json +102 -4
- package/reference.md +96 -21
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.generateText = generateText;
|
|
13
|
+
exports.streamText = streamText;
|
|
14
|
+
exports.generateObject = generateObject;
|
|
15
|
+
exports.streamObject = streamObject;
|
|
16
|
+
exports.embed = embed;
|
|
17
|
+
exports.embedMany = embedMany;
|
|
18
|
+
const api_1 = require("@opentelemetry/api");
|
|
19
|
+
const tracing_js_1 = require("../tracing.js");
|
|
20
|
+
const ai_1 = require("ai");
|
|
21
|
+
function getModelInfo(model) {
|
|
22
|
+
if (model === null || model === void 0 ? void 0 : model.modelId) {
|
|
23
|
+
const modelId = model.modelId;
|
|
24
|
+
if (modelId.startsWith('gpt-') || modelId.startsWith('text-embedding-') || modelId.startsWith('dall-e-')) {
|
|
25
|
+
return { system: 'openai', modelName: modelId };
|
|
26
|
+
}
|
|
27
|
+
if (modelId.startsWith('claude-')) {
|
|
28
|
+
return { system: 'anthropic', modelName: modelId };
|
|
29
|
+
}
|
|
30
|
+
if (modelId.startsWith('mistral-') || modelId.startsWith('codestral-')) {
|
|
31
|
+
return { system: 'mistral', modelName: modelId };
|
|
32
|
+
}
|
|
33
|
+
if (modelId.includes('gemini')) {
|
|
34
|
+
return { system: 'google', modelName: modelId };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
if (model === null || model === void 0 ? void 0 : model.provider) {
|
|
38
|
+
return { system: model.provider, modelName: model.modelId };
|
|
39
|
+
}
|
|
40
|
+
return { system: 'unknown' };
|
|
41
|
+
}
|
|
42
|
+
function extractUsageMetrics(usage) {
|
|
43
|
+
const usageAttrs = {};
|
|
44
|
+
const inputTokens = usage.promptTokens || usage.prompt_tokens || usage.inputTokens;
|
|
45
|
+
const outputTokens = usage.completionTokens || usage.completion_tokens || usage.outputTokens;
|
|
46
|
+
const cachedTokens = usage.cachedPromptTokens || usage.cached_prompt_tokens || usage.cachedInputTokens;
|
|
47
|
+
if (inputTokens !== undefined) {
|
|
48
|
+
usageAttrs["gen_ai.usage.input_tokens"] = inputTokens;
|
|
49
|
+
}
|
|
50
|
+
if (outputTokens !== undefined) {
|
|
51
|
+
usageAttrs["gen_ai.usage.output_tokens"] = outputTokens;
|
|
52
|
+
}
|
|
53
|
+
if (cachedTokens !== undefined) {
|
|
54
|
+
usageAttrs["gen_ai.usage.cached_input_tokens"] = cachedTokens;
|
|
55
|
+
}
|
|
56
|
+
if (usage.tokens !== undefined && inputTokens === undefined) {
|
|
57
|
+
usageAttrs["gen_ai.usage.input_tokens"] = usage.tokens;
|
|
58
|
+
}
|
|
59
|
+
return usageAttrs;
|
|
60
|
+
}
|
|
61
|
+
function validateContext() {
|
|
62
|
+
const externalCustomerId = (0, tracing_js_1.getCustomerIdStorage)();
|
|
63
|
+
const token = (0, tracing_js_1.getTokenStorage)();
|
|
64
|
+
if (!token || !externalCustomerId) {
|
|
65
|
+
throw new Error("No token or externalCustomerId: This wrapper should be used inside a callback to paid.trace().");
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
externalCustomerId,
|
|
69
|
+
externalAgentId: (0, tracing_js_1.getAgentIdStorage)(),
|
|
70
|
+
token,
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function generateText(params) {
|
|
74
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
75
|
+
const context = validateContext();
|
|
76
|
+
const { system: aiSystem, modelName } = getModelInfo(params.model);
|
|
77
|
+
return tracing_js_1.paidTracer.startActiveSpan("trace.ai-sdk.generateText", (span) => __awaiter(this, void 0, void 0, function* () {
|
|
78
|
+
var _a;
|
|
79
|
+
const attributes = {
|
|
80
|
+
"gen_ai.system": aiSystem,
|
|
81
|
+
"gen_ai.operation.name": "chat",
|
|
82
|
+
"external_customer_id": context.externalCustomerId,
|
|
83
|
+
"token": context.token,
|
|
84
|
+
};
|
|
85
|
+
if (context.externalAgentId) {
|
|
86
|
+
attributes["external_agent_id"] = context.externalAgentId;
|
|
87
|
+
}
|
|
88
|
+
if (modelName) {
|
|
89
|
+
attributes["gen_ai.request.model"] = modelName;
|
|
90
|
+
}
|
|
91
|
+
span.setAttributes(attributes);
|
|
92
|
+
try {
|
|
93
|
+
const result = yield (0, ai_1.generateText)(params);
|
|
94
|
+
if (result.usage) {
|
|
95
|
+
const usageAttrs = extractUsageMetrics(result.usage);
|
|
96
|
+
span.setAttributes(usageAttrs);
|
|
97
|
+
}
|
|
98
|
+
if ((_a = result.response) === null || _a === void 0 ? void 0 : _a.modelId) {
|
|
99
|
+
span.setAttribute("gen_ai.response.model", result.response.modelId);
|
|
100
|
+
}
|
|
101
|
+
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: error.message });
|
|
106
|
+
span.recordException(error);
|
|
107
|
+
throw error;
|
|
108
|
+
}
|
|
109
|
+
finally {
|
|
110
|
+
span.end();
|
|
111
|
+
}
|
|
112
|
+
}));
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
function streamText(params) {
|
|
116
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
117
|
+
const context = validateContext();
|
|
118
|
+
const { system: aiSystem, modelName } = getModelInfo(params.model);
|
|
119
|
+
return tracing_js_1.paidTracer.startActiveSpan("trace.ai-sdk.streamText", (span) => __awaiter(this, void 0, void 0, function* () {
|
|
120
|
+
const attributes = {
|
|
121
|
+
"gen_ai.system": aiSystem,
|
|
122
|
+
"gen_ai.operation.name": "chat",
|
|
123
|
+
"external_customer_id": context.externalCustomerId,
|
|
124
|
+
"token": context.token,
|
|
125
|
+
};
|
|
126
|
+
if (context.externalAgentId) {
|
|
127
|
+
attributes["external_agent_id"] = context.externalAgentId;
|
|
128
|
+
}
|
|
129
|
+
if (modelName) {
|
|
130
|
+
attributes["gen_ai.request.model"] = modelName;
|
|
131
|
+
}
|
|
132
|
+
span.setAttributes(attributes);
|
|
133
|
+
try {
|
|
134
|
+
const originalOnFinish = params.onFinish;
|
|
135
|
+
const wrappedParams = Object.assign(Object.assign({}, params), { onFinish: (result) => {
|
|
136
|
+
if (result.usage) {
|
|
137
|
+
const usageAttrs = extractUsageMetrics(result.usage);
|
|
138
|
+
span.setAttributes(usageAttrs);
|
|
139
|
+
}
|
|
140
|
+
if (originalOnFinish) {
|
|
141
|
+
originalOnFinish(result);
|
|
142
|
+
}
|
|
143
|
+
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
144
|
+
span.end();
|
|
145
|
+
} });
|
|
146
|
+
const result = (0, ai_1.streamText)(wrappedParams);
|
|
147
|
+
return result;
|
|
148
|
+
}
|
|
149
|
+
catch (error) {
|
|
150
|
+
span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: error.message });
|
|
151
|
+
span.recordException(error);
|
|
152
|
+
throw error;
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
span.end();
|
|
156
|
+
}
|
|
157
|
+
}));
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
function generateObject(params) {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
const context = validateContext();
|
|
163
|
+
const { system: aiSystem, modelName } = getModelInfo(params.model);
|
|
164
|
+
return tracing_js_1.paidTracer.startActiveSpan("trace.ai-sdk.generateObject", (span) => __awaiter(this, void 0, void 0, function* () {
|
|
165
|
+
var _a;
|
|
166
|
+
const attributes = {
|
|
167
|
+
"gen_ai.system": aiSystem,
|
|
168
|
+
"gen_ai.operation.name": "chat",
|
|
169
|
+
"external_customer_id": context.externalCustomerId,
|
|
170
|
+
"token": context.token,
|
|
171
|
+
};
|
|
172
|
+
if (context.externalAgentId) {
|
|
173
|
+
attributes["external_agent_id"] = context.externalAgentId;
|
|
174
|
+
}
|
|
175
|
+
if (modelName) {
|
|
176
|
+
attributes["gen_ai.request.model"] = modelName;
|
|
177
|
+
}
|
|
178
|
+
span.setAttributes(attributes);
|
|
179
|
+
try {
|
|
180
|
+
const result = yield (0, ai_1.generateObject)(params);
|
|
181
|
+
if (result.usage) {
|
|
182
|
+
const usageAttrs = extractUsageMetrics(result.usage);
|
|
183
|
+
span.setAttributes(usageAttrs);
|
|
184
|
+
}
|
|
185
|
+
if ((_a = result.response) === null || _a === void 0 ? void 0 : _a.modelId) {
|
|
186
|
+
span.setAttribute("gen_ai.response.model", result.response.modelId);
|
|
187
|
+
}
|
|
188
|
+
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
189
|
+
return result;
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: error.message });
|
|
193
|
+
span.recordException(error);
|
|
194
|
+
throw error;
|
|
195
|
+
}
|
|
196
|
+
finally {
|
|
197
|
+
span.end();
|
|
198
|
+
}
|
|
199
|
+
}));
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
function streamObject(params) {
|
|
203
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
204
|
+
const context = validateContext();
|
|
205
|
+
const { system: aiSystem, modelName } = getModelInfo(params.model);
|
|
206
|
+
return tracing_js_1.paidTracer.startActiveSpan("trace.ai-sdk.streamObject", (span) => __awaiter(this, void 0, void 0, function* () {
|
|
207
|
+
const attributes = {
|
|
208
|
+
"gen_ai.system": aiSystem,
|
|
209
|
+
"gen_ai.operation.name": "chat",
|
|
210
|
+
"external_customer_id": context.externalCustomerId,
|
|
211
|
+
"token": context.token,
|
|
212
|
+
};
|
|
213
|
+
if (context.externalAgentId) {
|
|
214
|
+
attributes["external_agent_id"] = context.externalAgentId;
|
|
215
|
+
}
|
|
216
|
+
if (modelName) {
|
|
217
|
+
attributes["gen_ai.request.model"] = modelName;
|
|
218
|
+
}
|
|
219
|
+
span.setAttributes(attributes);
|
|
220
|
+
try {
|
|
221
|
+
const originalOnFinish = params.onFinish;
|
|
222
|
+
const wrappedParams = Object.assign(Object.assign({}, params), { onFinish: (result) => {
|
|
223
|
+
if (result.usage) {
|
|
224
|
+
const usageAttrs = extractUsageMetrics(result.usage);
|
|
225
|
+
span.setAttributes(usageAttrs);
|
|
226
|
+
}
|
|
227
|
+
if (originalOnFinish) {
|
|
228
|
+
originalOnFinish(result);
|
|
229
|
+
}
|
|
230
|
+
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
231
|
+
span.end();
|
|
232
|
+
} });
|
|
233
|
+
const result = (0, ai_1.streamObject)(wrappedParams);
|
|
234
|
+
return result;
|
|
235
|
+
}
|
|
236
|
+
catch (error) {
|
|
237
|
+
span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: error.message });
|
|
238
|
+
span.recordException(error);
|
|
239
|
+
throw error;
|
|
240
|
+
}
|
|
241
|
+
}));
|
|
242
|
+
});
|
|
243
|
+
}
|
|
244
|
+
function embed(params) {
|
|
245
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
246
|
+
const context = validateContext();
|
|
247
|
+
const { system: aiSystem, modelName } = getModelInfo(params.model);
|
|
248
|
+
return tracing_js_1.paidTracer.startActiveSpan("trace.ai-sdk.embed", (span) => __awaiter(this, void 0, void 0, function* () {
|
|
249
|
+
const attributes = {
|
|
250
|
+
"gen_ai.system": aiSystem,
|
|
251
|
+
"gen_ai.operation.name": "embeddings",
|
|
252
|
+
"external_customer_id": context.externalCustomerId,
|
|
253
|
+
"token": context.token,
|
|
254
|
+
};
|
|
255
|
+
if (context.externalAgentId) {
|
|
256
|
+
attributes["external_agent_id"] = context.externalAgentId;
|
|
257
|
+
}
|
|
258
|
+
if (modelName) {
|
|
259
|
+
attributes["gen_ai.request.model"] = modelName;
|
|
260
|
+
}
|
|
261
|
+
span.setAttributes(attributes);
|
|
262
|
+
try {
|
|
263
|
+
const result = yield (0, ai_1.embed)(params);
|
|
264
|
+
if (result.usage) {
|
|
265
|
+
const usageAttrs = extractUsageMetrics(result.usage);
|
|
266
|
+
span.setAttributes(usageAttrs);
|
|
267
|
+
}
|
|
268
|
+
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
269
|
+
return result;
|
|
270
|
+
}
|
|
271
|
+
catch (error) {
|
|
272
|
+
span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: error.message });
|
|
273
|
+
span.recordException(error);
|
|
274
|
+
throw error;
|
|
275
|
+
}
|
|
276
|
+
finally {
|
|
277
|
+
span.end();
|
|
278
|
+
}
|
|
279
|
+
}));
|
|
280
|
+
});
|
|
281
|
+
}
|
|
282
|
+
function embedMany(params) {
|
|
283
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
284
|
+
const context = validateContext();
|
|
285
|
+
const { system: aiSystem, modelName } = getModelInfo(params.model);
|
|
286
|
+
return tracing_js_1.paidTracer.startActiveSpan("trace.ai-sdk.embedMany", (span) => __awaiter(this, void 0, void 0, function* () {
|
|
287
|
+
const attributes = {
|
|
288
|
+
"gen_ai.system": aiSystem,
|
|
289
|
+
"gen_ai.operation.name": "embeddings",
|
|
290
|
+
"external_customer_id": context.externalCustomerId,
|
|
291
|
+
"token": context.token,
|
|
292
|
+
};
|
|
293
|
+
if (context.externalAgentId) {
|
|
294
|
+
attributes["external_agent_id"] = context.externalAgentId;
|
|
295
|
+
}
|
|
296
|
+
if (modelName) {
|
|
297
|
+
attributes["gen_ai.request.model"] = modelName;
|
|
298
|
+
}
|
|
299
|
+
span.setAttributes(attributes);
|
|
300
|
+
try {
|
|
301
|
+
const result = yield (0, ai_1.embedMany)(params);
|
|
302
|
+
if (result.usage) {
|
|
303
|
+
const usageAttrs = extractUsageMetrics(result.usage);
|
|
304
|
+
span.setAttributes(usageAttrs);
|
|
305
|
+
}
|
|
306
|
+
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
307
|
+
return result;
|
|
308
|
+
}
|
|
309
|
+
catch (error) {
|
|
310
|
+
span.setStatus({ code: api_1.SpanStatusCode.ERROR, message: error.message });
|
|
311
|
+
span.recordException(error);
|
|
312
|
+
throw error;
|
|
313
|
+
}
|
|
314
|
+
finally {
|
|
315
|
+
span.end();
|
|
316
|
+
}
|
|
317
|
+
}));
|
|
318
|
+
});
|
|
319
|
+
}
|
|
320
|
+
exports.default = {
|
|
321
|
+
generateText,
|
|
322
|
+
streamText,
|
|
323
|
+
generateObject,
|
|
324
|
+
streamObject,
|
|
325
|
+
embed,
|
|
326
|
+
embedMany,
|
|
327
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { generateText as paidVercelGenerateText, streamText as paidVercelStreamText, generateObject as paidVercelGenerateObject, streamObject as paidVercelStreamObject, embed as paidVercelEmbed, embedMany as paidVercelEmbedMany, } from "../tracing/wrappers/vercelAIWrapper.js";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.paidVercelEmbedMany = exports.paidVercelEmbed = exports.paidVercelStreamObject = exports.paidVercelGenerateObject = exports.paidVercelStreamText = exports.paidVercelGenerateText = void 0;
|
|
4
|
+
var vercelAIWrapper_js_1 = require("../tracing/wrappers/vercelAIWrapper.js");
|
|
5
|
+
Object.defineProperty(exports, "paidVercelGenerateText", { enumerable: true, get: function () { return vercelAIWrapper_js_1.generateText; } });
|
|
6
|
+
Object.defineProperty(exports, "paidVercelStreamText", { enumerable: true, get: function () { return vercelAIWrapper_js_1.streamText; } });
|
|
7
|
+
Object.defineProperty(exports, "paidVercelGenerateObject", { enumerable: true, get: function () { return vercelAIWrapper_js_1.generateObject; } });
|
|
8
|
+
Object.defineProperty(exports, "paidVercelStreamObject", { enumerable: true, get: function () { return vercelAIWrapper_js_1.streamObject; } });
|
|
9
|
+
Object.defineProperty(exports, "paidVercelEmbed", { enumerable: true, get: function () { return vercelAIWrapper_js_1.embed; } });
|
|
10
|
+
Object.defineProperty(exports, "paidVercelEmbedMany", { enumerable: true, get: function () { return vercelAIWrapper_js_1.embedMany; } });
|
package/dist/cjs/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.0
|
|
1
|
+
export declare const SDK_VERSION = "0.2.0";
|
package/dist/cjs/version.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as core from "../core/index.js";
|
|
2
|
-
import { Usage as UsageClient } from "../api/resources/usage/client/Client";
|
|
2
|
+
import { Usage as UsageClient } from "../api/resources/usage/client/Client.js";
|
|
3
3
|
import * as Paid from "../api/types/Signal.js";
|
|
4
4
|
export declare class Usage extends UsageClient {
|
|
5
5
|
private signals;
|
|
6
|
-
flush(requestOptions?: UsageClient.RequestOptions): core.HttpResponsePromise<
|
|
7
|
-
|
|
6
|
+
flush(requestOptions?: UsageClient.RequestOptions): core.HttpResponsePromise<void>;
|
|
7
|
+
record(signal?: Paid.Signal, requestOptions?: UsageClient.RequestOptions): core.HttpResponsePromise<void>;
|
|
8
8
|
}
|
|
@@ -35,8 +35,8 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.Usage = void 0;
|
|
37
37
|
const core = __importStar(require("../core/index.js"));
|
|
38
|
-
const
|
|
39
|
-
class Usage extends
|
|
38
|
+
const Client_js_1 = require("../api/resources/usage/client/Client.js");
|
|
39
|
+
class Usage extends Client_js_1.Usage {
|
|
40
40
|
constructor() {
|
|
41
41
|
super(...arguments);
|
|
42
42
|
this.signals = [];
|
|
@@ -44,7 +44,7 @@ class Usage extends Client_1.Usage {
|
|
|
44
44
|
flush(requestOptions) {
|
|
45
45
|
return this.recordBulk({ signals: this.signals }, requestOptions);
|
|
46
46
|
}
|
|
47
|
-
|
|
47
|
+
record(signal = {}, requestOptions) {
|
|
48
48
|
if (!this.signals) {
|
|
49
49
|
this.signals = [];
|
|
50
50
|
}
|
|
@@ -54,7 +54,7 @@ class Usage extends Client_1.Usage {
|
|
|
54
54
|
this.signals = [];
|
|
55
55
|
return response;
|
|
56
56
|
}
|
|
57
|
-
return core.HttpResponsePromise.fromResult({ data:
|
|
57
|
+
return core.HttpResponsePromise.fromResult({ data: undefined, rawResponse: {} });
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
exports.Usage = Usage;
|
package/dist/esm/Client.d.mts
CHANGED
|
@@ -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
|
}
|
package/dist/esm/Client.mjs
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* This file was auto-generated by Fern from our API Definition.
|
|
3
3
|
*/
|
|
4
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
+
});
|
|
12
|
+
};
|
|
4
13
|
import * as core from "./core/index.mjs";
|
|
5
14
|
import { mergeHeaders } from "./core/headers.mjs";
|
|
6
15
|
import { Customers } from "./api/resources/customers/client/Client.mjs";
|
|
@@ -8,13 +17,15 @@ import { Agents } from "./api/resources/agents/client/Client.mjs";
|
|
|
8
17
|
import { Contacts } from "./api/resources/contacts/client/Client.mjs";
|
|
9
18
|
import { Orders } from "./api/resources/orders/client/Client.mjs";
|
|
10
19
|
import { Usage } from "./wrapper/BatchUsage.mjs";
|
|
20
|
+
import { _trace, _initializeTracing } from "./tracing/tracing.mjs";
|
|
21
|
+
import { _signal } from "./tracing/signal.mjs";
|
|
11
22
|
export class PaidClient {
|
|
12
23
|
constructor(_options) {
|
|
13
24
|
this._options = Object.assign(Object.assign({}, _options), { headers: mergeHeaders({
|
|
14
25
|
"X-Fern-Language": "JavaScript",
|
|
15
26
|
"X-Fern-SDK-Name": "@paid-ai/paid-node",
|
|
16
|
-
"X-Fern-SDK-Version": "0.0
|
|
17
|
-
"User-Agent": "@paid-ai/paid-node/0.0
|
|
27
|
+
"X-Fern-SDK-Version": "0.2.0",
|
|
28
|
+
"User-Agent": "@paid-ai/paid-node/0.2.0",
|
|
18
29
|
"X-Fern-Runtime": core.RUNTIME.type,
|
|
19
30
|
"X-Fern-Runtime-Version": core.RUNTIME.version,
|
|
20
31
|
}, _options === null || _options === void 0 ? void 0 : _options.headers) });
|
|
@@ -39,4 +50,36 @@ export class PaidClient {
|
|
|
39
50
|
var _a;
|
|
40
51
|
return ((_a = this._usage) !== null && _a !== void 0 ? _a : (this._usage = new Usage(this._options)));
|
|
41
52
|
}
|
|
53
|
+
// Need to call this method before using tracing or creating wrappers.
|
|
54
|
+
initializeTracing(collectorEndpoint) {
|
|
55
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
56
|
+
const tokenSupplier = this._options.token;
|
|
57
|
+
const token = typeof tokenSupplier === "function" ? yield tokenSupplier() : tokenSupplier;
|
|
58
|
+
const resolvedToken = yield Promise.resolve(token);
|
|
59
|
+
_initializeTracing(resolvedToken, collectorEndpoint);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
// Use this method to track actions like LLM costs and sending signals.
|
|
63
|
+
// The callback to this function is the work that you want to trace.
|
|
64
|
+
trace(externalCustomerId, fn, externalAgentId, ...args) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
return yield _trace(externalCustomerId, fn, externalAgentId, ...args);
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
signal(eventName, enableCostTracingOrData, data) {
|
|
70
|
+
let enableCostTracing = false;
|
|
71
|
+
let finalData;
|
|
72
|
+
if (typeof enableCostTracingOrData === 'boolean') {
|
|
73
|
+
// Case: signal(eventName, boolean, data?)
|
|
74
|
+
enableCostTracing = enableCostTracingOrData;
|
|
75
|
+
finalData = data;
|
|
76
|
+
}
|
|
77
|
+
else if (typeof enableCostTracingOrData === 'object') {
|
|
78
|
+
// Case: signal(eventName, data)
|
|
79
|
+
enableCostTracing = false;
|
|
80
|
+
finalData = enableCostTracingOrData;
|
|
81
|
+
}
|
|
82
|
+
// Case: signal(eventName) - both remain default/undefined
|
|
83
|
+
return _signal(eventName, enableCostTracing, finalData);
|
|
84
|
+
}
|
|
42
85
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PaidAnthropic } from "../tracing/wrappers/anthropicWrapper.mjs";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PaidAnthropic } from "../tracing/wrappers/anthropicWrapper.mjs";
|
|
@@ -41,8 +41,9 @@ export declare class Agents {
|
|
|
41
41
|
*
|
|
42
42
|
* @example
|
|
43
43
|
* await client.agents.create({
|
|
44
|
-
* name: "
|
|
45
|
-
* 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;
|
|
@@ -72,8 +72,9 @@ export class Agents {
|
|
|
72
72
|
*
|
|
73
73
|
* @example
|
|
74
74
|
* await client.agents.create({
|
|
75
|
-
* name: "
|
|
76
|
-
* description: "
|
|
75
|
+
* name: "Acme Agent",
|
|
76
|
+
* description: "Acme Agent is an AI agent that does things.",
|
|
77
|
+
* externalId: "acme-agent"
|
|
77
78
|
* })
|
|
78
79
|
*/
|
|
79
80
|
create(request, requestOptions) {
|
|
@@ -174,7 +175,36 @@ export class Agents {
|
|
|
174
175
|
* @param {Agents.RequestOptions} requestOptions - Request-specific configuration.
|
|
175
176
|
*
|
|
176
177
|
* @example
|
|
177
|
-
* await client.agents.update("agentId", {
|
|
178
|
+
* await client.agents.update("agentId", {
|
|
179
|
+
* name: "Acme Agent (Updated)",
|
|
180
|
+
* agentAttributes: [{
|
|
181
|
+
* name: "Emails sent signal",
|
|
182
|
+
* active: true,
|
|
183
|
+
* pricing: {
|
|
184
|
+
* eventName: "emails_sent",
|
|
185
|
+
* taxable: true,
|
|
186
|
+
* chargeType: "usage",
|
|
187
|
+
* pricingModel: "PerUnit",
|
|
188
|
+
* billingFrequency: "monthly",
|
|
189
|
+
* pricePoints: {
|
|
190
|
+
* "USD": {
|
|
191
|
+
* tiers: [{
|
|
192
|
+
* minQuantity: 0,
|
|
193
|
+
* maxQuantity: 10,
|
|
194
|
+
* unitPrice: 100
|
|
195
|
+
* }, {
|
|
196
|
+
* minQuantity: 11,
|
|
197
|
+
* maxQuantity: 100,
|
|
198
|
+
* unitPrice: 90
|
|
199
|
+
* }, {
|
|
200
|
+
* minQuantity: 101,
|
|
201
|
+
* unitPrice: 80
|
|
202
|
+
* }]
|
|
203
|
+
* }
|
|
204
|
+
* }
|
|
205
|
+
* }
|
|
206
|
+
* }]
|
|
207
|
+
* })
|
|
178
208
|
*/
|
|
179
209
|
update(agentId, request, requestOptions) {
|
|
180
210
|
return core.HttpResponsePromise.fromPromise(this.__update(agentId, request, requestOptions));
|
|
@@ -322,7 +352,25 @@ export class Agents {
|
|
|
322
352
|
* @param {Agents.RequestOptions} requestOptions - Request-specific configuration.
|
|
323
353
|
*
|
|
324
354
|
* @example
|
|
325
|
-
* await client.agents.updateByExternalId("externalId", {
|
|
355
|
+
* await client.agents.updateByExternalId("externalId", {
|
|
356
|
+
* name: "Acme Agent (Updated)",
|
|
357
|
+
* agentAttributes: [{
|
|
358
|
+
* name: "Emails sent signal",
|
|
359
|
+
* active: true,
|
|
360
|
+
* pricing: {
|
|
361
|
+
* eventName: "emails_sent",
|
|
362
|
+
* taxable: true,
|
|
363
|
+
* chargeType: "usage",
|
|
364
|
+
* pricingModel: "PerUnit",
|
|
365
|
+
* billingFrequency: "monthly",
|
|
366
|
+
* pricePoints: {
|
|
367
|
+
* "USD": {
|
|
368
|
+
* unitPrice: 150
|
|
369
|
+
* }
|
|
370
|
+
* }
|
|
371
|
+
* }
|
|
372
|
+
* }]
|
|
373
|
+
* })
|
|
326
374
|
*/
|
|
327
375
|
updateByExternalId(externalId, request, requestOptions) {
|
|
328
376
|
return core.HttpResponsePromise.fromPromise(this.__updateByExternalId(externalId, request, requestOptions));
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
/**
|
|
5
5
|
* @example
|
|
6
6
|
* {
|
|
7
|
-
* name: "
|
|
8
|
-
* 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
|
}
|