langwatch 0.1.0 → 0.1.3
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/copy-types.sh +17 -0
- package/dist/chunk-2I4YLOQY.mjs +736 -0
- package/dist/chunk-2I4YLOQY.mjs.map +1 -0
- package/dist/index.d.mts +352 -4
- package/dist/index.d.ts +352 -4
- package/dist/index.js +6505 -413
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +571 -359
- package/dist/index.mjs.map +1 -1
- package/dist/{utils-DDcm0z9v.d.mts → utils-CFtM8VVg.d.mts} +108 -31
- package/dist/{utils-DDcm0z9v.d.ts → utils-CFtM8VVg.d.ts} +108 -31
- package/dist/utils.d.mts +1 -2
- package/dist/utils.d.ts +1 -2
- package/dist/utils.js +437 -0
- package/dist/utils.js.map +1 -1
- package/dist/utils.mjs +3 -1
- package/example/README.md +3 -1
- package/example/app/(chat)/chat/[id]/page.tsx +1 -1
- package/example/app/(chat)/page.tsx +10 -5
- package/example/app/guardrails/page.tsx +26 -0
- package/example/app/langchain/page.tsx +27 -0
- package/example/app/langchain-rag/page.tsx +28 -0
- package/example/app/share/[id]/page.tsx +1 -1
- package/example/components/chat-list.tsx +1 -1
- package/example/components/chat-panel.tsx +1 -1
- package/example/components/header.tsx +39 -13
- package/example/components/prompt-form.tsx +1 -1
- package/example/components/stocks/stock-purchase.tsx +1 -1
- package/example/components/stocks/stocks.tsx +1 -1
- package/example/lib/chat/guardrails.tsx +181 -0
- package/example/lib/chat/langchain-rag.tsx +191 -0
- package/example/lib/chat/langchain.tsx +112 -0
- package/example/lib/chat/{actions.tsx → vercel-ai.tsx} +1 -1
- package/example/package-lock.json +289 -6
- package/example/package.json +1 -0
- package/package.json +13 -5
- package/src/evaluations.ts +219 -0
- package/src/index.test.ts +5 -0
- package/src/index.ts +190 -7
- package/src/langchain.ts +557 -0
- package/src/{helpers.ts → typeUtils.ts} +20 -2
- package/src/types.ts +7 -3
- package/src/utils.ts +25 -2
- package/ts-to-zod.config.js +2 -0
- package/dist/chunk-AP23NJ57.mjs +0 -296
- package/dist/chunk-AP23NJ57.mjs.map +0 -1
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CoreMessage } from 'ai';
|
|
2
|
-
import modelPrices from 'llm-cost/model_prices_and_context_window.json';
|
|
3
2
|
|
|
4
3
|
type ChatRole = "system" | "user" | "assistant" | "function" | "tool" | "unknown";
|
|
5
4
|
interface FunctionCall {
|
|
@@ -17,6 +16,7 @@ interface ChatMessage$1 {
|
|
|
17
16
|
function_call?: FunctionCall | null;
|
|
18
17
|
tool_calls?: ToolCall[] | null;
|
|
19
18
|
tool_call_id?: string | null;
|
|
19
|
+
name?: string | null;
|
|
20
20
|
}
|
|
21
21
|
type ChatRichContent$1 = {
|
|
22
22
|
type: "text";
|
|
@@ -49,18 +49,23 @@ type Money = {
|
|
|
49
49
|
currency: string;
|
|
50
50
|
amount: number;
|
|
51
51
|
};
|
|
52
|
-
interface
|
|
52
|
+
interface EvaluationResult {
|
|
53
53
|
status: "processed" | "skipped" | "error";
|
|
54
|
-
passed
|
|
54
|
+
passed?: boolean | null;
|
|
55
55
|
score?: number | null;
|
|
56
|
+
label?: string | null;
|
|
56
57
|
details?: string | null;
|
|
57
58
|
cost?: Money | null;
|
|
58
59
|
}
|
|
59
60
|
interface TypedValueGuardrailResult {
|
|
60
61
|
type: "guardrail_result";
|
|
61
|
-
value:
|
|
62
|
+
value: EvaluationResult;
|
|
63
|
+
}
|
|
64
|
+
interface TypedValueEvaluationResult {
|
|
65
|
+
type: "evaluation_result";
|
|
66
|
+
value: EvaluationResult;
|
|
62
67
|
}
|
|
63
|
-
type SpanInputOutput$1 = TypedValueText | TypedValueChatMessages | TypedValueGuardrailResult | TypedValueJson | TypedValueRaw | {
|
|
68
|
+
type SpanInputOutput$1 = TypedValueText | TypedValueChatMessages | TypedValueGuardrailResult | TypedValueEvaluationResult | TypedValueJson | TypedValueRaw | {
|
|
64
69
|
type: "list";
|
|
65
70
|
value: SpanInputOutput$1[];
|
|
66
71
|
};
|
|
@@ -75,19 +80,32 @@ interface SpanMetrics {
|
|
|
75
80
|
tokens_estimated?: boolean | null;
|
|
76
81
|
cost?: number | null;
|
|
77
82
|
}
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
type ReservedSpanParams = {
|
|
84
|
+
frequency_penalty?: number | null;
|
|
85
|
+
logit_bias?: Record<string, number> | null;
|
|
86
|
+
logprobs?: boolean | null;
|
|
87
|
+
top_logprobs?: number | null;
|
|
88
|
+
max_tokens?: number | null;
|
|
89
|
+
n?: number | null;
|
|
90
|
+
presence_penalty?: number | null;
|
|
91
|
+
seed?: number | null;
|
|
92
|
+
stop?: string | string[] | null;
|
|
93
|
+
stream?: boolean | null;
|
|
94
|
+
temperature?: number | null;
|
|
95
|
+
top_p?: number | null;
|
|
96
|
+
tools?: Record<string, any>[] | null;
|
|
97
|
+
tool_choice?: Record<string, any> | string | null;
|
|
98
|
+
parallel_tool_calls?: boolean | null;
|
|
99
|
+
functions?: Record<string, any>[] | null;
|
|
100
|
+
user?: string | null;
|
|
101
|
+
};
|
|
102
|
+
type SpanParams = ReservedSpanParams & Record<string, any>;
|
|
85
103
|
interface SpanTimestamps {
|
|
86
104
|
started_at: number;
|
|
87
105
|
first_token_at?: number | null;
|
|
88
106
|
finished_at: number;
|
|
89
107
|
}
|
|
90
|
-
type SpanTypes = "span" | "llm" | "chain" | "tool" | "agent" | "rag" | "guardrail" | "unknown";
|
|
108
|
+
type SpanTypes = "span" | "llm" | "chain" | "tool" | "agent" | "rag" | "guardrail" | "evaluation" | "workflow" | "component" | "server" | "client" | "producer" | "consumer" | "task" | "unknown";
|
|
91
109
|
interface BaseSpan$1 {
|
|
92
110
|
span_id: string;
|
|
93
111
|
parent_id?: string | null;
|
|
@@ -99,12 +117,12 @@ interface BaseSpan$1 {
|
|
|
99
117
|
error?: ErrorCapture | null;
|
|
100
118
|
timestamps: SpanTimestamps;
|
|
101
119
|
metrics?: SpanMetrics | null;
|
|
120
|
+
params?: SpanParams | null;
|
|
102
121
|
}
|
|
103
122
|
interface LLMSpan$1 extends BaseSpan$1 {
|
|
104
123
|
type: "llm";
|
|
105
124
|
vendor?: string | null;
|
|
106
|
-
model
|
|
107
|
-
params: SpanParams;
|
|
125
|
+
model?: string | null;
|
|
108
126
|
}
|
|
109
127
|
interface RAGChunk {
|
|
110
128
|
document_id?: string | null;
|
|
@@ -131,25 +149,35 @@ type TraceOutput = {
|
|
|
131
149
|
embeddings: number[];
|
|
132
150
|
};
|
|
133
151
|
};
|
|
152
|
+
type PrimitiveType = string | number | boolean | null | undefined;
|
|
153
|
+
type ReservedTraceMetadata = {
|
|
154
|
+
thread_id?: string | null;
|
|
155
|
+
user_id?: string | null;
|
|
156
|
+
customer_id?: string | null;
|
|
157
|
+
labels?: string[] | null;
|
|
158
|
+
topic_id?: string | null;
|
|
159
|
+
subtopic_id?: string | null;
|
|
160
|
+
sdk_version?: string | null;
|
|
161
|
+
sdk_language?: string | null;
|
|
162
|
+
};
|
|
163
|
+
type CustomMetadata = Record<string, PrimitiveType | PrimitiveType[] | Record<string, PrimitiveType> | Record<string, Record<string, PrimitiveType>>>;
|
|
164
|
+
type TraceMetadata = ReservedTraceMetadata & CustomMetadata;
|
|
134
165
|
type Trace = {
|
|
135
166
|
trace_id: string;
|
|
136
167
|
project_id: string;
|
|
137
|
-
metadata:
|
|
138
|
-
thread_id?: string;
|
|
139
|
-
user_id?: string;
|
|
140
|
-
customer_id?: string;
|
|
141
|
-
labels?: string[];
|
|
142
|
-
topic_id?: string;
|
|
143
|
-
subtopic_id?: string;
|
|
144
|
-
};
|
|
168
|
+
metadata: TraceMetadata;
|
|
145
169
|
timestamps: {
|
|
146
170
|
started_at: number;
|
|
147
171
|
inserted_at: number;
|
|
148
172
|
updated_at: number;
|
|
149
173
|
};
|
|
150
|
-
input
|
|
174
|
+
input?: TraceInput;
|
|
151
175
|
output?: TraceOutput;
|
|
152
|
-
|
|
176
|
+
contexts?: RAGChunk[];
|
|
177
|
+
expected_output?: {
|
|
178
|
+
value: string;
|
|
179
|
+
};
|
|
180
|
+
metrics?: {
|
|
153
181
|
first_token_ms?: number | null;
|
|
154
182
|
total_time_ms?: number | null;
|
|
155
183
|
prompt_tokens?: number | null;
|
|
@@ -159,10 +187,39 @@ type Trace = {
|
|
|
159
187
|
};
|
|
160
188
|
error?: ErrorCapture | null;
|
|
161
189
|
indexing_md5s?: string[];
|
|
190
|
+
events?: Event[];
|
|
191
|
+
evaluations?: Evaluation[];
|
|
162
192
|
};
|
|
163
|
-
type
|
|
164
|
-
|
|
165
|
-
|
|
193
|
+
type EvaluationStatus = "scheduled" | "in_progress" | "error" | "skipped" | "processed";
|
|
194
|
+
type Evaluation = {
|
|
195
|
+
evaluation_id: string;
|
|
196
|
+
evaluator_id: string;
|
|
197
|
+
span_id?: string | null;
|
|
198
|
+
name: string;
|
|
199
|
+
type?: string | null;
|
|
200
|
+
is_guardrail?: boolean | null;
|
|
201
|
+
status: EvaluationStatus;
|
|
202
|
+
passed?: boolean | null;
|
|
203
|
+
score?: number | null;
|
|
204
|
+
label?: string | null;
|
|
205
|
+
details?: string | null;
|
|
206
|
+
error?: ErrorCapture | null;
|
|
207
|
+
retries?: number | null;
|
|
208
|
+
timestamps: {
|
|
209
|
+
inserted_at?: number | null;
|
|
210
|
+
started_at?: number | null;
|
|
211
|
+
finished_at?: number | null;
|
|
212
|
+
updated_at?: number | null;
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
type RESTEvaluation$1 = Omit<Evaluation, "evaluation_id" | "evaluator_id" | "status" | "timestamps" | "retries"> & {
|
|
216
|
+
evaluation_id?: string | null;
|
|
217
|
+
evaluator_id?: string | null;
|
|
218
|
+
status?: "processed" | "skipped" | "error" | null;
|
|
219
|
+
timestamps?: {
|
|
220
|
+
started_at?: number | null;
|
|
221
|
+
finished_at?: number | null;
|
|
222
|
+
} | null;
|
|
166
223
|
};
|
|
167
224
|
type CollectorRESTParams = {
|
|
168
225
|
trace_id?: string | null | undefined;
|
|
@@ -172,7 +229,23 @@ type CollectorRESTParams = {
|
|
|
172
229
|
thread_id?: string | null | undefined;
|
|
173
230
|
customer_id?: string | null | undefined;
|
|
174
231
|
labels?: string[] | null | undefined;
|
|
175
|
-
|
|
232
|
+
sdk_version?: string | null | undefined;
|
|
233
|
+
sdk_language?: string | null | undefined;
|
|
234
|
+
} & CustomMetadata;
|
|
235
|
+
expected_output?: string | null;
|
|
236
|
+
evaluations?: RESTEvaluation$1[];
|
|
237
|
+
};
|
|
238
|
+
type Event = {
|
|
239
|
+
event_id: string;
|
|
240
|
+
event_type: string;
|
|
241
|
+
project_id: string;
|
|
242
|
+
metrics: Record<string, number>;
|
|
243
|
+
event_details: Record<string, string>;
|
|
244
|
+
trace_id: string;
|
|
245
|
+
timestamps: {
|
|
246
|
+
started_at: number;
|
|
247
|
+
inserted_at: number;
|
|
248
|
+
updated_at: number;
|
|
176
249
|
};
|
|
177
250
|
};
|
|
178
251
|
|
|
@@ -202,13 +275,17 @@ type PendingSpan<T extends BaseSpan> = Omit<T, "traceId" | "timestamps"> & {
|
|
|
202
275
|
type BaseSpan = ConvertServerSpan<BaseSpan$1>;
|
|
203
276
|
type PendingBaseSpan = PendingSpan<BaseSpan>;
|
|
204
277
|
type LLMSpan = ConvertServerSpan<Omit<LLMSpan$1, "vendor" | "model">> & {
|
|
205
|
-
model:
|
|
278
|
+
model: string;
|
|
206
279
|
};
|
|
207
280
|
type PendingLLMSpan = PendingSpan<LLMSpan>;
|
|
208
281
|
type RAGSpan = ConvertServerSpan<RAGSpan$1>;
|
|
209
282
|
type PendingRAGSpan = PendingSpan<RAGSpan>;
|
|
283
|
+
type RESTEvaluation = SnakeToCamelCaseNested<Omit<RESTEvaluation$1, "error">> & {
|
|
284
|
+
error?: RESTEvaluation$1["error"];
|
|
285
|
+
};
|
|
210
286
|
|
|
211
287
|
declare function convertFromVercelAIMessages(messages: CoreMessage[]): ChatMessage[];
|
|
212
288
|
declare const captureError: (error: unknown) => ErrorCapture;
|
|
289
|
+
declare const autoconvertTypedValues: (value: unknown) => SpanInputOutput;
|
|
213
290
|
|
|
214
|
-
export { type BaseSpan as B, type CollectorRESTParams as C, type LLMSpan as L, type Metadata as M, type PendingBaseSpan as P, type
|
|
291
|
+
export { type BaseSpan as B, type CollectorRESTParams as C, type LLMSpan as L, type Metadata as M, type PendingBaseSpan as P, type RAGChunk as R, type Span as S, type RESTEvaluation as a, type PendingLLMSpan as b, type PendingRAGSpan as c, type SpanTypes as d, type ChatMessage as e, type ChatRichContent as f, type RAGSpan as g, type SpanInputOutput as h, autoconvertTypedValues as i, captureError as j, convertFromVercelAIMessages as k };
|
package/dist/utils.d.mts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import 'ai';
|
|
2
|
-
export {
|
|
3
|
-
import 'llm-cost/model_prices_and_context_window.json';
|
|
2
|
+
export { i as autoconvertTypedValues, j as captureError, k as convertFromVercelAIMessages } from './utils-CFtM8VVg.mjs';
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
1
|
import 'ai';
|
|
2
|
-
export {
|
|
3
|
-
import 'llm-cost/model_prices_and_context_window.json';
|
|
2
|
+
export { i as autoconvertTypedValues, j as captureError, k as convertFromVercelAIMessages } from './utils-CFtM8VVg.js';
|
package/dist/utils.js
CHANGED
|
@@ -137,6 +137,7 @@ var require_secure_json_parse = __commonJS({
|
|
|
137
137
|
// src/utils.ts
|
|
138
138
|
var utils_exports = {};
|
|
139
139
|
__export(utils_exports, {
|
|
140
|
+
autoconvertTypedValues: () => autoconvertTypedValues,
|
|
140
141
|
captureError: () => captureError,
|
|
141
142
|
convertFromVercelAIMessages: () => convertFromVercelAIMessages
|
|
142
143
|
});
|
|
@@ -157,6 +158,423 @@ function convertUint8ArrayToBase64(array) {
|
|
|
157
158
|
return globalThis.btoa(latin1string);
|
|
158
159
|
}
|
|
159
160
|
|
|
161
|
+
// src/utils.ts
|
|
162
|
+
var import_zod2 = require("zod");
|
|
163
|
+
|
|
164
|
+
// src/server/types/tracer.generated.ts
|
|
165
|
+
var import_zod = require("zod");
|
|
166
|
+
var chatRoleSchema = import_zod.z.union([
|
|
167
|
+
import_zod.z.literal("system"),
|
|
168
|
+
import_zod.z.literal("user"),
|
|
169
|
+
import_zod.z.literal("assistant"),
|
|
170
|
+
import_zod.z.literal("function"),
|
|
171
|
+
import_zod.z.literal("tool"),
|
|
172
|
+
import_zod.z.literal("unknown")
|
|
173
|
+
]);
|
|
174
|
+
var functionCallSchema = import_zod.z.object({
|
|
175
|
+
name: import_zod.z.string().optional(),
|
|
176
|
+
arguments: import_zod.z.string().optional()
|
|
177
|
+
});
|
|
178
|
+
var toolCallSchema = import_zod.z.object({
|
|
179
|
+
id: import_zod.z.string(),
|
|
180
|
+
type: import_zod.z.string(),
|
|
181
|
+
function: functionCallSchema
|
|
182
|
+
});
|
|
183
|
+
var rAGChunkSchema = import_zod.z.object({
|
|
184
|
+
document_id: import_zod.z.string().optional().nullable(),
|
|
185
|
+
chunk_id: import_zod.z.string().optional().nullable(),
|
|
186
|
+
content: import_zod.z.union([import_zod.z.string(), import_zod.z.record(import_zod.z.any()), import_zod.z.array(import_zod.z.any())])
|
|
187
|
+
});
|
|
188
|
+
var chatRichContentSchema = import_zod.z.union([
|
|
189
|
+
import_zod.z.object({
|
|
190
|
+
type: import_zod.z.literal("text"),
|
|
191
|
+
text: import_zod.z.string().optional()
|
|
192
|
+
}),
|
|
193
|
+
import_zod.z.object({
|
|
194
|
+
type: import_zod.z.literal("image_url"),
|
|
195
|
+
image_url: import_zod.z.object({
|
|
196
|
+
url: import_zod.z.string(),
|
|
197
|
+
detail: import_zod.z.union([import_zod.z.literal("auto"), import_zod.z.literal("low"), import_zod.z.literal("high")]).optional()
|
|
198
|
+
}).optional()
|
|
199
|
+
})
|
|
200
|
+
]);
|
|
201
|
+
var typedValueTextSchema = import_zod.z.object({
|
|
202
|
+
type: import_zod.z.literal("text"),
|
|
203
|
+
value: import_zod.z.string()
|
|
204
|
+
});
|
|
205
|
+
var typedValueRawSchema = import_zod.z.object({
|
|
206
|
+
type: import_zod.z.literal("raw"),
|
|
207
|
+
value: import_zod.z.string()
|
|
208
|
+
});
|
|
209
|
+
var jSONSerializableSchema = import_zod.z.union([
|
|
210
|
+
import_zod.z.string(),
|
|
211
|
+
import_zod.z.number(),
|
|
212
|
+
import_zod.z.boolean(),
|
|
213
|
+
import_zod.z.record(import_zod.z.any()),
|
|
214
|
+
import_zod.z.array(import_zod.z.any())
|
|
215
|
+
]).nullable();
|
|
216
|
+
var typedValueJsonSchema = import_zod.z.object({
|
|
217
|
+
type: import_zod.z.literal("json"),
|
|
218
|
+
value: jSONSerializableSchema
|
|
219
|
+
});
|
|
220
|
+
var moneySchema = import_zod.z.object({
|
|
221
|
+
currency: import_zod.z.string(),
|
|
222
|
+
amount: import_zod.z.number()
|
|
223
|
+
});
|
|
224
|
+
var evaluationResultSchema = import_zod.z.object({
|
|
225
|
+
status: import_zod.z.union([
|
|
226
|
+
import_zod.z.literal("processed"),
|
|
227
|
+
import_zod.z.literal("skipped"),
|
|
228
|
+
import_zod.z.literal("error")
|
|
229
|
+
]),
|
|
230
|
+
passed: import_zod.z.boolean().optional().nullable(),
|
|
231
|
+
score: import_zod.z.number().optional().nullable(),
|
|
232
|
+
label: import_zod.z.string().optional().nullable(),
|
|
233
|
+
details: import_zod.z.string().optional().nullable(),
|
|
234
|
+
cost: moneySchema.optional().nullable()
|
|
235
|
+
});
|
|
236
|
+
var typedValueGuardrailResultSchema = import_zod.z.object({
|
|
237
|
+
type: import_zod.z.literal("guardrail_result"),
|
|
238
|
+
value: evaluationResultSchema
|
|
239
|
+
});
|
|
240
|
+
var typedValueEvaluationResultSchema = import_zod.z.object({
|
|
241
|
+
type: import_zod.z.literal("evaluation_result"),
|
|
242
|
+
value: evaluationResultSchema
|
|
243
|
+
});
|
|
244
|
+
var errorCaptureSchema = import_zod.z.object({
|
|
245
|
+
has_error: import_zod.z.literal(true),
|
|
246
|
+
message: import_zod.z.string(),
|
|
247
|
+
stacktrace: import_zod.z.array(import_zod.z.string())
|
|
248
|
+
});
|
|
249
|
+
var spanMetricsSchema = import_zod.z.object({
|
|
250
|
+
prompt_tokens: import_zod.z.number().optional().nullable(),
|
|
251
|
+
completion_tokens: import_zod.z.number().optional().nullable(),
|
|
252
|
+
tokens_estimated: import_zod.z.boolean().optional().nullable(),
|
|
253
|
+
cost: import_zod.z.number().optional().nullable()
|
|
254
|
+
});
|
|
255
|
+
var reservedSpanParamsSchema = import_zod.z.object({
|
|
256
|
+
frequency_penalty: import_zod.z.number().optional().nullable(),
|
|
257
|
+
logit_bias: import_zod.z.record(import_zod.z.number()).optional().nullable(),
|
|
258
|
+
logprobs: import_zod.z.boolean().optional().nullable(),
|
|
259
|
+
top_logprobs: import_zod.z.number().optional().nullable(),
|
|
260
|
+
max_tokens: import_zod.z.number().optional().nullable(),
|
|
261
|
+
n: import_zod.z.number().optional().nullable(),
|
|
262
|
+
presence_penalty: import_zod.z.number().optional().nullable(),
|
|
263
|
+
seed: import_zod.z.number().optional().nullable(),
|
|
264
|
+
stop: import_zod.z.union([import_zod.z.string(), import_zod.z.array(import_zod.z.string())]).optional().nullable(),
|
|
265
|
+
stream: import_zod.z.boolean().optional().nullable(),
|
|
266
|
+
temperature: import_zod.z.number().optional().nullable(),
|
|
267
|
+
top_p: import_zod.z.number().optional().nullable(),
|
|
268
|
+
tools: import_zod.z.array(import_zod.z.record(import_zod.z.any())).optional().nullable(),
|
|
269
|
+
tool_choice: import_zod.z.union([import_zod.z.record(import_zod.z.any()), import_zod.z.string()]).optional().nullable(),
|
|
270
|
+
parallel_tool_calls: import_zod.z.boolean().optional().nullable(),
|
|
271
|
+
functions: import_zod.z.array(import_zod.z.record(import_zod.z.any())).optional().nullable(),
|
|
272
|
+
user: import_zod.z.string().optional().nullable()
|
|
273
|
+
});
|
|
274
|
+
var spanParamsSchema = reservedSpanParamsSchema.and(import_zod.z.record(import_zod.z.any()));
|
|
275
|
+
var spanTimestampsSchema = import_zod.z.object({
|
|
276
|
+
started_at: import_zod.z.number(),
|
|
277
|
+
first_token_at: import_zod.z.number().optional().nullable(),
|
|
278
|
+
finished_at: import_zod.z.number()
|
|
279
|
+
});
|
|
280
|
+
var spanTypesSchema = import_zod.z.union([
|
|
281
|
+
import_zod.z.literal("span"),
|
|
282
|
+
import_zod.z.literal("llm"),
|
|
283
|
+
import_zod.z.literal("chain"),
|
|
284
|
+
import_zod.z.literal("tool"),
|
|
285
|
+
import_zod.z.literal("agent"),
|
|
286
|
+
import_zod.z.literal("rag"),
|
|
287
|
+
import_zod.z.literal("guardrail"),
|
|
288
|
+
import_zod.z.literal("evaluation"),
|
|
289
|
+
import_zod.z.literal("workflow"),
|
|
290
|
+
import_zod.z.literal("component"),
|
|
291
|
+
import_zod.z.literal("server"),
|
|
292
|
+
import_zod.z.literal("client"),
|
|
293
|
+
import_zod.z.literal("producer"),
|
|
294
|
+
import_zod.z.literal("consumer"),
|
|
295
|
+
import_zod.z.literal("task"),
|
|
296
|
+
import_zod.z.literal("unknown")
|
|
297
|
+
]);
|
|
298
|
+
var traceInputSchema = import_zod.z.object({
|
|
299
|
+
value: import_zod.z.string(),
|
|
300
|
+
embeddings: import_zod.z.object({
|
|
301
|
+
model: import_zod.z.string(),
|
|
302
|
+
embeddings: import_zod.z.array(import_zod.z.number())
|
|
303
|
+
}).optional(),
|
|
304
|
+
satisfaction_score: import_zod.z.number().optional()
|
|
305
|
+
});
|
|
306
|
+
var traceOutputSchema = import_zod.z.object({
|
|
307
|
+
value: import_zod.z.string(),
|
|
308
|
+
embeddings: import_zod.z.object({
|
|
309
|
+
model: import_zod.z.string(),
|
|
310
|
+
embeddings: import_zod.z.array(import_zod.z.number())
|
|
311
|
+
}).optional()
|
|
312
|
+
});
|
|
313
|
+
var primitiveTypeSchema = import_zod.z.union([import_zod.z.string(), import_zod.z.number(), import_zod.z.boolean(), import_zod.z.undefined()]).nullable();
|
|
314
|
+
var reservedTraceMetadataSchema = import_zod.z.object({
|
|
315
|
+
thread_id: import_zod.z.string().optional().nullable(),
|
|
316
|
+
user_id: import_zod.z.string().optional().nullable(),
|
|
317
|
+
customer_id: import_zod.z.string().optional().nullable(),
|
|
318
|
+
labels: import_zod.z.array(import_zod.z.string()).optional().nullable(),
|
|
319
|
+
topic_id: import_zod.z.string().optional().nullable(),
|
|
320
|
+
subtopic_id: import_zod.z.string().optional().nullable(),
|
|
321
|
+
sdk_version: import_zod.z.string().optional().nullable(),
|
|
322
|
+
sdk_language: import_zod.z.string().optional().nullable()
|
|
323
|
+
});
|
|
324
|
+
var customMetadataSchema = import_zod.z.record(
|
|
325
|
+
import_zod.z.union([
|
|
326
|
+
primitiveTypeSchema,
|
|
327
|
+
import_zod.z.array(primitiveTypeSchema),
|
|
328
|
+
import_zod.z.record(primitiveTypeSchema),
|
|
329
|
+
import_zod.z.record(import_zod.z.record(primitiveTypeSchema))
|
|
330
|
+
])
|
|
331
|
+
);
|
|
332
|
+
var traceMetadataSchema = reservedTraceMetadataSchema.and(customMetadataSchema);
|
|
333
|
+
var eventSchema = import_zod.z.object({
|
|
334
|
+
event_id: import_zod.z.string(),
|
|
335
|
+
event_type: import_zod.z.string(),
|
|
336
|
+
project_id: import_zod.z.string(),
|
|
337
|
+
metrics: import_zod.z.record(import_zod.z.number()),
|
|
338
|
+
event_details: import_zod.z.record(import_zod.z.string()),
|
|
339
|
+
trace_id: import_zod.z.string(),
|
|
340
|
+
timestamps: import_zod.z.object({
|
|
341
|
+
started_at: import_zod.z.number(),
|
|
342
|
+
inserted_at: import_zod.z.number(),
|
|
343
|
+
updated_at: import_zod.z.number()
|
|
344
|
+
})
|
|
345
|
+
});
|
|
346
|
+
var elasticSearchEventSchema = eventSchema.omit({ metrics: true, event_details: true }).and(
|
|
347
|
+
import_zod.z.object({
|
|
348
|
+
metrics: import_zod.z.array(
|
|
349
|
+
import_zod.z.object({
|
|
350
|
+
key: import_zod.z.string(),
|
|
351
|
+
value: import_zod.z.number()
|
|
352
|
+
})
|
|
353
|
+
),
|
|
354
|
+
event_details: import_zod.z.array(
|
|
355
|
+
import_zod.z.object({
|
|
356
|
+
key: import_zod.z.string(),
|
|
357
|
+
value: import_zod.z.string()
|
|
358
|
+
})
|
|
359
|
+
)
|
|
360
|
+
})
|
|
361
|
+
);
|
|
362
|
+
var evaluationStatusSchema = import_zod.z.union([
|
|
363
|
+
import_zod.z.literal("scheduled"),
|
|
364
|
+
import_zod.z.literal("in_progress"),
|
|
365
|
+
import_zod.z.literal("error"),
|
|
366
|
+
import_zod.z.literal("skipped"),
|
|
367
|
+
import_zod.z.literal("processed")
|
|
368
|
+
]);
|
|
369
|
+
var trackEventRESTParamsValidatorSchema = eventSchema.omit({
|
|
370
|
+
event_id: true,
|
|
371
|
+
project_id: true,
|
|
372
|
+
timestamps: true,
|
|
373
|
+
event_details: true
|
|
374
|
+
}).and(
|
|
375
|
+
import_zod.z.object({
|
|
376
|
+
event_id: import_zod.z.string().optional(),
|
|
377
|
+
event_details: import_zod.z.record(import_zod.z.string()).optional(),
|
|
378
|
+
timestamp: import_zod.z.number().optional()
|
|
379
|
+
})
|
|
380
|
+
);
|
|
381
|
+
var contextsSchema = import_zod.z.object({
|
|
382
|
+
traceId: import_zod.z.string(),
|
|
383
|
+
contexts: import_zod.z.array(rAGChunkSchema)
|
|
384
|
+
});
|
|
385
|
+
var chatMessageSchema = import_zod.z.object({
|
|
386
|
+
role: chatRoleSchema.optional(),
|
|
387
|
+
content: import_zod.z.union([import_zod.z.string(), import_zod.z.array(chatRichContentSchema)]).optional().nullable(),
|
|
388
|
+
function_call: functionCallSchema.optional().nullable(),
|
|
389
|
+
tool_calls: import_zod.z.array(toolCallSchema).optional().nullable(),
|
|
390
|
+
tool_call_id: import_zod.z.string().optional().nullable(),
|
|
391
|
+
name: import_zod.z.string().optional().nullable()
|
|
392
|
+
});
|
|
393
|
+
var typedValueChatMessagesSchema = import_zod.z.object({
|
|
394
|
+
type: import_zod.z.literal("chat_messages"),
|
|
395
|
+
value: import_zod.z.array(chatMessageSchema)
|
|
396
|
+
});
|
|
397
|
+
var spanInputOutputSchema = import_zod.z.lazy(
|
|
398
|
+
() => import_zod.z.union([
|
|
399
|
+
typedValueTextSchema,
|
|
400
|
+
typedValueChatMessagesSchema,
|
|
401
|
+
typedValueGuardrailResultSchema,
|
|
402
|
+
typedValueEvaluationResultSchema,
|
|
403
|
+
typedValueJsonSchema,
|
|
404
|
+
typedValueRawSchema,
|
|
405
|
+
import_zod.z.object({
|
|
406
|
+
type: import_zod.z.literal("list"),
|
|
407
|
+
value: import_zod.z.array(spanInputOutputSchema)
|
|
408
|
+
})
|
|
409
|
+
])
|
|
410
|
+
);
|
|
411
|
+
var baseSpanSchema = import_zod.z.object({
|
|
412
|
+
span_id: import_zod.z.string(),
|
|
413
|
+
parent_id: import_zod.z.string().optional().nullable(),
|
|
414
|
+
trace_id: import_zod.z.string(),
|
|
415
|
+
type: spanTypesSchema,
|
|
416
|
+
name: import_zod.z.string().optional().nullable(),
|
|
417
|
+
input: spanInputOutputSchema.optional().nullable(),
|
|
418
|
+
output: spanInputOutputSchema.optional().nullable(),
|
|
419
|
+
error: errorCaptureSchema.optional().nullable(),
|
|
420
|
+
timestamps: spanTimestampsSchema,
|
|
421
|
+
metrics: spanMetricsSchema.optional().nullable(),
|
|
422
|
+
params: spanParamsSchema.optional().nullable()
|
|
423
|
+
});
|
|
424
|
+
var lLMSpanSchema = baseSpanSchema.extend({
|
|
425
|
+
type: import_zod.z.literal("llm"),
|
|
426
|
+
vendor: import_zod.z.string().optional().nullable(),
|
|
427
|
+
model: import_zod.z.string().optional().nullable()
|
|
428
|
+
});
|
|
429
|
+
var rAGSpanSchema = baseSpanSchema.extend({
|
|
430
|
+
type: import_zod.z.literal("rag"),
|
|
431
|
+
contexts: import_zod.z.array(rAGChunkSchema)
|
|
432
|
+
});
|
|
433
|
+
var spanSchema = import_zod.z.union([
|
|
434
|
+
lLMSpanSchema,
|
|
435
|
+
rAGSpanSchema,
|
|
436
|
+
baseSpanSchema
|
|
437
|
+
]);
|
|
438
|
+
var spanInputOutputValidatorSchema = spanInputOutputSchema.and(
|
|
439
|
+
import_zod.z.object({
|
|
440
|
+
value: import_zod.z.any()
|
|
441
|
+
})
|
|
442
|
+
);
|
|
443
|
+
var spanValidatorSchema = import_zod.z.union([
|
|
444
|
+
lLMSpanSchema.omit({ input: true, output: true, params: true }),
|
|
445
|
+
rAGSpanSchema.omit({ input: true, output: true, params: true }),
|
|
446
|
+
baseSpanSchema.omit({ input: true, output: true, params: true })
|
|
447
|
+
]).and(
|
|
448
|
+
import_zod.z.object({
|
|
449
|
+
input: spanInputOutputValidatorSchema.optional().nullable(),
|
|
450
|
+
output: spanInputOutputValidatorSchema.optional().nullable(),
|
|
451
|
+
params: import_zod.z.record(import_zod.z.any()).optional().nullable()
|
|
452
|
+
})
|
|
453
|
+
);
|
|
454
|
+
var evaluationSchema = import_zod.z.object({
|
|
455
|
+
evaluation_id: import_zod.z.string(),
|
|
456
|
+
evaluator_id: import_zod.z.string(),
|
|
457
|
+
span_id: import_zod.z.string().optional().nullable(),
|
|
458
|
+
name: import_zod.z.string(),
|
|
459
|
+
type: import_zod.z.string().optional().nullable(),
|
|
460
|
+
is_guardrail: import_zod.z.boolean().optional().nullable(),
|
|
461
|
+
status: evaluationStatusSchema,
|
|
462
|
+
passed: import_zod.z.boolean().optional().nullable(),
|
|
463
|
+
score: import_zod.z.number().optional().nullable(),
|
|
464
|
+
label: import_zod.z.string().optional().nullable(),
|
|
465
|
+
details: import_zod.z.string().optional().nullable(),
|
|
466
|
+
error: errorCaptureSchema.optional().nullable(),
|
|
467
|
+
retries: import_zod.z.number().optional().nullable(),
|
|
468
|
+
timestamps: import_zod.z.object({
|
|
469
|
+
inserted_at: import_zod.z.number().optional().nullable(),
|
|
470
|
+
started_at: import_zod.z.number().optional().nullable(),
|
|
471
|
+
finished_at: import_zod.z.number().optional().nullable(),
|
|
472
|
+
updated_at: import_zod.z.number().optional().nullable()
|
|
473
|
+
})
|
|
474
|
+
});
|
|
475
|
+
var rESTEvaluationSchema = evaluationSchema.omit({
|
|
476
|
+
evaluation_id: true,
|
|
477
|
+
evaluator_id: true,
|
|
478
|
+
status: true,
|
|
479
|
+
timestamps: true,
|
|
480
|
+
retries: true
|
|
481
|
+
}).and(
|
|
482
|
+
import_zod.z.object({
|
|
483
|
+
evaluation_id: import_zod.z.string().optional().nullable(),
|
|
484
|
+
evaluator_id: import_zod.z.string().optional().nullable(),
|
|
485
|
+
status: import_zod.z.union([
|
|
486
|
+
import_zod.z.literal("processed"),
|
|
487
|
+
import_zod.z.literal("skipped"),
|
|
488
|
+
import_zod.z.literal("error")
|
|
489
|
+
]).optional().nullable(),
|
|
490
|
+
timestamps: import_zod.z.object({
|
|
491
|
+
started_at: import_zod.z.number().optional().nullable(),
|
|
492
|
+
finished_at: import_zod.z.number().optional().nullable()
|
|
493
|
+
}).optional().nullable()
|
|
494
|
+
})
|
|
495
|
+
);
|
|
496
|
+
var collectorRESTParamsSchema = import_zod.z.object({
|
|
497
|
+
trace_id: import_zod.z.union([import_zod.z.string(), import_zod.z.undefined()]).optional().nullable(),
|
|
498
|
+
spans: import_zod.z.array(spanSchema),
|
|
499
|
+
metadata: import_zod.z.object({
|
|
500
|
+
user_id: import_zod.z.union([import_zod.z.string(), import_zod.z.undefined()]).optional().nullable(),
|
|
501
|
+
thread_id: import_zod.z.union([import_zod.z.string(), import_zod.z.undefined()]).optional().nullable(),
|
|
502
|
+
customer_id: import_zod.z.union([import_zod.z.string(), import_zod.z.undefined()]).optional().nullable(),
|
|
503
|
+
labels: import_zod.z.union([import_zod.z.array(import_zod.z.string()), import_zod.z.undefined()]).optional().nullable(),
|
|
504
|
+
sdk_version: import_zod.z.union([import_zod.z.string(), import_zod.z.undefined()]).optional().nullable(),
|
|
505
|
+
sdk_language: import_zod.z.union([import_zod.z.string(), import_zod.z.undefined()]).optional().nullable()
|
|
506
|
+
}).and(customMetadataSchema).optional(),
|
|
507
|
+
expected_output: import_zod.z.string().optional().nullable(),
|
|
508
|
+
evaluations: import_zod.z.array(rESTEvaluationSchema).optional()
|
|
509
|
+
});
|
|
510
|
+
var collectorRESTParamsValidatorSchema = collectorRESTParamsSchema.omit({ spans: true });
|
|
511
|
+
var datasetSpanSchema = import_zod.z.union([
|
|
512
|
+
baseSpanSchema.omit({
|
|
513
|
+
project_id: true,
|
|
514
|
+
trace_id: true,
|
|
515
|
+
id: true,
|
|
516
|
+
timestamps: true,
|
|
517
|
+
metrics: true,
|
|
518
|
+
params: true
|
|
519
|
+
}).and(
|
|
520
|
+
import_zod.z.object({
|
|
521
|
+
params: import_zod.z.record(import_zod.z.any())
|
|
522
|
+
})
|
|
523
|
+
),
|
|
524
|
+
lLMSpanSchema.omit({
|
|
525
|
+
project_id: true,
|
|
526
|
+
trace_id: true,
|
|
527
|
+
id: true,
|
|
528
|
+
timestamps: true,
|
|
529
|
+
metrics: true,
|
|
530
|
+
params: true
|
|
531
|
+
}).and(
|
|
532
|
+
import_zod.z.object({
|
|
533
|
+
params: import_zod.z.record(import_zod.z.any())
|
|
534
|
+
})
|
|
535
|
+
),
|
|
536
|
+
rAGSpanSchema.omit({
|
|
537
|
+
project_id: true,
|
|
538
|
+
trace_id: true,
|
|
539
|
+
id: true,
|
|
540
|
+
timestamps: true,
|
|
541
|
+
metrics: true,
|
|
542
|
+
params: true
|
|
543
|
+
}).and(
|
|
544
|
+
import_zod.z.object({
|
|
545
|
+
params: import_zod.z.record(import_zod.z.any())
|
|
546
|
+
})
|
|
547
|
+
)
|
|
548
|
+
]);
|
|
549
|
+
var traceSchema = import_zod.z.object({
|
|
550
|
+
trace_id: import_zod.z.string(),
|
|
551
|
+
project_id: import_zod.z.string(),
|
|
552
|
+
metadata: traceMetadataSchema,
|
|
553
|
+
timestamps: import_zod.z.object({
|
|
554
|
+
started_at: import_zod.z.number(),
|
|
555
|
+
inserted_at: import_zod.z.number(),
|
|
556
|
+
updated_at: import_zod.z.number()
|
|
557
|
+
}),
|
|
558
|
+
input: traceInputSchema.optional(),
|
|
559
|
+
output: traceOutputSchema.optional(),
|
|
560
|
+
contexts: import_zod.z.array(rAGChunkSchema).optional(),
|
|
561
|
+
expected_output: import_zod.z.object({
|
|
562
|
+
value: import_zod.z.string()
|
|
563
|
+
}).optional(),
|
|
564
|
+
metrics: import_zod.z.object({
|
|
565
|
+
first_token_ms: import_zod.z.number().optional().nullable(),
|
|
566
|
+
total_time_ms: import_zod.z.number().optional().nullable(),
|
|
567
|
+
prompt_tokens: import_zod.z.number().optional().nullable(),
|
|
568
|
+
completion_tokens: import_zod.z.number().optional().nullable(),
|
|
569
|
+
total_cost: import_zod.z.number().optional().nullable(),
|
|
570
|
+
tokens_estimated: import_zod.z.boolean().optional().nullable()
|
|
571
|
+
}).optional(),
|
|
572
|
+
error: errorCaptureSchema.optional().nullable(),
|
|
573
|
+
indexing_md5s: import_zod.z.array(import_zod.z.string()).optional(),
|
|
574
|
+
events: import_zod.z.array(eventSchema).optional(),
|
|
575
|
+
evaluations: import_zod.z.array(evaluationSchema).optional()
|
|
576
|
+
});
|
|
577
|
+
|
|
160
578
|
// src/utils.ts
|
|
161
579
|
var convertImageToUrl = (image, mimeType) => {
|
|
162
580
|
try {
|
|
@@ -283,8 +701,27 @@ var captureError = (error) => {
|
|
|
283
701
|
};
|
|
284
702
|
}
|
|
285
703
|
};
|
|
704
|
+
var autoconvertTypedValues = (value) => {
|
|
705
|
+
if (typeof value === "string") {
|
|
706
|
+
return { type: "text", value };
|
|
707
|
+
}
|
|
708
|
+
const chatMessages = import_zod2.z.array(chatMessageSchema).safeParse(value);
|
|
709
|
+
if (Array.isArray(value) && chatMessages.success) {
|
|
710
|
+
return {
|
|
711
|
+
type: "chat_messages",
|
|
712
|
+
value: chatMessages.data
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
try {
|
|
716
|
+
JSON.stringify(value);
|
|
717
|
+
return { type: "json", value };
|
|
718
|
+
} catch (e) {
|
|
719
|
+
return { type: "raw", value };
|
|
720
|
+
}
|
|
721
|
+
};
|
|
286
722
|
// Annotate the CommonJS export names for ESM import in node:
|
|
287
723
|
0 && (module.exports = {
|
|
724
|
+
autoconvertTypedValues,
|
|
288
725
|
captureError,
|
|
289
726
|
convertFromVercelAIMessages
|
|
290
727
|
});
|