@paid-ai/paid-node 0.0.8-alpha1 → 0.0.8-alpha3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +17 -16
- package/dist/cjs/Client.d.ts +3 -2
- package/dist/cjs/Client.js +12 -4
- package/dist/cjs/index.d.ts +3 -1
- package/dist/cjs/index.js +7 -4
- package/dist/cjs/tracing/signal.d.ts +1 -0
- package/dist/cjs/tracing/signal.js +45 -0
- package/dist/cjs/tracing/tracing.d.ts +7 -3
- package/dist/cjs/tracing/tracing.js +78 -31
- 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.js +42 -56
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wrapper/BatchUsage.d.ts +1 -1
- package/dist/cjs/wrapper/BatchUsage.js +2 -2
- package/dist/esm/Client.d.mts +3 -2
- package/dist/esm/Client.mjs +13 -5
- package/dist/esm/index.d.mts +3 -1
- package/dist/esm/index.mjs +3 -1
- package/dist/esm/tracing/signal.d.mts +1 -0
- package/dist/esm/tracing/signal.mjs +42 -0
- package/dist/esm/tracing/tracing.d.mts +7 -3
- package/dist/esm/tracing/tracing.mjs +73 -30
- 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.mjs +42 -56
- package/dist/esm/version.d.mts +1 -1
- package/dist/esm/version.mjs +1 -1
- package/dist/esm/wrapper/BatchUsage.d.mts +1 -1
- package/dist/esm/wrapper/BatchUsage.mjs +1 -1
- package/package.json +7 -3
- package/dist/cjs/tracing/index.d.ts +0 -1
- package/dist/cjs/tracing/index.js +0 -17
- package/dist/esm/tracing/index.d.mts +0 -1
- package/dist/esm/tracing/index.mjs +0 -1
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { BaseCallbackHandler } from "@langchain/core/callbacks/base";
|
|
2
|
+
interface SerializedData {
|
|
3
|
+
id?: string[];
|
|
4
|
+
[key: string]: any;
|
|
5
|
+
}
|
|
6
|
+
interface Metadata {
|
|
7
|
+
ls_model_type?: string;
|
|
8
|
+
ls_model_name?: string;
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}
|
|
11
|
+
export declare class PaidLangChainCallback extends BaseCallbackHandler {
|
|
12
|
+
name: string;
|
|
13
|
+
private tracer;
|
|
14
|
+
private spans;
|
|
15
|
+
constructor();
|
|
16
|
+
private extractProvider;
|
|
17
|
+
handleLLMStart(llm: SerializedData, prompts: string[], runId: string, parentRunId?: string, extraParams?: Record<string, unknown>, tags?: string[], metadata?: Metadata): Promise<void>;
|
|
18
|
+
handleLLMEnd(output: any, runId: string, parentRunId?: string): Promise<void>;
|
|
19
|
+
handleLLMError(err: Error, runId: string, parentRunId?: string): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { BaseCallbackHandler } from "@langchain/core/callbacks/base";
|
|
11
|
+
import { SpanStatusCode } from "@opentelemetry/api";
|
|
12
|
+
import { getCustomerIdStorage, getAgentIdStorage, getTokenStorage, paidTracer } from "../tracing.mjs";
|
|
13
|
+
export class PaidLangChainCallback extends BaseCallbackHandler {
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
this.name = "PaidLangChainCallback";
|
|
17
|
+
this.spans = new Map();
|
|
18
|
+
this.tracer = paidTracer;
|
|
19
|
+
}
|
|
20
|
+
extractProvider(serialized) {
|
|
21
|
+
if (!(serialized === null || serialized === void 0 ? void 0 : serialized.id))
|
|
22
|
+
return "unknown";
|
|
23
|
+
const idStr = serialized.id.join(" ").toLowerCase();
|
|
24
|
+
if (idStr.includes("openai"))
|
|
25
|
+
return "openai";
|
|
26
|
+
if (idStr.includes("anthropic"))
|
|
27
|
+
return "anthropic";
|
|
28
|
+
if (idStr.includes("mistral"))
|
|
29
|
+
return "mistral";
|
|
30
|
+
if (idStr.includes("cohere"))
|
|
31
|
+
return "cohere";
|
|
32
|
+
if (idStr.includes("huggingface"))
|
|
33
|
+
return "huggingface";
|
|
34
|
+
if (idStr.includes("azure"))
|
|
35
|
+
return "azure";
|
|
36
|
+
return "unknown";
|
|
37
|
+
}
|
|
38
|
+
handleLLMStart(llm, prompts, runId, parentRunId, extraParams, tags, metadata) {
|
|
39
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
const externalCustomerId = getCustomerIdStorage();
|
|
41
|
+
const externalAgentId = getAgentIdStorage();
|
|
42
|
+
const token = getTokenStorage();
|
|
43
|
+
if (!token || !externalCustomerId) {
|
|
44
|
+
throw new Error("No token or externalCustomerId: This wrapper should be used inside a callback to paid.trace().");
|
|
45
|
+
}
|
|
46
|
+
const modelType = (metadata === null || metadata === void 0 ? void 0 : metadata.ls_model_type) || "unknown";
|
|
47
|
+
const modelName = (metadata === null || metadata === void 0 ? void 0 : metadata.ls_model_name) || "unknown";
|
|
48
|
+
const spanName = `trace.langchain.${modelType}`;
|
|
49
|
+
const span = this.tracer.startSpan(spanName);
|
|
50
|
+
const attributes = {
|
|
51
|
+
"gen_ai.system": this.extractProvider(llm),
|
|
52
|
+
"gen_ai.operation.name": modelType,
|
|
53
|
+
"gen_ai.request.model": modelName,
|
|
54
|
+
external_customer_id: externalCustomerId,
|
|
55
|
+
token: token,
|
|
56
|
+
};
|
|
57
|
+
if (externalAgentId) {
|
|
58
|
+
attributes["external_agent_id"] = externalAgentId;
|
|
59
|
+
}
|
|
60
|
+
span.setAttributes(attributes);
|
|
61
|
+
this.spans.set(runId, span);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
handleLLMEnd(output, runId, parentRunId) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
66
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
67
|
+
const span = this.spans.get(runId);
|
|
68
|
+
if (!span)
|
|
69
|
+
return;
|
|
70
|
+
try {
|
|
71
|
+
const attributes = {};
|
|
72
|
+
// Extract token usage information
|
|
73
|
+
if ((_a = output.llmOutput) === null || _a === void 0 ? void 0 : _a.tokenUsage) {
|
|
74
|
+
const usage = output.llmOutput.tokenUsage;
|
|
75
|
+
if (usage.promptTokens !== undefined) {
|
|
76
|
+
attributes["gen_ai.usage.input_tokens"] = usage.promptTokens;
|
|
77
|
+
}
|
|
78
|
+
if (usage.completionTokens !== undefined) {
|
|
79
|
+
attributes["gen_ai.usage.output_tokens"] = usage.completionTokens;
|
|
80
|
+
}
|
|
81
|
+
if (usage.cachedInputTokens !== undefined) {
|
|
82
|
+
attributes["gen_ai.usage.cached_input_tokens"] = usage.cachedInputTokens;
|
|
83
|
+
}
|
|
84
|
+
if (usage.reasoningOutputTokens !== undefined) {
|
|
85
|
+
attributes["gen_ai.usage.reasoning_output_tokens"] = usage.reasoningOutputTokens;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
// Alternative token usage format (some providers use different field names)
|
|
89
|
+
if ((_b = output.llmOutput) === null || _b === void 0 ? void 0 : _b.token_usage) {
|
|
90
|
+
const usage = output.llmOutput.token_usage;
|
|
91
|
+
if (usage.prompt_tokens !== undefined) {
|
|
92
|
+
attributes["gen_ai.usage.input_tokens"] = usage.prompt_tokens;
|
|
93
|
+
}
|
|
94
|
+
if (usage.completion_tokens !== undefined) {
|
|
95
|
+
attributes["gen_ai.usage.output_tokens"] = usage.completion_tokens;
|
|
96
|
+
}
|
|
97
|
+
if (usage.cached_input_tokens !== undefined) {
|
|
98
|
+
attributes["gen_ai.usage.cached_input_tokens"] = usage.cached_input_tokens;
|
|
99
|
+
}
|
|
100
|
+
if (usage.reasoning_output_tokens !== undefined) {
|
|
101
|
+
attributes["gen_ai.usage.reasoning_output_tokens"] = usage.reasoning_output_tokens;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
// Add model from response if available
|
|
105
|
+
if ((_c = output.llmOutput) === null || _c === void 0 ? void 0 : _c.modelName) {
|
|
106
|
+
attributes["gen_ai.response.model"] = output.llmOutput.modelName;
|
|
107
|
+
}
|
|
108
|
+
else if ((_d = output.llmOutput) === null || _d === void 0 ? void 0 : _d.model_name) {
|
|
109
|
+
attributes["gen_ai.response.model"] = output.llmOutput.model_name;
|
|
110
|
+
}
|
|
111
|
+
else if ((_j = (_h = (_g = (_f = (_e = output.generations) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f[0]) === null || _g === void 0 ? void 0 : _g.message) === null || _h === void 0 ? void 0 : _h["response_metadata"]) === null || _j === void 0 ? void 0 : _j.model_name) {
|
|
112
|
+
attributes["gen_ai.response.model"] = output.generations[0][0].message["response_metadata"].model_name;
|
|
113
|
+
}
|
|
114
|
+
span.setAttributes(attributes);
|
|
115
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
116
|
+
}
|
|
117
|
+
finally {
|
|
118
|
+
span.end();
|
|
119
|
+
this.spans.delete(runId);
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
handleLLMError(err, runId, parentRunId) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const span = this.spans.get(runId);
|
|
126
|
+
if (!span)
|
|
127
|
+
return;
|
|
128
|
+
try {
|
|
129
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: err.message });
|
|
130
|
+
span.recordException(err);
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
span.end();
|
|
134
|
+
this.spans.delete(runId);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Mistral } from "@mistralai/mistralai";
|
|
2
|
+
import { Tracer } from "@opentelemetry/api";
|
|
3
|
+
import { OCRRequest, OCRResponse } from "@mistralai/mistralai/models/components";
|
|
4
|
+
import { RequestOptions } from "@mistralai/mistralai/lib/sdks";
|
|
5
|
+
export declare class PaidMistral {
|
|
6
|
+
private readonly mistral;
|
|
7
|
+
private readonly tracer;
|
|
8
|
+
constructor(mistralClient: Mistral);
|
|
9
|
+
get ocr(): OCRWrapper;
|
|
10
|
+
}
|
|
11
|
+
declare class OCRWrapper {
|
|
12
|
+
private mistral;
|
|
13
|
+
private tracer;
|
|
14
|
+
constructor(mistral: Mistral, tracer: Tracer);
|
|
15
|
+
process(request: OCRRequest, options?: RequestOptions): Promise<OCRResponse>;
|
|
16
|
+
}
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { SpanStatusCode } from "@opentelemetry/api";
|
|
11
|
+
import { getCustomerIdStorage, getAgentIdStorage, getTokenStorage, paidTracer } from "../tracing.mjs";
|
|
12
|
+
export class PaidMistral {
|
|
13
|
+
constructor(mistralClient) {
|
|
14
|
+
this.mistral = mistralClient;
|
|
15
|
+
this.tracer = paidTracer;
|
|
16
|
+
}
|
|
17
|
+
get ocr() {
|
|
18
|
+
return new OCRWrapper(this.mistral, this.tracer);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
class OCRWrapper {
|
|
22
|
+
constructor(mistral, tracer) {
|
|
23
|
+
this.mistral = mistral;
|
|
24
|
+
this.tracer = tracer;
|
|
25
|
+
}
|
|
26
|
+
process(request, options) {
|
|
27
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
28
|
+
const externalCustomerId = getCustomerIdStorage();
|
|
29
|
+
const externalAgentId = getAgentIdStorage();
|
|
30
|
+
const token = getTokenStorage();
|
|
31
|
+
if (!token || !externalCustomerId) {
|
|
32
|
+
throw new Error("No token or externalCustomerId: This wrapper should be used inside a callback to paid.trace().");
|
|
33
|
+
}
|
|
34
|
+
return this.tracer.startActiveSpan("trace.mistral.ocr", (span) => __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
var _a;
|
|
36
|
+
const attributes = {
|
|
37
|
+
"gen_ai.system": "mistral",
|
|
38
|
+
"gen_ai.operation.name": "ocr",
|
|
39
|
+
external_customer_id: externalCustomerId,
|
|
40
|
+
token: token,
|
|
41
|
+
};
|
|
42
|
+
if (externalAgentId) {
|
|
43
|
+
attributes["external_agent_id"] = externalAgentId;
|
|
44
|
+
}
|
|
45
|
+
// Check if annotations are requested
|
|
46
|
+
if (request.bboxAnnotationFormat || request.documentAnnotationFormat) {
|
|
47
|
+
attributes["gen_ai.ocr.annotated"] = "true";
|
|
48
|
+
}
|
|
49
|
+
// Set request model
|
|
50
|
+
if (request.model) {
|
|
51
|
+
attributes["gen_ai.request.model"] = request.model;
|
|
52
|
+
}
|
|
53
|
+
span.setAttributes(attributes);
|
|
54
|
+
try {
|
|
55
|
+
const response = yield this.mistral.ocr.process(request, options);
|
|
56
|
+
// Add usage information from response
|
|
57
|
+
if (((_a = response.usageInfo) === null || _a === void 0 ? void 0 : _a.pagesProcessed) !== undefined) {
|
|
58
|
+
span.setAttribute("gen_ai.ocr.pages_processed", response.usageInfo.pagesProcessed);
|
|
59
|
+
}
|
|
60
|
+
if (response.model) {
|
|
61
|
+
span.setAttribute("gen_ai.response.model", response.model);
|
|
62
|
+
}
|
|
63
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
64
|
+
return response;
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: error.message });
|
|
68
|
+
span.recordException(error);
|
|
69
|
+
throw error;
|
|
70
|
+
}
|
|
71
|
+
finally {
|
|
72
|
+
span.end();
|
|
73
|
+
}
|
|
74
|
+
}));
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -7,12 +7,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
10
|
+
import { SpanStatusCode } from "@opentelemetry/api";
|
|
11
|
+
import { getCustomerIdStorage, getAgentIdStorage, getTokenStorage, paidTracer } from "../tracing.mjs";
|
|
12
12
|
export class PaidOpenAI {
|
|
13
13
|
constructor(openaiClient) {
|
|
14
14
|
this.openai = openaiClient;
|
|
15
|
-
this.tracer =
|
|
15
|
+
this.tracer = paidTracer;
|
|
16
16
|
}
|
|
17
17
|
get chat() {
|
|
18
18
|
return new ChatWrapper(this.openai, this.tracer);
|
|
@@ -43,25 +43,21 @@ class ChatCompletionsWrapper {
|
|
|
43
43
|
}
|
|
44
44
|
create(params) {
|
|
45
45
|
return __awaiter(this, void 0, void 0, function* () {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
console.warn("No active span found, calling OpenAI directly without tracing.");
|
|
49
|
-
return this.openai.chat.completions.create(params);
|
|
50
|
-
}
|
|
51
|
-
const externalCustomerId = getCustomerId();
|
|
46
|
+
const externalCustomerId = getCustomerIdStorage();
|
|
47
|
+
const externalAgentId = getAgentIdStorage();
|
|
52
48
|
const token = getTokenStorage();
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
49
|
+
if (!token || !externalCustomerId) {
|
|
50
|
+
throw new Error("No token or externalCustomerId: This wrapper should be used inside a callback to paid.trace().");
|
|
51
|
+
}
|
|
52
|
+
return this.tracer.startActiveSpan("trace.openai.chat", (span) => __awaiter(this, void 0, void 0, function* () {
|
|
56
53
|
const attributes = {
|
|
57
54
|
"gen_ai.system": "openai",
|
|
58
55
|
"gen_ai.operation.name": "chat",
|
|
59
56
|
};
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
attributes["token"] = token;
|
|
57
|
+
attributes["external_customer_id"] = externalCustomerId;
|
|
58
|
+
attributes["token"] = token;
|
|
59
|
+
if (externalAgentId) {
|
|
60
|
+
attributes["external_agent_id"] = externalAgentId;
|
|
65
61
|
}
|
|
66
62
|
span.setAttributes(attributes);
|
|
67
63
|
try {
|
|
@@ -95,24 +91,22 @@ class ResponsesWrapper {
|
|
|
95
91
|
}
|
|
96
92
|
create(params) {
|
|
97
93
|
return __awaiter(this, void 0, void 0, function* () {
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
console.warn("No active span found, calling OpenAI directly without tracing.");
|
|
101
|
-
return this.openai.responses.create(params);
|
|
102
|
-
}
|
|
103
|
-
const externalCustomerId = getCustomerId();
|
|
94
|
+
const externalCustomerId = getCustomerIdStorage();
|
|
95
|
+
const externalAgentId = getAgentIdStorage();
|
|
104
96
|
const token = getTokenStorage();
|
|
97
|
+
if (!token || !externalCustomerId) {
|
|
98
|
+
throw new Error("No token or externalCustomerId: This wrapper should be used inside a callback to paid.trace().");
|
|
99
|
+
}
|
|
105
100
|
return this.tracer.startActiveSpan("trace.openai.responses", (span) => __awaiter(this, void 0, void 0, function* () {
|
|
106
101
|
var _a, _b;
|
|
107
102
|
const attributes = {
|
|
108
103
|
"gen_ai.system": "openai",
|
|
109
104
|
"gen_ai.operation.name": "chat", // Equivalent to chat.completions
|
|
110
105
|
};
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
attributes["token"] = token;
|
|
106
|
+
attributes["external_customer_id"] = externalCustomerId;
|
|
107
|
+
attributes["token"] = token;
|
|
108
|
+
if (externalAgentId) {
|
|
109
|
+
attributes["external_agent_id"] = externalAgentId;
|
|
116
110
|
}
|
|
117
111
|
span.setAttributes(attributes);
|
|
118
112
|
try {
|
|
@@ -152,26 +146,21 @@ class EmbeddingsWrapper {
|
|
|
152
146
|
}
|
|
153
147
|
create(params) {
|
|
154
148
|
return __awaiter(this, void 0, void 0, function* () {
|
|
155
|
-
|
|
156
|
-
const
|
|
157
|
-
if (!currentSpan) {
|
|
158
|
-
console.warn("No active span found, calling OpenAI directly without tracing.");
|
|
159
|
-
return this.openai.embeddings.create(params);
|
|
160
|
-
}
|
|
161
|
-
const externalCustomerId = getCustomerId();
|
|
149
|
+
const externalCustomerId = getCustomerIdStorage();
|
|
150
|
+
const externalAgentId = getAgentIdStorage();
|
|
162
151
|
const token = getTokenStorage();
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
152
|
+
if (!token || !externalCustomerId) {
|
|
153
|
+
throw new Error("No token or externalCustomerId: This wrapper should be used inside a callback to paid.trace().");
|
|
154
|
+
}
|
|
155
|
+
return this.tracer.startActiveSpan("trace.openai.embeddings", (span) => __awaiter(this, void 0, void 0, function* () {
|
|
166
156
|
const attributes = {
|
|
167
157
|
"gen_ai.system": "openai",
|
|
168
158
|
"gen_ai.operation.name": "embeddings",
|
|
169
159
|
};
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
attributes["token"] = token;
|
|
160
|
+
attributes["external_customer_id"] = externalCustomerId;
|
|
161
|
+
attributes["token"] = token;
|
|
162
|
+
if (externalAgentId) {
|
|
163
|
+
attributes["external_agent_id"] = externalAgentId;
|
|
175
164
|
}
|
|
176
165
|
span.setAttributes(attributes);
|
|
177
166
|
try {
|
|
@@ -205,27 +194,24 @@ class ImagesWrapper {
|
|
|
205
194
|
generate(params) {
|
|
206
195
|
return __awaiter(this, void 0, void 0, function* () {
|
|
207
196
|
var _a;
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
console.warn("No active span found, calling OpenAI directly without tracing.");
|
|
211
|
-
return this.openai.images.generate(params);
|
|
212
|
-
}
|
|
213
|
-
const externalCustomerId = getCustomerId();
|
|
197
|
+
const externalCustomerId = getCustomerIdStorage();
|
|
198
|
+
const externalAgentId = getAgentIdStorage();
|
|
214
199
|
const token = getTokenStorage();
|
|
215
200
|
const model = (_a = params.model) !== null && _a !== void 0 ? _a : "dall-e-3";
|
|
216
|
-
|
|
217
|
-
|
|
201
|
+
if (!token || !externalCustomerId) {
|
|
202
|
+
throw new Error("No token or externalCustomerId: This wrapper should be used inside a callback to paid.trace().");
|
|
203
|
+
}
|
|
204
|
+
return this.tracer.startActiveSpan("trace.openai.images", (span) => __awaiter(this, void 0, void 0, function* () {
|
|
218
205
|
var _a, _b, _c;
|
|
219
206
|
const attributes = {
|
|
220
207
|
"gen_ai.request.model": model,
|
|
221
208
|
"gen_ai.system": "openai",
|
|
222
209
|
"gen_ai.operation.name": "image_generation",
|
|
223
210
|
};
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
attributes["token"] = token;
|
|
211
|
+
attributes["external_customer_id"] = externalCustomerId;
|
|
212
|
+
attributes["token"] = token;
|
|
213
|
+
if (externalAgentId) {
|
|
214
|
+
attributes["external_agent_id"] = externalAgentId;
|
|
229
215
|
}
|
|
230
216
|
span.setAttributes(attributes);
|
|
231
217
|
try {
|
package/dist/esm/version.d.mts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.0.8-
|
|
1
|
+
export declare const SDK_VERSION = "0.0.8-alpha3";
|
package/dist/esm/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.0.8-
|
|
1
|
+
export const SDK_VERSION = "0.0.8-alpha3";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as core from "../core/index.mjs";
|
|
2
|
-
import { Usage as UsageClient } from "../api/resources/usage/client/Client";
|
|
2
|
+
import { Usage as UsageClient } from "../api/resources/usage/client/Client.mjs";
|
|
3
3
|
import * as Paid from "../api/types/Signal.mjs";
|
|
4
4
|
export declare class Usage extends UsageClient {
|
|
5
5
|
private signals;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as core from "../core/index.mjs";
|
|
2
|
-
import { Usage as UsageClient } from "../api/resources/usage/client/Client";
|
|
2
|
+
import { Usage as UsageClient } from "../api/resources/usage/client/Client.mjs";
|
|
3
3
|
export class Usage extends UsageClient {
|
|
4
4
|
constructor() {
|
|
5
5
|
super(...arguments);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paid-ai/paid-node",
|
|
3
|
-
"version": "0.0.8-
|
|
3
|
+
"version": "0.0.8-alpha3",
|
|
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";
|