langwatch 1.0.0 → 1.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/README.md +33 -0
- package/dist/{chunk-TKSTXX3D.js → chunk-CLTKABMO.js} +52 -2
- package/dist/chunk-CLTKABMO.js.map +1 -0
- package/dist/{chunk-L5KBRKHS.mjs → chunk-CMZFFKLA.mjs} +51 -1
- package/dist/{chunk-L5KBRKHS.mjs.map → chunk-CMZFFKLA.mjs.map} +1 -1
- package/dist/{chunk-52VMSJ4O.js → chunk-DTSULVK5.js} +39 -19
- package/dist/chunk-DTSULVK5.js.map +1 -0
- package/dist/{chunk-5Q2DUSMQ.mjs → chunk-JYTJEAOU.mjs} +3 -3
- package/dist/chunk-JYTJEAOU.mjs.map +1 -0
- package/dist/chunk-K6KPNTQO.js +15624 -0
- package/dist/chunk-K6KPNTQO.js.map +1 -0
- package/dist/{chunk-2O4ILSP5.mjs → chunk-LTDUROCE.mjs} +2 -2
- package/dist/{chunk-ALPIFEXL.mjs → chunk-PDNXHBSL.mjs} +26 -6
- package/dist/chunk-PDNXHBSL.mjs.map +1 -0
- package/dist/chunk-SYJIEBJY.mjs +15624 -0
- package/dist/chunk-SYJIEBJY.mjs.map +1 -0
- package/dist/{chunk-WHBCX64R.js → chunk-UOFSG6R4.js} +19 -19
- package/dist/chunk-UOFSG6R4.js.map +1 -0
- package/dist/{chunk-IUSLT65Z.js → chunk-ZTOXEWNX.js} +2 -2
- package/dist/chunk-ZTOXEWNX.js.map +1 -0
- package/dist/cli/bundle.js +265 -180
- package/dist/{implementation-CPfDot-W.d.mts → implementation-CHXrVq_q.d.mts} +1 -1
- package/dist/{implementation-aYHmyVZ_.d.ts → implementation-D_v0fUvU.d.ts} +1 -1
- package/dist/index.d.mts +1125 -5
- package/dist/index.d.ts +1125 -5
- package/dist/index.js +1272 -151
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1197 -76
- package/dist/index.mjs.map +1 -1
- package/dist/observability-sdk/index.d.mts +3 -3
- package/dist/observability-sdk/index.d.ts +3 -3
- package/dist/observability-sdk/index.js +5 -5
- package/dist/observability-sdk/index.js.map +1 -1
- package/dist/observability-sdk/index.mjs +4 -4
- package/dist/observability-sdk/instrumentation/langchain/index.d.mts +1 -1
- package/dist/observability-sdk/instrumentation/langchain/index.d.ts +1 -1
- package/dist/observability-sdk/instrumentation/langchain/index.js +18 -18
- package/dist/observability-sdk/instrumentation/langchain/index.js.map +1 -1
- package/dist/observability-sdk/instrumentation/langchain/index.mjs +2 -2
- package/dist/observability-sdk/setup/node/index.js +4 -4
- package/dist/observability-sdk/setup/node/index.js.map +1 -1
- package/dist/observability-sdk/setup/node/index.mjs +3 -3
- package/dist/{types-Cw-3VUv7.d.mts → types-DlP7QdqU.d.mts} +15065 -6184
- package/dist/{types-CeZ-M8JZ.d.ts → types-av2kmt_i.d.ts} +15065 -6184
- package/package.json +9 -10
- package/dist/chunk-52VMSJ4O.js.map +0 -1
- package/dist/chunk-5Q2DUSMQ.mjs.map +0 -1
- package/dist/chunk-ADJOFPAZ.js +0 -1005
- package/dist/chunk-ADJOFPAZ.js.map +0 -1
- package/dist/chunk-ALPIFEXL.mjs.map +0 -1
- package/dist/chunk-C323F5VC.mjs +0 -1005
- package/dist/chunk-C323F5VC.mjs.map +0 -1
- package/dist/chunk-IUSLT65Z.js.map +0 -1
- package/dist/chunk-TKSTXX3D.js.map +0 -1
- package/dist/chunk-WHBCX64R.js.map +0 -1
- /package/dist/{chunk-2O4ILSP5.mjs.map → chunk-LTDUROCE.mjs.map} +0 -0
package/dist/chunk-ADJOFPAZ.js
DELETED
|
@@ -1,1005 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
var _chunkTKSTXX3Djs = require('./chunk-TKSTXX3D.js');
|
|
15
|
-
|
|
16
|
-
// src/observability-sdk/span/types.ts
|
|
17
|
-
var INPUT_OUTPUT_TYPES = [
|
|
18
|
-
"text",
|
|
19
|
-
"raw",
|
|
20
|
-
"chat_messages",
|
|
21
|
-
"list",
|
|
22
|
-
"json",
|
|
23
|
-
"guardrail_result",
|
|
24
|
-
"evaluation_result"
|
|
25
|
-
];
|
|
26
|
-
var spanTypes = [
|
|
27
|
-
"span",
|
|
28
|
-
"llm",
|
|
29
|
-
"chain",
|
|
30
|
-
"tool",
|
|
31
|
-
"agent",
|
|
32
|
-
"guardrail",
|
|
33
|
-
"evaluation",
|
|
34
|
-
"rag",
|
|
35
|
-
"prompt",
|
|
36
|
-
"workflow",
|
|
37
|
-
"component",
|
|
38
|
-
"module",
|
|
39
|
-
"server",
|
|
40
|
-
"client",
|
|
41
|
-
"producer",
|
|
42
|
-
"consumer",
|
|
43
|
-
"task",
|
|
44
|
-
"unknown"
|
|
45
|
-
];
|
|
46
|
-
|
|
47
|
-
// src/internal/generated/types/tracer.ts
|
|
48
|
-
var _zod = require('zod');
|
|
49
|
-
var chatRoleSchema = _zod.z.union([
|
|
50
|
-
_zod.z.literal("system"),
|
|
51
|
-
/**
|
|
52
|
-
* OpenAI Responses-dialect spelling of the system role. Accepted wherever
|
|
53
|
-
* chat messages are parsed and treated as a system-role message everywhere
|
|
54
|
-
* it matters (system-instruction extraction, transcript rendering) — a
|
|
55
|
-
* developer message must never fail schema validation into a raw-JSON
|
|
56
|
-
* fallback, and never render as a user bubble.
|
|
57
|
-
*/
|
|
58
|
-
_zod.z.literal("developer"),
|
|
59
|
-
_zod.z.literal("user"),
|
|
60
|
-
_zod.z.literal("assistant"),
|
|
61
|
-
_zod.z.literal("function"),
|
|
62
|
-
_zod.z.literal("tool"),
|
|
63
|
-
_zod.z.literal("unknown")
|
|
64
|
-
]);
|
|
65
|
-
var functionCallSchema = _zod.z.object({
|
|
66
|
-
name: _zod.z.string().optional(),
|
|
67
|
-
arguments: _zod.z.string().optional()
|
|
68
|
-
});
|
|
69
|
-
var toolCallSchema = _zod.z.object({
|
|
70
|
-
id: _zod.z.string(),
|
|
71
|
-
type: _zod.z.string(),
|
|
72
|
-
function: functionCallSchema
|
|
73
|
-
});
|
|
74
|
-
var rAGChunkSchema = _zod.z.object({
|
|
75
|
-
document_id: _zod.z.string().optional().nullable(),
|
|
76
|
-
chunk_id: _zod.z.string().optional().nullable(),
|
|
77
|
-
content: _zod.z.union([
|
|
78
|
-
_zod.z.string(),
|
|
79
|
-
_zod.z.record(_zod.z.string(), _zod.z.any()),
|
|
80
|
-
_zod.z.array(_zod.z.any())
|
|
81
|
-
])
|
|
82
|
-
});
|
|
83
|
-
var contextsSchema = _zod.z.object({
|
|
84
|
-
traceId: _zod.z.string(),
|
|
85
|
-
contexts: _zod.z.array(rAGChunkSchema)
|
|
86
|
-
});
|
|
87
|
-
var chatRichContentSchema = _zod.z.union([
|
|
88
|
-
_zod.z.object({
|
|
89
|
-
type: _zod.z.literal("text"),
|
|
90
|
-
text: _zod.z.string().optional(),
|
|
91
|
-
/** pi-ai uses `content` instead of `text` inside text blocks */
|
|
92
|
-
content: _zod.z.string().optional()
|
|
93
|
-
}),
|
|
94
|
-
_zod.z.object({
|
|
95
|
-
text: _zod.z.string()
|
|
96
|
-
}),
|
|
97
|
-
_zod.z.object({
|
|
98
|
-
type: _zod.z.literal("image_url"),
|
|
99
|
-
image_url: _zod.z.object({
|
|
100
|
-
url: _zod.z.string(),
|
|
101
|
-
detail: _zod.z.union([_zod.z.literal("auto"), _zod.z.literal("low"), _zod.z.literal("high")]).optional()
|
|
102
|
-
}).optional()
|
|
103
|
-
}),
|
|
104
|
-
_zod.z.object({
|
|
105
|
-
type: _zod.z.literal("tool_call"),
|
|
106
|
-
toolName: _zod.z.string().optional(),
|
|
107
|
-
toolCallId: _zod.z.string().optional(),
|
|
108
|
-
args: _zod.z.string().optional()
|
|
109
|
-
}),
|
|
110
|
-
_zod.z.object({
|
|
111
|
-
type: _zod.z.literal("tool_result"),
|
|
112
|
-
toolName: _zod.z.string().optional(),
|
|
113
|
-
toolCallId: _zod.z.string().optional(),
|
|
114
|
-
result: _zod.z.any().optional()
|
|
115
|
-
}),
|
|
116
|
-
/**
|
|
117
|
-
* AG-UI binary content part. Used for audio/image/video/file attachments.
|
|
118
|
-
* Mutually-exclusive payload: exactly one of `data` (inline base64), `url`
|
|
119
|
-
* (already-externalized reference), or `id` (stored_objects id) is present.
|
|
120
|
-
* After ingest-side extraction (stored-objects pipeline), inline `data` is
|
|
121
|
-
* rewritten to `id` + `url` pointing at /api/files/{id}.
|
|
122
|
-
*/
|
|
123
|
-
_zod.z.object({
|
|
124
|
-
type: _zod.z.literal("binary"),
|
|
125
|
-
mimeType: _zod.z.string(),
|
|
126
|
-
data: _zod.z.string().optional(),
|
|
127
|
-
url: _zod.z.string().optional(),
|
|
128
|
-
id: _zod.z.string().optional(),
|
|
129
|
-
filename: _zod.z.string().optional()
|
|
130
|
-
}),
|
|
131
|
-
/**
|
|
132
|
-
* OpenAI Realtime `input_audio` content part. Pre-extraction the payload is
|
|
133
|
-
* inline base64 (`{ data, format }`); after ingest-side stored-objects
|
|
134
|
-
* extraction it is rewritten to a reference (`{ url, mimeType }`) pointing at
|
|
135
|
-
* /api/files/{projectId}/{id}. Every field is optional so this validates both
|
|
136
|
-
* shapes. Mirrors `inputAudioContentPartSchema` in the scenario event schemas.
|
|
137
|
-
*/
|
|
138
|
-
_zod.z.object({
|
|
139
|
-
type: _zod.z.literal("input_audio"),
|
|
140
|
-
input_audio: _zod.z.object({
|
|
141
|
-
data: _zod.z.string().optional(),
|
|
142
|
-
format: _zod.z.string().optional(),
|
|
143
|
-
url: _zod.z.string().optional(),
|
|
144
|
-
mimeType: _zod.z.string().optional(),
|
|
145
|
-
id: _zod.z.string().optional()
|
|
146
|
-
})
|
|
147
|
-
}),
|
|
148
|
-
/**
|
|
149
|
-
* AG-UI media `audio` content part. A typed `source` carries either an
|
|
150
|
-
* externalized `url` or inline base64 `data`, with an optional `mimeType`.
|
|
151
|
-
* Shared shape with image/video/document media parts (see `visitContentPart`).
|
|
152
|
-
*/
|
|
153
|
-
_zod.z.object({
|
|
154
|
-
type: _zod.z.literal("audio"),
|
|
155
|
-
source: _zod.z.object({
|
|
156
|
-
type: _zod.z.union([_zod.z.literal("url"), _zod.z.literal("data")]),
|
|
157
|
-
value: _zod.z.string(),
|
|
158
|
-
mimeType: _zod.z.string().optional()
|
|
159
|
-
})
|
|
160
|
-
}),
|
|
161
|
-
/**
|
|
162
|
-
* AI-SDK image part. `image` is a data: URI pre-extraction, a
|
|
163
|
-
* /api/files/{projectId}/{id} reference after ingest-side extraction, or an
|
|
164
|
-
* external http(s) URL (passed through, never re-hosted). This is the shape
|
|
165
|
-
* the typescript scenario SDK ships for image attachments in simulated user
|
|
166
|
-
* messages (scenario docs: multimodal-images).
|
|
167
|
-
*/
|
|
168
|
-
_zod.z.object({
|
|
169
|
-
type: _zod.z.literal("image"),
|
|
170
|
-
image: _zod.z.string(),
|
|
171
|
-
mediaType: _zod.z.string().optional()
|
|
172
|
-
}),
|
|
173
|
-
/**
|
|
174
|
-
* AI-SDK file part. Non-audio mediaTypes are externalized to a `binary`
|
|
175
|
-
* reference at ingest; audio/* mediaTypes route through the `input_audio`
|
|
176
|
-
* externalization path (see `visitContentPart`).
|
|
177
|
-
*/
|
|
178
|
-
_zod.z.object({
|
|
179
|
-
type: _zod.z.literal("file"),
|
|
180
|
-
mediaType: _zod.z.string(),
|
|
181
|
-
data: _zod.z.string().optional(),
|
|
182
|
-
url: _zod.z.string().optional(),
|
|
183
|
-
filename: _zod.z.string().optional()
|
|
184
|
-
}),
|
|
185
|
-
/**
|
|
186
|
-
* OpenAI ChatCompletion file part (scenario docs: multimodal-files).
|
|
187
|
-
* `file_data` is a data: URI or raw base64; `file_id` references a file
|
|
188
|
-
* hosted on the provider side and carries no bytes, so it passes through
|
|
189
|
-
* extraction unchanged. Externalized at ingest to a `binary` reference
|
|
190
|
-
* preserving the filename.
|
|
191
|
-
*/
|
|
192
|
-
_zod.z.object({
|
|
193
|
-
type: _zod.z.literal("file"),
|
|
194
|
-
file: _zod.z.object({
|
|
195
|
-
file_data: _zod.z.string().optional(),
|
|
196
|
-
file_id: _zod.z.string().optional(),
|
|
197
|
-
filename: _zod.z.string().optional()
|
|
198
|
-
})
|
|
199
|
-
})
|
|
200
|
-
]);
|
|
201
|
-
var chatMessageSchema = _zod.z.object({
|
|
202
|
-
role: chatRoleSchema.optional(),
|
|
203
|
-
content: _zod.z.union([_zod.z.string(), _zod.z.array(chatRichContentSchema)]).optional().nullable(),
|
|
204
|
-
/** Vercel AI SDK / pi-ai use `parts` instead of `content` */
|
|
205
|
-
parts: _zod.z.array(chatRichContentSchema).optional(),
|
|
206
|
-
function_call: functionCallSchema.optional().nullable(),
|
|
207
|
-
tool_calls: _zod.z.array(toolCallSchema).optional().nullable(),
|
|
208
|
-
tool_call_id: _zod.z.string().optional().nullable(),
|
|
209
|
-
name: _zod.z.string().optional().nullable(),
|
|
210
|
-
reasoning_content: _zod.z.string().optional().nullable()
|
|
211
|
-
});
|
|
212
|
-
var typedValueTextSchema = _zod.z.object({
|
|
213
|
-
type: _zod.z.literal("text"),
|
|
214
|
-
value: _zod.z.string()
|
|
215
|
-
});
|
|
216
|
-
var typedValueRawSchema = _zod.z.object({
|
|
217
|
-
type: _zod.z.literal("raw"),
|
|
218
|
-
value: _zod.z.string()
|
|
219
|
-
});
|
|
220
|
-
var jSONSerializableSchema = _zod.z.union([
|
|
221
|
-
_zod.z.string(),
|
|
222
|
-
_zod.z.number(),
|
|
223
|
-
_zod.z.boolean(),
|
|
224
|
-
_zod.z.record(_zod.z.string(), _zod.z.any()),
|
|
225
|
-
_zod.z.array(_zod.z.any())
|
|
226
|
-
]).nullable();
|
|
227
|
-
var typedValueJsonSchema = _zod.z.object({
|
|
228
|
-
type: _zod.z.literal("json"),
|
|
229
|
-
value: jSONSerializableSchema
|
|
230
|
-
});
|
|
231
|
-
var moneySchema = _zod.z.object({
|
|
232
|
-
currency: _zod.z.string(),
|
|
233
|
-
amount: _zod.z.number()
|
|
234
|
-
});
|
|
235
|
-
var evaluationResultSchema = _zod.z.object({
|
|
236
|
-
status: _zod.z.union([
|
|
237
|
-
_zod.z.literal("processed"),
|
|
238
|
-
_zod.z.literal("skipped"),
|
|
239
|
-
_zod.z.literal("error")
|
|
240
|
-
]),
|
|
241
|
-
passed: _zod.z.boolean().optional().nullable(),
|
|
242
|
-
score: _zod.z.number().optional().nullable(),
|
|
243
|
-
label: _zod.z.string().optional().nullable(),
|
|
244
|
-
details: _zod.z.string().optional().nullable(),
|
|
245
|
-
cost: moneySchema.optional().nullable()
|
|
246
|
-
});
|
|
247
|
-
var typedValueGuardrailResultSchema = _zod.z.object({
|
|
248
|
-
type: _zod.z.literal("guardrail_result"),
|
|
249
|
-
value: evaluationResultSchema
|
|
250
|
-
});
|
|
251
|
-
var typedValueEvaluationResultSchema = _zod.z.object({
|
|
252
|
-
type: _zod.z.literal("evaluation_result"),
|
|
253
|
-
value: evaluationResultSchema
|
|
254
|
-
});
|
|
255
|
-
var typedValueChatMessagesSchema = _zod.z.object({
|
|
256
|
-
type: _zod.z.literal("chat_messages"),
|
|
257
|
-
value: _zod.z.array(chatMessageSchema)
|
|
258
|
-
});
|
|
259
|
-
var spanInputOutputSchema = _zod.z.lazy(
|
|
260
|
-
() => _zod.z.union([
|
|
261
|
-
typedValueTextSchema,
|
|
262
|
-
typedValueChatMessagesSchema,
|
|
263
|
-
typedValueGuardrailResultSchema,
|
|
264
|
-
typedValueEvaluationResultSchema,
|
|
265
|
-
typedValueJsonSchema,
|
|
266
|
-
typedValueRawSchema,
|
|
267
|
-
_zod.z.object({
|
|
268
|
-
type: _zod.z.literal("list"),
|
|
269
|
-
value: _zod.z.array(spanInputOutputSchema)
|
|
270
|
-
})
|
|
271
|
-
])
|
|
272
|
-
);
|
|
273
|
-
var errorCaptureSchema = _zod.z.object({
|
|
274
|
-
has_error: _zod.z.literal(true),
|
|
275
|
-
message: _zod.z.string(),
|
|
276
|
-
stacktrace: _zod.z.array(_zod.z.string())
|
|
277
|
-
});
|
|
278
|
-
var spanMetricsSchema = _zod.z.object({
|
|
279
|
-
prompt_tokens: _zod.z.number().optional().nullable(),
|
|
280
|
-
completion_tokens: _zod.z.number().optional().nullable(),
|
|
281
|
-
reasoning_tokens: _zod.z.number().optional().nullable(),
|
|
282
|
-
cache_read_input_tokens: _zod.z.number().optional().nullable(),
|
|
283
|
-
cache_creation_input_tokens: _zod.z.number().optional().nullable(),
|
|
284
|
-
tokens_estimated: _zod.z.boolean().optional().nullable(),
|
|
285
|
-
cost: _zod.z.number().optional().nullable()
|
|
286
|
-
});
|
|
287
|
-
var reservedSpanParamsSchema = _zod.z.object({
|
|
288
|
-
frequency_penalty: _zod.z.number().optional().nullable(),
|
|
289
|
-
logit_bias: _zod.z.record(_zod.z.string(), _zod.z.number()).optional().nullable(),
|
|
290
|
-
logprobs: _zod.z.boolean().optional().nullable(),
|
|
291
|
-
top_logprobs: _zod.z.number().optional().nullable(),
|
|
292
|
-
max_tokens: _zod.z.number().optional().nullable(),
|
|
293
|
-
n: _zod.z.number().optional().nullable(),
|
|
294
|
-
presence_penalty: _zod.z.number().optional().nullable(),
|
|
295
|
-
seed: _zod.z.number().optional().nullable(),
|
|
296
|
-
stop: _zod.z.union([_zod.z.string(), _zod.z.array(_zod.z.string())]).optional().nullable(),
|
|
297
|
-
stream: _zod.z.boolean().optional().nullable(),
|
|
298
|
-
temperature: _zod.z.number().optional().nullable(),
|
|
299
|
-
top_p: _zod.z.number().optional().nullable(),
|
|
300
|
-
tools: _zod.z.array(_zod.z.record(_zod.z.string(), _zod.z.any())).optional().nullable(),
|
|
301
|
-
tool_choice: _zod.z.union([_zod.z.record(_zod.z.string(), _zod.z.any()), _zod.z.string()]).optional().nullable(),
|
|
302
|
-
parallel_tool_calls: _zod.z.boolean().optional().nullable(),
|
|
303
|
-
functions: _zod.z.array(_zod.z.record(_zod.z.string(), _zod.z.any())).optional().nullable(),
|
|
304
|
-
user: _zod.z.string().optional().nullable(),
|
|
305
|
-
reasoning_effort: _zod.z.string().optional().nullable()
|
|
306
|
-
});
|
|
307
|
-
var spanParamsSchema = reservedSpanParamsSchema.and(
|
|
308
|
-
_zod.z.record(_zod.z.string(), _zod.z.any())
|
|
309
|
-
);
|
|
310
|
-
var spanTimestampsSchema = _zod.z.object({
|
|
311
|
-
ignore_timestamps_on_write: _zod.z.boolean().optional().nullable(),
|
|
312
|
-
started_at: _zod.z.number(),
|
|
313
|
-
first_token_at: _zod.z.number().optional().nullable(),
|
|
314
|
-
finished_at: _zod.z.number()
|
|
315
|
-
});
|
|
316
|
-
var spanTypesSchema = _zod.z.union([
|
|
317
|
-
_zod.z.literal("span"),
|
|
318
|
-
_zod.z.literal("llm"),
|
|
319
|
-
_zod.z.literal("chain"),
|
|
320
|
-
_zod.z.literal("tool"),
|
|
321
|
-
_zod.z.literal("agent"),
|
|
322
|
-
_zod.z.literal("rag"),
|
|
323
|
-
_zod.z.literal("guardrail"),
|
|
324
|
-
_zod.z.literal("evaluation"),
|
|
325
|
-
// Low-code
|
|
326
|
-
_zod.z.literal("workflow"),
|
|
327
|
-
_zod.z.literal("component"),
|
|
328
|
-
// DSPy
|
|
329
|
-
_zod.z.literal("module"),
|
|
330
|
-
// OpenTelemetry
|
|
331
|
-
_zod.z.literal("server"),
|
|
332
|
-
_zod.z.literal("client"),
|
|
333
|
-
_zod.z.literal("producer"),
|
|
334
|
-
_zod.z.literal("consumer"),
|
|
335
|
-
// Other
|
|
336
|
-
_zod.z.literal("task"),
|
|
337
|
-
// openllmetry
|
|
338
|
-
_zod.z.literal("unknown")
|
|
339
|
-
]);
|
|
340
|
-
var baseSpanSchema = _zod.z.object({
|
|
341
|
-
span_id: _zod.z.string(),
|
|
342
|
-
parent_id: _zod.z.string().optional().nullable(),
|
|
343
|
-
trace_id: _zod.z.string(),
|
|
344
|
-
type: spanTypesSchema,
|
|
345
|
-
name: _zod.z.string().optional().nullable(),
|
|
346
|
-
input: spanInputOutputSchema.optional().nullable(),
|
|
347
|
-
output: spanInputOutputSchema.optional().nullable(),
|
|
348
|
-
error: errorCaptureSchema.optional().nullable(),
|
|
349
|
-
timestamps: spanTimestampsSchema,
|
|
350
|
-
metrics: spanMetricsSchema.optional().nullable(),
|
|
351
|
-
params: spanParamsSchema.optional().nullable()
|
|
352
|
-
});
|
|
353
|
-
var lLMSpanSchema = baseSpanSchema.extend({
|
|
354
|
-
type: _zod.z.literal("llm"),
|
|
355
|
-
// TODO: deprecate field, standardize on litellm model names
|
|
356
|
-
vendor: _zod.z.string().optional().nullable(),
|
|
357
|
-
model: _zod.z.string().optional().nullable()
|
|
358
|
-
});
|
|
359
|
-
var rAGSpanSchema = baseSpanSchema.extend({
|
|
360
|
-
type: _zod.z.literal("rag"),
|
|
361
|
-
contexts: _zod.z.array(rAGChunkSchema)
|
|
362
|
-
});
|
|
363
|
-
var spanSchema = _zod.z.union([
|
|
364
|
-
lLMSpanSchema,
|
|
365
|
-
rAGSpanSchema,
|
|
366
|
-
baseSpanSchema
|
|
367
|
-
]);
|
|
368
|
-
var spanInputOutputValidatorSchema = spanInputOutputSchema.and(
|
|
369
|
-
_zod.z.object({
|
|
370
|
-
value: _zod.z.any()
|
|
371
|
-
})
|
|
372
|
-
);
|
|
373
|
-
var spanValidatorSchema = _zod.z.union([
|
|
374
|
-
lLMSpanSchema.omit({ input: true, output: true, params: true }),
|
|
375
|
-
rAGSpanSchema.omit({ input: true, output: true, params: true }),
|
|
376
|
-
baseSpanSchema.omit({ input: true, output: true, params: true })
|
|
377
|
-
]).and(
|
|
378
|
-
_zod.z.object({
|
|
379
|
-
input: spanInputOutputValidatorSchema.optional().nullable(),
|
|
380
|
-
output: spanInputOutputValidatorSchema.optional().nullable(),
|
|
381
|
-
params: _zod.z.record(_zod.z.string(), _zod.z.any()).optional().nullable()
|
|
382
|
-
})
|
|
383
|
-
);
|
|
384
|
-
var traceInputSchema = _zod.z.object({
|
|
385
|
-
value: _zod.z.string()
|
|
386
|
-
});
|
|
387
|
-
var traceOutputSchema = _zod.z.object({
|
|
388
|
-
value: _zod.z.string()
|
|
389
|
-
});
|
|
390
|
-
var primitiveTypeSchema = _zod.z.union([_zod.z.string(), _zod.z.number(), _zod.z.boolean(), _zod.z.undefined()]).nullable();
|
|
391
|
-
var reservedTraceMetadataSchema = _zod.z.object({
|
|
392
|
-
thread_id: _zod.z.string().optional().nullable(),
|
|
393
|
-
user_id: _zod.z.string().optional().nullable(),
|
|
394
|
-
customer_id: _zod.z.string().optional().nullable(),
|
|
395
|
-
labels: _zod.z.array(_zod.z.string()).optional().nullable(),
|
|
396
|
-
topic_id: _zod.z.string().optional().nullable(),
|
|
397
|
-
subtopic_id: _zod.z.string().optional().nullable(),
|
|
398
|
-
sdk_name: _zod.z.string().optional().nullable(),
|
|
399
|
-
sdk_version: _zod.z.string().optional().nullable(),
|
|
400
|
-
sdk_language: _zod.z.string().optional().nullable(),
|
|
401
|
-
telemetry_sdk_language: _zod.z.string().optional().nullable(),
|
|
402
|
-
telemetry_sdk_name: _zod.z.string().optional().nullable(),
|
|
403
|
-
telemetry_sdk_version: _zod.z.string().optional().nullable(),
|
|
404
|
-
prompt_ids: _zod.z.array(_zod.z.string()).optional().nullable(),
|
|
405
|
-
prompt_version_ids: _zod.z.array(_zod.z.string()).optional().nullable()
|
|
406
|
-
});
|
|
407
|
-
var reservedTraceMetadataMappingSchema = _zod.z.record(
|
|
408
|
-
_zod.z.string(),
|
|
409
|
-
reservedTraceMetadataSchema.keyof()
|
|
410
|
-
);
|
|
411
|
-
var customMetadataSchema = _zod.z.record(
|
|
412
|
-
_zod.z.string(),
|
|
413
|
-
_zod.z.union([
|
|
414
|
-
primitiveTypeSchema,
|
|
415
|
-
_zod.z.array(primitiveTypeSchema),
|
|
416
|
-
_zod.z.record(_zod.z.string(), primitiveTypeSchema),
|
|
417
|
-
_zod.z.record(_zod.z.string(), _zod.z.record(_zod.z.string(), primitiveTypeSchema))
|
|
418
|
-
])
|
|
419
|
-
);
|
|
420
|
-
var traceMetadataSchema = reservedTraceMetadataSchema.and(customMetadataSchema);
|
|
421
|
-
var eventSchema = _zod.z.object({
|
|
422
|
-
event_id: _zod.z.string(),
|
|
423
|
-
event_type: _zod.z.string(),
|
|
424
|
-
// Type of event (e.g., 'thumbs_up_down', 'add_to_cart')
|
|
425
|
-
project_id: _zod.z.string(),
|
|
426
|
-
metrics: _zod.z.record(_zod.z.string(), _zod.z.number()),
|
|
427
|
-
event_details: _zod.z.record(_zod.z.string(), _zod.z.string()),
|
|
428
|
-
trace_id: _zod.z.string(),
|
|
429
|
-
timestamps: _zod.z.object({
|
|
430
|
-
started_at: _zod.z.number(),
|
|
431
|
-
inserted_at: _zod.z.number(),
|
|
432
|
-
updated_at: _zod.z.number()
|
|
433
|
-
})
|
|
434
|
-
});
|
|
435
|
-
var elasticSearchEventSchema = eventSchema.omit({ metrics: true, event_details: true }).and(
|
|
436
|
-
_zod.z.object({
|
|
437
|
-
metrics: _zod.z.array(
|
|
438
|
-
_zod.z.object({
|
|
439
|
-
key: _zod.z.string(),
|
|
440
|
-
value: _zod.z.number()
|
|
441
|
-
})
|
|
442
|
-
),
|
|
443
|
-
event_details: _zod.z.array(
|
|
444
|
-
_zod.z.object({
|
|
445
|
-
key: _zod.z.string(),
|
|
446
|
-
value: _zod.z.string()
|
|
447
|
-
})
|
|
448
|
-
)
|
|
449
|
-
})
|
|
450
|
-
);
|
|
451
|
-
var evaluationStatusSchema = _zod.z.union([
|
|
452
|
-
_zod.z.literal("scheduled"),
|
|
453
|
-
_zod.z.literal("in_progress"),
|
|
454
|
-
_zod.z.literal("error"),
|
|
455
|
-
_zod.z.literal("skipped"),
|
|
456
|
-
_zod.z.literal("processed")
|
|
457
|
-
]);
|
|
458
|
-
var evaluationSchema = _zod.z.object({
|
|
459
|
-
evaluation_id: _zod.z.string(),
|
|
460
|
-
evaluator_id: _zod.z.string(),
|
|
461
|
-
span_id: _zod.z.string().optional().nullable(),
|
|
462
|
-
name: _zod.z.string(),
|
|
463
|
-
type: _zod.z.string().optional().nullable(),
|
|
464
|
-
is_guardrail: _zod.z.boolean().optional().nullable(),
|
|
465
|
-
evaluation_thread_id: _zod.z.string().optional().nullable(),
|
|
466
|
-
// Thread ID used for thread-based evaluation data
|
|
467
|
-
status: evaluationStatusSchema,
|
|
468
|
-
passed: _zod.z.boolean().optional().nullable(),
|
|
469
|
-
score: _zod.z.number().optional().nullable(),
|
|
470
|
-
label: _zod.z.string().optional().nullable(),
|
|
471
|
-
details: _zod.z.string().optional().nullable(),
|
|
472
|
-
inputs: _zod.z.record(_zod.z.string(), _zod.z.any()).optional().nullable(),
|
|
473
|
-
error: errorCaptureSchema.optional().nullable(),
|
|
474
|
-
retries: _zod.z.number().optional().nullable(),
|
|
475
|
-
timestamps: _zod.z.object({
|
|
476
|
-
ignore_timestamps_on_write: _zod.z.boolean().optional().nullable(),
|
|
477
|
-
inserted_at: _zod.z.number().optional().nullable(),
|
|
478
|
-
started_at: _zod.z.number().optional().nullable(),
|
|
479
|
-
finished_at: _zod.z.number().optional().nullable(),
|
|
480
|
-
updated_at: _zod.z.number().optional().nullable()
|
|
481
|
-
})
|
|
482
|
-
});
|
|
483
|
-
var rESTEvaluationSchema = evaluationSchema.omit({
|
|
484
|
-
evaluation_id: true,
|
|
485
|
-
evaluator_id: true,
|
|
486
|
-
status: true,
|
|
487
|
-
timestamps: true,
|
|
488
|
-
retries: true
|
|
489
|
-
}).and(
|
|
490
|
-
_zod.z.object({
|
|
491
|
-
evaluation_id: _zod.z.string().optional().nullable(),
|
|
492
|
-
evaluator_id: _zod.z.string().optional().nullable(),
|
|
493
|
-
status: _zod.z.union([
|
|
494
|
-
_zod.z.literal("processed"),
|
|
495
|
-
_zod.z.literal("skipped"),
|
|
496
|
-
_zod.z.literal("error")
|
|
497
|
-
]).optional().nullable(),
|
|
498
|
-
timestamps: _zod.z.object({
|
|
499
|
-
started_at: _zod.z.number().optional().nullable(),
|
|
500
|
-
finished_at: _zod.z.number().optional().nullable()
|
|
501
|
-
}).optional().nullable()
|
|
502
|
-
})
|
|
503
|
-
);
|
|
504
|
-
var tracePrivacySchema = _zod.z.object({
|
|
505
|
-
// Content categories that a `drop` privacy policy stripped before the spans
|
|
506
|
-
// were stored, derived at read time from the marker the drop stamps on each
|
|
507
|
-
// span. The content was never stored and cannot be recovered, which is what
|
|
508
|
-
// distinguishes it from a read-time `restrict` (the data is kept and hidden by
|
|
509
|
-
// audience, surfaced through the field-redaction path). Absent when nothing
|
|
510
|
-
// was dropped.
|
|
511
|
-
droppedCategories: _zod.z.array(_zod.z.string()).optional()
|
|
512
|
-
});
|
|
513
|
-
var traceSchema = _zod.z.object({
|
|
514
|
-
trace_id: _zod.z.string(),
|
|
515
|
-
project_id: _zod.z.string(),
|
|
516
|
-
metadata: traceMetadataSchema,
|
|
517
|
-
privacy: tracePrivacySchema.optional(),
|
|
518
|
-
timestamps: _zod.z.object({
|
|
519
|
-
started_at: _zod.z.number(),
|
|
520
|
-
inserted_at: _zod.z.number(),
|
|
521
|
-
updated_at: _zod.z.number()
|
|
522
|
-
}),
|
|
523
|
-
input: traceInputSchema.optional(),
|
|
524
|
-
output: traceOutputSchema.optional(),
|
|
525
|
-
contexts: _zod.z.array(rAGChunkSchema).optional(),
|
|
526
|
-
expected_output: _zod.z.object({
|
|
527
|
-
value: _zod.z.string()
|
|
528
|
-
}).optional(),
|
|
529
|
-
metrics: _zod.z.object({
|
|
530
|
-
first_token_ms: _zod.z.number().optional().nullable(),
|
|
531
|
-
total_time_ms: _zod.z.number().optional().nullable(),
|
|
532
|
-
prompt_tokens: _zod.z.number().optional().nullable(),
|
|
533
|
-
completion_tokens: _zod.z.number().optional().nullable(),
|
|
534
|
-
reasoning_tokens: _zod.z.number().optional().nullable(),
|
|
535
|
-
cache_read_input_tokens: _zod.z.number().optional().nullable(),
|
|
536
|
-
cache_creation_input_tokens: _zod.z.number().optional().nullable(),
|
|
537
|
-
total_cost: _zod.z.number().optional().nullable(),
|
|
538
|
-
tokens_estimated: _zod.z.boolean().optional().nullable()
|
|
539
|
-
}).optional(),
|
|
540
|
-
error: errorCaptureSchema.optional().nullable(),
|
|
541
|
-
indexing_md5s: _zod.z.array(_zod.z.string()).optional(),
|
|
542
|
-
events: _zod.z.array(eventSchema).optional(),
|
|
543
|
-
evaluations: _zod.z.array(evaluationSchema).optional(),
|
|
544
|
-
spans: _zod.z.array(spanSchema),
|
|
545
|
-
// Set server-side when content was teaser-redacted by the plan's
|
|
546
|
-
// visibility window — the UI renders the upgrade CTA off this flag.
|
|
547
|
-
redacted_by_visibility_window: _zod.z.boolean().optional()
|
|
548
|
-
});
|
|
549
|
-
var lLMModeTraceSchema = traceSchema.omit({ timestamps: true, indexing_md5s: true }).and(
|
|
550
|
-
_zod.z.object({
|
|
551
|
-
timestamps: _zod.z.object({
|
|
552
|
-
started_at: _zod.z.string(),
|
|
553
|
-
inserted_at: _zod.z.string(),
|
|
554
|
-
updated_at: _zod.z.string()
|
|
555
|
-
}),
|
|
556
|
-
ascii_tree: _zod.z.string()
|
|
557
|
-
})
|
|
558
|
-
);
|
|
559
|
-
var collectorRESTParamsSchema = _zod.z.object({
|
|
560
|
-
trace_id: _zod.z.union([_zod.z.string(), _zod.z.undefined()]).optional().nullable(),
|
|
561
|
-
spans: _zod.z.array(spanSchema),
|
|
562
|
-
metadata: _zod.z.object({
|
|
563
|
-
user_id: _zod.z.union([_zod.z.string(), _zod.z.undefined()]).optional().nullable(),
|
|
564
|
-
thread_id: _zod.z.union([_zod.z.string(), _zod.z.undefined()]).optional().nullable(),
|
|
565
|
-
customer_id: _zod.z.union([_zod.z.string(), _zod.z.undefined()]).optional().nullable(),
|
|
566
|
-
labels: _zod.z.union([_zod.z.array(_zod.z.string()), _zod.z.undefined()]).optional().nullable(),
|
|
567
|
-
sdk_version: _zod.z.union([_zod.z.string(), _zod.z.undefined()]).optional().nullable(),
|
|
568
|
-
sdk_language: _zod.z.union([_zod.z.string(), _zod.z.undefined()]).optional().nullable()
|
|
569
|
-
}).and(customMetadataSchema).optional(),
|
|
570
|
-
expected_output: _zod.z.string().optional().nullable(),
|
|
571
|
-
evaluations: _zod.z.array(rESTEvaluationSchema).optional()
|
|
572
|
-
});
|
|
573
|
-
var collectorRESTParamsValidatorSchema = collectorRESTParamsSchema.omit({ spans: true });
|
|
574
|
-
var trackEventRESTParamsValidatorSchema = eventSchema.omit({
|
|
575
|
-
event_id: true,
|
|
576
|
-
project_id: true,
|
|
577
|
-
timestamps: true,
|
|
578
|
-
event_details: true
|
|
579
|
-
}).and(
|
|
580
|
-
_zod.z.object({
|
|
581
|
-
event_id: _zod.z.string().optional(),
|
|
582
|
-
// auto generated unless you want to guarantee idempotency
|
|
583
|
-
event_details: _zod.z.record(_zod.z.string(), _zod.z.string().nullable()).optional(),
|
|
584
|
-
timestamp: _zod.z.number().optional()
|
|
585
|
-
// The timestamp when the event occurred
|
|
586
|
-
})
|
|
587
|
-
);
|
|
588
|
-
|
|
589
|
-
// src/observability-sdk/evaluation/index.ts
|
|
590
|
-
var _api = require('@opentelemetry/api');
|
|
591
|
-
var _xksuid = require('xksuid');
|
|
592
|
-
function toEpochMillis(value) {
|
|
593
|
-
return value instanceof Date ? value.getTime() : value;
|
|
594
|
-
}
|
|
595
|
-
function captureError(error) {
|
|
596
|
-
if (error instanceof Error) {
|
|
597
|
-
return {
|
|
598
|
-
message: String(error),
|
|
599
|
-
stacktrace: error.stack ? error.stack.split("\n") : []
|
|
600
|
-
};
|
|
601
|
-
}
|
|
602
|
-
return {
|
|
603
|
-
message: String(error),
|
|
604
|
-
stacktrace: []
|
|
605
|
-
};
|
|
606
|
-
}
|
|
607
|
-
function emitEvaluationEvent(span, params) {
|
|
608
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
609
|
-
const spanContext = span.spanContext();
|
|
610
|
-
const spanId = spanContext && _api.isSpanContextValid.call(void 0, spanContext) ? spanContext.spanId : null;
|
|
611
|
-
const payload = {
|
|
612
|
-
evaluation_id: (_a = params.evaluationId) != null ? _a : `eval_${_xksuid.generate.call(void 0, )}`,
|
|
613
|
-
span_id: spanId,
|
|
614
|
-
name: params.name,
|
|
615
|
-
type: (_b = params.type) != null ? _b : null,
|
|
616
|
-
is_guardrail: (_c = params.isGuardrail) != null ? _c : null,
|
|
617
|
-
status: (_d = params.status) != null ? _d : "processed",
|
|
618
|
-
passed: (_e = params.passed) != null ? _e : null,
|
|
619
|
-
score: (_f = params.score) != null ? _f : null,
|
|
620
|
-
label: (_g = params.label) != null ? _g : null,
|
|
621
|
-
details: (_h = params.details) != null ? _h : null,
|
|
622
|
-
error: params.error != null ? captureError(params.error) : null,
|
|
623
|
-
timestamps: params.timestamps ? {
|
|
624
|
-
started_at: toEpochMillis(params.timestamps.startedAt),
|
|
625
|
-
finished_at: toEpochMillis(params.timestamps.finishedAt)
|
|
626
|
-
} : null
|
|
627
|
-
};
|
|
628
|
-
span.addEvent(_chunkTKSTXX3Djs.ATTR_LANGWATCH_EVALUATION_CUSTOM, {
|
|
629
|
-
json_encoded_event: JSON.stringify(payload)
|
|
630
|
-
});
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
// src/observability-sdk/span/implementation.ts
|
|
634
|
-
var _incubating = require('@opentelemetry/semantic-conventions/incubating'); var semconv = _interopRequireWildcard(_incubating);
|
|
635
|
-
|
|
636
|
-
// src/observability-sdk/span/input-output.ts
|
|
637
|
-
|
|
638
|
-
var simpleChatMessageSchema = _zod.z.object({
|
|
639
|
-
role: _zod.z.string(),
|
|
640
|
-
content: _zod.z.union([_zod.z.string(), _zod.z.array(_zod.z.any())]).nullable().optional()
|
|
641
|
-
});
|
|
642
|
-
var simpleChatMessageArraySchema = _zod.z.array(simpleChatMessageSchema);
|
|
643
|
-
function createSafeFallbackValue(value) {
|
|
644
|
-
if (typeof value === "object" && value !== null) {
|
|
645
|
-
try {
|
|
646
|
-
return JSON.stringify(value);
|
|
647
|
-
} catch (e) {
|
|
648
|
-
return JSON.stringify({ type: "raw", value: "[Non-Serializable]" });
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
return String(value);
|
|
652
|
-
}
|
|
653
|
-
function createSafeSpanInputOutput(type, value) {
|
|
654
|
-
const safeValue = createSafeFallbackValue(value);
|
|
655
|
-
return { type, value: safeValue };
|
|
656
|
-
}
|
|
657
|
-
function isString(value) {
|
|
658
|
-
return typeof value === "string";
|
|
659
|
-
}
|
|
660
|
-
function isObject(value) {
|
|
661
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
662
|
-
}
|
|
663
|
-
function isChatMessage(value) {
|
|
664
|
-
if (!isObject(value)) return false;
|
|
665
|
-
return typeof value.role === "string" && (typeof value.content === "string" || value.content === null || value.content === void 0);
|
|
666
|
-
}
|
|
667
|
-
function isChatMessageArray(value) {
|
|
668
|
-
return Array.isArray(value) && value.every(isChatMessage);
|
|
669
|
-
}
|
|
670
|
-
function processChatMessages(value) {
|
|
671
|
-
const messages = Array.isArray(value) ? value : [value];
|
|
672
|
-
const strictResult = _zod.z.array(chatMessageSchema).safeParse(messages);
|
|
673
|
-
if (strictResult.success) {
|
|
674
|
-
return { type: "chat_messages", value: strictResult.data };
|
|
675
|
-
}
|
|
676
|
-
const simpleResult = simpleChatMessageArraySchema.safeParse(messages);
|
|
677
|
-
if (simpleResult.success) {
|
|
678
|
-
return { type: "chat_messages", value: simpleResult.data };
|
|
679
|
-
}
|
|
680
|
-
return createSafeSpanInputOutput("text", JSON.stringify(messages));
|
|
681
|
-
}
|
|
682
|
-
function convertToSpanInputOutput(value) {
|
|
683
|
-
try {
|
|
684
|
-
if (value === null || value === void 0) {
|
|
685
|
-
return spanInputOutputSchema.parse({ type: "json", value: null });
|
|
686
|
-
}
|
|
687
|
-
if (isString(value)) {
|
|
688
|
-
return spanInputOutputSchema.parse({ type: "text", value });
|
|
689
|
-
}
|
|
690
|
-
if (isChatMessage(value) || Array.isArray(value) && value.length > 0 && isChatMessageArray(value)) {
|
|
691
|
-
return processChatMessages(value);
|
|
692
|
-
}
|
|
693
|
-
if (Array.isArray(value)) {
|
|
694
|
-
return spanInputOutputSchema.parse({
|
|
695
|
-
type: "list",
|
|
696
|
-
value: value.map((item) => convertToSpanInputOutput(item))
|
|
697
|
-
});
|
|
698
|
-
}
|
|
699
|
-
if (isObject(value)) {
|
|
700
|
-
try {
|
|
701
|
-
return spanInputOutputSchema.parse({ type: "json", value });
|
|
702
|
-
} catch (e) {
|
|
703
|
-
return createSafeSpanInputOutput("text", value);
|
|
704
|
-
}
|
|
705
|
-
}
|
|
706
|
-
return createSafeSpanInputOutput("text", value);
|
|
707
|
-
} catch (e) {
|
|
708
|
-
return createSafeSpanInputOutput("text", value);
|
|
709
|
-
}
|
|
710
|
-
}
|
|
711
|
-
function isValidInputOutputType(type) {
|
|
712
|
-
return INPUT_OUTPUT_TYPES.includes(type);
|
|
713
|
-
}
|
|
714
|
-
function validateValueForInputOutputType(type, value) {
|
|
715
|
-
switch (type) {
|
|
716
|
-
case "chat_messages": {
|
|
717
|
-
const messages = Array.isArray(value) ? value : [value];
|
|
718
|
-
const strictResult = _zod.z.array(chatMessageSchema).safeParse(messages);
|
|
719
|
-
if (strictResult.success) {
|
|
720
|
-
return strictResult.data;
|
|
721
|
-
}
|
|
722
|
-
const simpleResult = simpleChatMessageArraySchema.safeParse(messages);
|
|
723
|
-
if (simpleResult.success) {
|
|
724
|
-
return simpleResult.data;
|
|
725
|
-
}
|
|
726
|
-
return [{ role: "user", content: createSafeFallbackValue(value) }];
|
|
727
|
-
}
|
|
728
|
-
case "list": {
|
|
729
|
-
const listResult = _zod.z.array(spanInputOutputSchema).safeParse(value);
|
|
730
|
-
return listResult.success ? listResult.data : [{ type: "text", value: createSafeFallbackValue(value) }];
|
|
731
|
-
}
|
|
732
|
-
case "json": {
|
|
733
|
-
try {
|
|
734
|
-
JSON.stringify(value);
|
|
735
|
-
return value;
|
|
736
|
-
} catch (e) {
|
|
737
|
-
return createSafeFallbackValue(value);
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
case "text":
|
|
741
|
-
case "raw": {
|
|
742
|
-
const stringResult = _zod.z.string().safeParse(value);
|
|
743
|
-
return stringResult.success ? stringResult.data : createSafeFallbackValue(value);
|
|
744
|
-
}
|
|
745
|
-
case "guardrail_result":
|
|
746
|
-
case "evaluation_result": {
|
|
747
|
-
try {
|
|
748
|
-
JSON.stringify(value);
|
|
749
|
-
return value;
|
|
750
|
-
} catch (e) {
|
|
751
|
-
return createSafeFallbackValue(value);
|
|
752
|
-
}
|
|
753
|
-
}
|
|
754
|
-
default:
|
|
755
|
-
return value;
|
|
756
|
-
}
|
|
757
|
-
}
|
|
758
|
-
function processSpanInputOutput(typeOrValue, value) {
|
|
759
|
-
try {
|
|
760
|
-
if (typeof typeOrValue === "string" && value !== void 0) {
|
|
761
|
-
const type = isValidInputOutputType(typeOrValue) ? typeOrValue : "json";
|
|
762
|
-
const validatedValue = validateValueForInputOutputType(type, value);
|
|
763
|
-
const result = spanInputOutputSchema.safeParse({ type, value: validatedValue });
|
|
764
|
-
return result.success ? result.data : createSafeSpanInputOutput("raw", validatedValue);
|
|
765
|
-
}
|
|
766
|
-
return convertToSpanInputOutput(typeOrValue);
|
|
767
|
-
} catch (e) {
|
|
768
|
-
return createSafeSpanInputOutput("text", typeOrValue);
|
|
769
|
-
}
|
|
770
|
-
}
|
|
771
|
-
|
|
772
|
-
// src/observability-sdk/span/implementation.ts
|
|
773
|
-
var LangWatchSpanInternal = class {
|
|
774
|
-
constructor(span) {
|
|
775
|
-
this.span = span;
|
|
776
|
-
}
|
|
777
|
-
setAttributes(attributes) {
|
|
778
|
-
this.span.setAttributes(attributes);
|
|
779
|
-
return this;
|
|
780
|
-
}
|
|
781
|
-
setAttribute(key, value) {
|
|
782
|
-
this.span.setAttribute(key, value);
|
|
783
|
-
return this;
|
|
784
|
-
}
|
|
785
|
-
addEvent(name, attributes) {
|
|
786
|
-
this.span.addEvent(name, attributes);
|
|
787
|
-
return this;
|
|
788
|
-
}
|
|
789
|
-
recordException(exception) {
|
|
790
|
-
this.span.recordException(exception);
|
|
791
|
-
return this;
|
|
792
|
-
}
|
|
793
|
-
setStatus(status) {
|
|
794
|
-
this.span.setStatus(status);
|
|
795
|
-
return this;
|
|
796
|
-
}
|
|
797
|
-
updateName(name) {
|
|
798
|
-
this.span.updateName(name);
|
|
799
|
-
return this;
|
|
800
|
-
}
|
|
801
|
-
end(endTime) {
|
|
802
|
-
this.span.end(endTime);
|
|
803
|
-
}
|
|
804
|
-
isRecording() {
|
|
805
|
-
return this.span.isRecording();
|
|
806
|
-
}
|
|
807
|
-
spanContext() {
|
|
808
|
-
return this.span.spanContext();
|
|
809
|
-
}
|
|
810
|
-
addLink(link) {
|
|
811
|
-
this.span.addLink(link);
|
|
812
|
-
return this;
|
|
813
|
-
}
|
|
814
|
-
addLinks(links) {
|
|
815
|
-
this.span.addLinks(links);
|
|
816
|
-
return this;
|
|
817
|
-
}
|
|
818
|
-
/**
|
|
819
|
-
* Records a manual evaluation on this span by emitting the `langwatch.evaluation.custom` span
|
|
820
|
-
* event. See {@link AddEvaluationParams} for available parameters.
|
|
821
|
-
*/
|
|
822
|
-
addEvaluation(params) {
|
|
823
|
-
emitEvaluationEvent(this.span, params);
|
|
824
|
-
return this;
|
|
825
|
-
}
|
|
826
|
-
/**
|
|
827
|
-
* @deprecated Use {@link addEvaluation} instead. Thin back-compat alias kept for
|
|
828
|
-
* the earlier documented name.
|
|
829
|
-
*/
|
|
830
|
-
recordEvaluation(params) {
|
|
831
|
-
return this.addEvaluation(params);
|
|
832
|
-
}
|
|
833
|
-
setType(type) {
|
|
834
|
-
return this.setAttribute(_chunkTKSTXX3Djs.ATTR_LANGWATCH_SPAN_TYPE, type);
|
|
835
|
-
}
|
|
836
|
-
setSelectedPrompt(prompt) {
|
|
837
|
-
return this.setAttributes({
|
|
838
|
-
[_chunkTKSTXX3Djs.ATTR_LANGWATCH_PROMPT_SELECTED_ID]: prompt.id,
|
|
839
|
-
[_chunkTKSTXX3Djs.ATTR_LANGWATCH_PROMPT_ID]: prompt.id,
|
|
840
|
-
[_chunkTKSTXX3Djs.ATTR_LANGWATCH_PROMPT_VERSION_ID]: prompt.versionId,
|
|
841
|
-
[_chunkTKSTXX3Djs.ATTR_LANGWATCH_PROMPT_VERSION_NUMBER]: prompt.version
|
|
842
|
-
});
|
|
843
|
-
}
|
|
844
|
-
setRequestModel(model) {
|
|
845
|
-
return this.setAttribute(semconv.ATTR_GEN_AI_REQUEST_MODEL, model);
|
|
846
|
-
}
|
|
847
|
-
setResponseModel(model) {
|
|
848
|
-
return this.setAttribute(semconv.ATTR_GEN_AI_RESPONSE_MODEL, model);
|
|
849
|
-
}
|
|
850
|
-
setRAGContexts(ragContexts) {
|
|
851
|
-
return this.setAttribute(
|
|
852
|
-
_chunkTKSTXX3Djs.ATTR_LANGWATCH_RAG_CONTEXTS,
|
|
853
|
-
JSON.stringify(ragContexts)
|
|
854
|
-
);
|
|
855
|
-
}
|
|
856
|
-
setRAGContext(ragContext) {
|
|
857
|
-
return this.setRAGContexts([ragContext]);
|
|
858
|
-
}
|
|
859
|
-
setMetrics(metrics) {
|
|
860
|
-
return this.setAttribute(
|
|
861
|
-
_chunkTKSTXX3Djs.ATTR_LANGWATCH_METRICS,
|
|
862
|
-
JSON.stringify({
|
|
863
|
-
type: "json",
|
|
864
|
-
value: metrics
|
|
865
|
-
})
|
|
866
|
-
);
|
|
867
|
-
}
|
|
868
|
-
setInput(typeOrInput, input) {
|
|
869
|
-
const spanInput = processSpanInputOutput(typeOrInput, input);
|
|
870
|
-
return this.setAttribute(
|
|
871
|
-
_chunkTKSTXX3Djs.ATTR_LANGWATCH_INPUT,
|
|
872
|
-
JSON.stringify(spanInput)
|
|
873
|
-
);
|
|
874
|
-
}
|
|
875
|
-
setOutput(typeOrOutput, output) {
|
|
876
|
-
const spanOutput = processSpanInputOutput(typeOrOutput, output);
|
|
877
|
-
return this.setAttribute(
|
|
878
|
-
_chunkTKSTXX3Djs.ATTR_LANGWATCH_OUTPUT,
|
|
879
|
-
JSON.stringify(spanOutput)
|
|
880
|
-
);
|
|
881
|
-
}
|
|
882
|
-
};
|
|
883
|
-
function createLangWatchSpan(span) {
|
|
884
|
-
return new LangWatchSpanInternal(span);
|
|
885
|
-
}
|
|
886
|
-
|
|
887
|
-
// src/observability-sdk/tracer/implementation.ts
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
function getLangWatchTracer(name, version) {
|
|
893
|
-
return getLangWatchTracerFromProvider(
|
|
894
|
-
_api.trace.getTracerProvider(),
|
|
895
|
-
name,
|
|
896
|
-
version
|
|
897
|
-
);
|
|
898
|
-
}
|
|
899
|
-
function getLangWatchTracerFromProvider(tracerProvider, name, version) {
|
|
900
|
-
const tracer = tracerProvider.getTracer(name, version);
|
|
901
|
-
let proxyInstance;
|
|
902
|
-
const handler = {
|
|
903
|
-
get(target, prop) {
|
|
904
|
-
switch (prop) {
|
|
905
|
-
case "startActiveSpan":
|
|
906
|
-
return (...args) => {
|
|
907
|
-
const spanArgs = normalizeSpanArgs(args);
|
|
908
|
-
const options = withDefaultOrigin(spanArgs.options);
|
|
909
|
-
const wrappedFn = (span, ...cbArgs) => spanArgs.fn(createLangWatchSpan(span), ...cbArgs);
|
|
910
|
-
if (spanArgs.context !== void 0)
|
|
911
|
-
return target.startActiveSpan(spanArgs.name, options, spanArgs.context, wrappedFn);
|
|
912
|
-
return target.startActiveSpan(spanArgs.name, options, wrappedFn);
|
|
913
|
-
};
|
|
914
|
-
case "withActiveSpan":
|
|
915
|
-
return (...args) => {
|
|
916
|
-
const spanArgs = normalizeSpanArgs(args);
|
|
917
|
-
const optionsWithOrigin = withDefaultOrigin(spanArgs.options);
|
|
918
|
-
const cb = (span) => {
|
|
919
|
-
var _a, _b;
|
|
920
|
-
const wrappedSpan = createLangWatchSpan(span);
|
|
921
|
-
try {
|
|
922
|
-
const result = spanArgs.fn(wrappedSpan);
|
|
923
|
-
if (result && typeof result.then === "function") {
|
|
924
|
-
return result.then((result2) => {
|
|
925
|
-
wrappedSpan.setStatus({
|
|
926
|
-
code: _api.SpanStatusCode.OK
|
|
927
|
-
});
|
|
928
|
-
return result2;
|
|
929
|
-
}).catch((err) => {
|
|
930
|
-
var _a2, _b2;
|
|
931
|
-
wrappedSpan.setStatus({
|
|
932
|
-
code: _api.SpanStatusCode.ERROR,
|
|
933
|
-
message: (_a2 = err == null ? void 0 : err.message) != null ? _a2 : String(err)
|
|
934
|
-
});
|
|
935
|
-
(_b2 = wrappedSpan.recordException) == null ? void 0 : _b2.call(wrappedSpan, err);
|
|
936
|
-
throw err;
|
|
937
|
-
}).finally(() => {
|
|
938
|
-
wrappedSpan.end();
|
|
939
|
-
});
|
|
940
|
-
}
|
|
941
|
-
wrappedSpan.setStatus({
|
|
942
|
-
code: _api.SpanStatusCode.OK
|
|
943
|
-
});
|
|
944
|
-
wrappedSpan.end();
|
|
945
|
-
return result;
|
|
946
|
-
} catch (err) {
|
|
947
|
-
wrappedSpan.setStatus({
|
|
948
|
-
code: _api.SpanStatusCode.ERROR,
|
|
949
|
-
message: (_a = err == null ? void 0 : err.message) != null ? _a : String(err)
|
|
950
|
-
});
|
|
951
|
-
(_b = wrappedSpan.recordException) == null ? void 0 : _b.call(wrappedSpan, err);
|
|
952
|
-
wrappedSpan.end();
|
|
953
|
-
throw err;
|
|
954
|
-
}
|
|
955
|
-
};
|
|
956
|
-
if (spanArgs.context !== void 0)
|
|
957
|
-
return target.startActiveSpan(spanArgs.name, optionsWithOrigin, spanArgs.context, cb);
|
|
958
|
-
return target.startActiveSpan(spanArgs.name, optionsWithOrigin, cb);
|
|
959
|
-
};
|
|
960
|
-
case "startSpan":
|
|
961
|
-
return (name2, options, context) => createLangWatchSpan(target.startSpan(name2, withDefaultOrigin(options), context));
|
|
962
|
-
case "addEvaluation":
|
|
963
|
-
return (params) => {
|
|
964
|
-
const activeSpan = _api.trace.getActiveSpan();
|
|
965
|
-
if (!activeSpan) return;
|
|
966
|
-
emitEvaluationEvent(activeSpan, params);
|
|
967
|
-
};
|
|
968
|
-
default: {
|
|
969
|
-
const value = target[prop];
|
|
970
|
-
return typeof value === "function" ? value.bind(target) : value;
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
}
|
|
974
|
-
};
|
|
975
|
-
proxyInstance = new Proxy(tracer, handler);
|
|
976
|
-
return proxyInstance;
|
|
977
|
-
}
|
|
978
|
-
function normalizeSpanArgs(args) {
|
|
979
|
-
const [name, arg2, arg3, arg4] = args;
|
|
980
|
-
if (typeof arg4 === "function")
|
|
981
|
-
return { name, options: arg2, context: arg3, fn: arg4 };
|
|
982
|
-
if (typeof arg3 === "function") return { name, options: arg2, fn: arg3 };
|
|
983
|
-
if (typeof arg2 === "function") return { name, fn: arg2 };
|
|
984
|
-
throw new Error("Expected a span callback as the last argument");
|
|
985
|
-
}
|
|
986
|
-
function withDefaultOrigin(options) {
|
|
987
|
-
var _a;
|
|
988
|
-
const existing = (_a = options == null ? void 0 : options.attributes) == null ? void 0 : _a["langwatch.origin"];
|
|
989
|
-
if (existing) return options != null ? options : {};
|
|
990
|
-
return _chunkTKSTXX3Djs.__spreadProps.call(void 0, _chunkTKSTXX3Djs.__spreadValues.call(void 0, {}, options), {
|
|
991
|
-
attributes: _chunkTKSTXX3Djs.__spreadProps.call(void 0, _chunkTKSTXX3Djs.__spreadValues.call(void 0, {}, options == null ? void 0 : options.attributes), {
|
|
992
|
-
"langwatch.origin": "application"
|
|
993
|
-
})
|
|
994
|
-
});
|
|
995
|
-
}
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
exports.spanTypes = spanTypes; exports.chatMessageSchema = chatMessageSchema; exports.emitEvaluationEvent = emitEvaluationEvent; exports.createLangWatchSpan = createLangWatchSpan; exports.getLangWatchTracer = getLangWatchTracer; exports.getLangWatchTracerFromProvider = getLangWatchTracerFromProvider;
|
|
1005
|
-
//# sourceMappingURL=chunk-ADJOFPAZ.js.map
|