evalution 2.0.3 → 2.0.5
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/dist/cli/index.js +59 -9
- package/dist/client/assets/{DatasetView-DZ2uLHKV.js → DatasetView-dWZOCEO1.js} +4 -4
- package/dist/client/assets/{EvalRunView-T610dLVw.js → EvalRunView-Cm1YhpbN.js} +1 -1
- package/dist/client/assets/{EvalView-Cae68vPB.js → EvalView-By5XAZnh.js} +1 -1
- package/dist/client/assets/{data-grid-overlay-editor-PtH7A6E4.js → data-grid-overlay-editor-BuUUbLjU.js} +1 -1
- package/dist/client/assets/{highlighted-body-KPVGNVTW-CPtwvSJb.js → highlighted-body-KPVGNVTW-B5z7-guY.js} +1 -1
- package/dist/client/assets/{index-BFH07Ynk.js → index-BK0ALIOn.js} +128 -128
- package/dist/client/assets/{number-overlay-editor-BbQhagHP.js → number-overlay-editor-DIsrCfnq.js} +1 -1
- package/dist/client/index.html +1 -1
- package/dist/{cost-fetching-trace-sink-Dz8gniQ6.js → cost-fetching-trace-sink-X0hvDGGH.js} +1 -1
- package/dist/index.d.ts +25 -4
- package/dist/index.js +2 -2
- package/dist/ingest.d.ts +1 -1
- package/dist/ingest.js +2 -2
- package/dist/{local-database-trace-provider-87-WGqfS.js → local-database-trace-provider-Dy64Lll3.js} +69 -10
- package/dist/{trace-event-ingestor-B1DYEg2H.js → trace-event-ingestor-Bu2FKHC4.js} +293 -157
- package/dist/{trace-event-ingestor-JNpe-OrX.d.ts → trace-event-ingestor-D2zmkQm1.d.ts} +1 -1
- package/package.json +6 -6
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { SpanStatusCode } from "@opentelemetry/api";
|
|
2
2
|
import { BaseTraceIngestor, PROMPT_ID_ATTRIBUTE, PROMPT_INPUTS_ATTRIBUTE, PROMPT_NAME_ATTRIBUTE, PROMPT_PROVIDER_ID_ATTRIBUTE, PROMPT_VARIATION_ATTRIBUTE, PROMPT_VERSION_ATTRIBUTE, SPAN_KIND_ATTRIBUTE, answersWithConfidence, toolCallingOutput, unwrapToolResultOutput } from "@evalution/sdk";
|
|
3
|
-
import protobuf from "protobufjs";
|
|
4
3
|
//#region src/shared/helpers.ts
|
|
5
4
|
function otelOperationToSpanKind(operationName) {
|
|
6
5
|
switch (operationName) {
|
|
@@ -146,170 +145,266 @@ function normalizeOtlpRequest(body) {
|
|
|
146
145
|
}
|
|
147
146
|
//#endregion
|
|
148
147
|
//#region src/trace/otlp/otlp-protobuf.ts
|
|
149
|
-
const
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
}
|
|
232
|
-
message ResourceSpans {
|
|
233
|
-
Resource resource = 1;
|
|
234
|
-
repeated ScopeSpans scope_spans = 2;
|
|
235
|
-
string schema_url = 3;
|
|
236
|
-
}
|
|
237
|
-
message ExportTraceServiceRequest {
|
|
238
|
-
repeated ResourceSpans resource_spans = 1;
|
|
239
|
-
}
|
|
240
|
-
`, { keepCase: false }).root.lookupType("otlp.ExportTraceServiceRequest");
|
|
148
|
+
const VARINT = 0;
|
|
149
|
+
const FIXED64 = 1;
|
|
150
|
+
const LENGTH_DELIMITED = 2;
|
|
151
|
+
const FIXED32 = 5;
|
|
152
|
+
const utf8 = new TextDecoder();
|
|
153
|
+
/** A cursor over one message's bytes. */
|
|
154
|
+
var Reader = class Reader {
|
|
155
|
+
pos = 0;
|
|
156
|
+
buf;
|
|
157
|
+
view;
|
|
158
|
+
constructor(buf) {
|
|
159
|
+
this.buf = buf;
|
|
160
|
+
this.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
161
|
+
}
|
|
162
|
+
/** Calls `onField` with each field's number and wire type, in order. */
|
|
163
|
+
forEachField(onField) {
|
|
164
|
+
while (this.pos < this.buf.length) {
|
|
165
|
+
const tag = this.varint();
|
|
166
|
+
const field = Number(tag >> 3n);
|
|
167
|
+
const wireType = Number(tag & 7n);
|
|
168
|
+
if (field === 0) throw new Error("invalid field number 0");
|
|
169
|
+
if (!onField(field, wireType)) this.skip(wireType);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
varint() {
|
|
173
|
+
let result = 0n;
|
|
174
|
+
for (let shift = 0n; shift < 70n; shift += 7n) {
|
|
175
|
+
if (this.pos >= this.buf.length) throw new Error("truncated varint");
|
|
176
|
+
const byte = this.buf[this.pos++];
|
|
177
|
+
result |= BigInt(byte & 127) << shift;
|
|
178
|
+
if (byte < 128) return BigInt.asUintN(64, result);
|
|
179
|
+
}
|
|
180
|
+
throw new Error("varint too long");
|
|
181
|
+
}
|
|
182
|
+
fixed64() {
|
|
183
|
+
this.need(8);
|
|
184
|
+
const value = this.view.getBigUint64(this.pos, true);
|
|
185
|
+
this.pos += 8;
|
|
186
|
+
return value;
|
|
187
|
+
}
|
|
188
|
+
double() {
|
|
189
|
+
this.need(8);
|
|
190
|
+
const value = this.view.getFloat64(this.pos, true);
|
|
191
|
+
this.pos += 8;
|
|
192
|
+
return value;
|
|
193
|
+
}
|
|
194
|
+
bytes() {
|
|
195
|
+
const length = Number(this.varint());
|
|
196
|
+
this.need(length);
|
|
197
|
+
const value = this.buf.subarray(this.pos, this.pos + length);
|
|
198
|
+
this.pos += length;
|
|
199
|
+
return value;
|
|
200
|
+
}
|
|
201
|
+
string() {
|
|
202
|
+
return utf8.decode(this.bytes());
|
|
203
|
+
}
|
|
204
|
+
/** Decodes a length-delimited submessage with `decode`. */
|
|
205
|
+
message(decode) {
|
|
206
|
+
return decode(new Reader(this.bytes()));
|
|
207
|
+
}
|
|
208
|
+
skip(wireType) {
|
|
209
|
+
switch (wireType) {
|
|
210
|
+
case VARINT:
|
|
211
|
+
this.varint();
|
|
212
|
+
return;
|
|
213
|
+
case FIXED64:
|
|
214
|
+
this.need(8);
|
|
215
|
+
this.pos += 8;
|
|
216
|
+
return;
|
|
217
|
+
case LENGTH_DELIMITED:
|
|
218
|
+
this.bytes();
|
|
219
|
+
return;
|
|
220
|
+
case FIXED32:
|
|
221
|
+
this.need(4);
|
|
222
|
+
this.pos += 4;
|
|
223
|
+
return;
|
|
224
|
+
default: throw new Error(`unsupported wire type ${wireType}`);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
need(length) {
|
|
228
|
+
if (this.pos + length > this.buf.length) throw new Error("truncated message");
|
|
229
|
+
}
|
|
230
|
+
};
|
|
241
231
|
function bytesToHex(bytes) {
|
|
242
232
|
if (!bytes || bytes.length === 0) return void 0;
|
|
243
233
|
let hex = "";
|
|
244
234
|
for (let i = 0; i < bytes.length; i++) hex += bytes[i].toString(16).padStart(2, "0");
|
|
245
235
|
return hex;
|
|
246
236
|
}
|
|
247
|
-
function
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
237
|
+
function decodeAnyValue(r) {
|
|
238
|
+
let value;
|
|
239
|
+
r.forEachField((field, wireType) => {
|
|
240
|
+
if (field === 1 && wireType === LENGTH_DELIMITED) value = { stringValue: r.string() };
|
|
241
|
+
else if (field === 2 && wireType === VARINT) value = { boolValue: r.varint() !== 0n };
|
|
242
|
+
else if (field === 3 && wireType === VARINT) value = { intValue: String(BigInt.asIntN(64, r.varint())) };
|
|
243
|
+
else if (field === 4 && wireType === FIXED64) value = { doubleValue: r.double() };
|
|
244
|
+
else if (field === 5 && wireType === LENGTH_DELIMITED) value = { arrayValue: { values: r.message(decodeRepeated(decodeAnyValue)) } };
|
|
245
|
+
else if (field === 6 && wireType === LENGTH_DELIMITED) value = { kvlistValue: { values: r.message(decodeRepeated(decodeKeyValue)) } };
|
|
246
|
+
else if (field === 7 && wireType === LENGTH_DELIMITED) value = { stringValue: bytesToHex(r.bytes()) ?? "" };
|
|
247
|
+
else return false;
|
|
248
|
+
return true;
|
|
249
|
+
});
|
|
250
|
+
return value;
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Decodes a message whose one field read here is a repeated submessage at
|
|
254
|
+
* field 1: `ArrayValue`, `KeyValueList`, `Resource` and
|
|
255
|
+
* `ExportTraceServiceRequest`.
|
|
256
|
+
*/
|
|
257
|
+
function decodeRepeated(decode) {
|
|
258
|
+
return (r) => {
|
|
259
|
+
const values = [];
|
|
260
|
+
r.forEachField((field, wireType) => {
|
|
261
|
+
if (field !== 1 || wireType !== LENGTH_DELIMITED) return false;
|
|
262
|
+
values.push(r.message(decode));
|
|
263
|
+
return true;
|
|
264
|
+
});
|
|
265
|
+
return values;
|
|
261
266
|
};
|
|
262
267
|
}
|
|
263
|
-
function
|
|
268
|
+
function decodeKeyValue(r) {
|
|
269
|
+
let key = "";
|
|
270
|
+
let value;
|
|
271
|
+
r.forEachField((field, wireType) => {
|
|
272
|
+
if (wireType !== LENGTH_DELIMITED) return false;
|
|
273
|
+
if (field === 1) key = r.string();
|
|
274
|
+
else if (field === 2) value = r.message(decodeAnyValue);
|
|
275
|
+
else return false;
|
|
276
|
+
return true;
|
|
277
|
+
});
|
|
264
278
|
return {
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
parentSpanId: bytesToHex(s.parentSpanId),
|
|
268
|
-
traceState: s.traceState,
|
|
269
|
-
name: s.name ?? "",
|
|
270
|
-
kind: typeof s.kind === "number" ? s.kind : 0,
|
|
271
|
-
startTimeUnixNano: String(s.startTimeUnixNano ?? "0"),
|
|
272
|
-
endTimeUnixNano: String(s.endTimeUnixNano ?? "0"),
|
|
273
|
-
attributes: (s.attributes ?? []).map(convertKeyValue),
|
|
274
|
-
events: (s.events ?? []).map((e) => ({
|
|
275
|
-
timeUnixNano: String(e.timeUnixNano ?? "0"),
|
|
276
|
-
name: e.name ?? "",
|
|
277
|
-
attributes: (e.attributes ?? []).map(convertKeyValue)
|
|
278
|
-
})),
|
|
279
|
-
links: (s.links ?? []).map((l) => ({
|
|
280
|
-
traceId: bytesToHex(l.traceId) ?? "",
|
|
281
|
-
spanId: bytesToHex(l.spanId) ?? "",
|
|
282
|
-
attributes: (l.attributes ?? []).map(convertKeyValue)
|
|
283
|
-
})),
|
|
284
|
-
status: s.status ? {
|
|
285
|
-
code: typeof s.status.code === "number" ? s.status.code : 0,
|
|
286
|
-
message: s.status.message
|
|
287
|
-
} : void 0
|
|
279
|
+
key,
|
|
280
|
+
value
|
|
288
281
|
};
|
|
289
282
|
}
|
|
283
|
+
function decodeStatus(r) {
|
|
284
|
+
const status = { code: 0 };
|
|
285
|
+
r.forEachField((field, wireType) => {
|
|
286
|
+
if (field === 2 && wireType === LENGTH_DELIMITED) status.message = r.string();
|
|
287
|
+
else if (field === 3 && wireType === VARINT) status.code = Number(BigInt.asIntN(32, r.varint()));
|
|
288
|
+
else return false;
|
|
289
|
+
return true;
|
|
290
|
+
});
|
|
291
|
+
return status;
|
|
292
|
+
}
|
|
293
|
+
function decodeEvent(r) {
|
|
294
|
+
const event = {
|
|
295
|
+
timeUnixNano: "0",
|
|
296
|
+
name: "",
|
|
297
|
+
attributes: []
|
|
298
|
+
};
|
|
299
|
+
r.forEachField((field, wireType) => {
|
|
300
|
+
if (field === 1 && wireType === FIXED64) event.timeUnixNano = String(r.fixed64());
|
|
301
|
+
else if (field === 2 && wireType === LENGTH_DELIMITED) event.name = r.string();
|
|
302
|
+
else if (field === 3 && wireType === LENGTH_DELIMITED) event.attributes.push(r.message(decodeKeyValue));
|
|
303
|
+
else return false;
|
|
304
|
+
return true;
|
|
305
|
+
});
|
|
306
|
+
return event;
|
|
307
|
+
}
|
|
308
|
+
function decodeLink(r) {
|
|
309
|
+
const link = {
|
|
310
|
+
traceId: "",
|
|
311
|
+
spanId: "",
|
|
312
|
+
attributes: []
|
|
313
|
+
};
|
|
314
|
+
r.forEachField((field, wireType) => {
|
|
315
|
+
if (wireType !== LENGTH_DELIMITED) return false;
|
|
316
|
+
if (field === 1) link.traceId = bytesToHex(r.bytes()) ?? "";
|
|
317
|
+
else if (field === 2) link.spanId = bytesToHex(r.bytes()) ?? "";
|
|
318
|
+
else if (field === 4) link.attributes.push(r.message(decodeKeyValue));
|
|
319
|
+
else return false;
|
|
320
|
+
return true;
|
|
321
|
+
});
|
|
322
|
+
return link;
|
|
323
|
+
}
|
|
324
|
+
function decodeSpan(r) {
|
|
325
|
+
const span = {
|
|
326
|
+
traceId: "",
|
|
327
|
+
spanId: "",
|
|
328
|
+
parentSpanId: void 0,
|
|
329
|
+
traceState: void 0,
|
|
330
|
+
name: "",
|
|
331
|
+
kind: 0,
|
|
332
|
+
startTimeUnixNano: "0",
|
|
333
|
+
endTimeUnixNano: "0",
|
|
334
|
+
attributes: [],
|
|
335
|
+
events: [],
|
|
336
|
+
links: [],
|
|
337
|
+
status: void 0
|
|
338
|
+
};
|
|
339
|
+
r.forEachField((field, wireType) => {
|
|
340
|
+
if (wireType === LENGTH_DELIMITED) if (field === 1) span.traceId = bytesToHex(r.bytes()) ?? "";
|
|
341
|
+
else if (field === 2) span.spanId = bytesToHex(r.bytes()) ?? "";
|
|
342
|
+
else if (field === 3) span.traceState = r.string() || void 0;
|
|
343
|
+
else if (field === 4) span.parentSpanId = bytesToHex(r.bytes());
|
|
344
|
+
else if (field === 5) span.name = r.string();
|
|
345
|
+
else if (field === 9) span.attributes.push(r.message(decodeKeyValue));
|
|
346
|
+
else if (field === 11) span.events.push(r.message(decodeEvent));
|
|
347
|
+
else if (field === 13) span.links.push(r.message(decodeLink));
|
|
348
|
+
else if (field === 15) span.status = r.message(decodeStatus);
|
|
349
|
+
else return false;
|
|
350
|
+
else if (field === 6 && wireType === VARINT) span.kind = Number(BigInt.asIntN(32, r.varint()));
|
|
351
|
+
else if (field === 7 && wireType === FIXED64) span.startTimeUnixNano = String(r.fixed64());
|
|
352
|
+
else if (field === 8 && wireType === FIXED64) span.endTimeUnixNano = String(r.fixed64());
|
|
353
|
+
else return false;
|
|
354
|
+
return true;
|
|
355
|
+
});
|
|
356
|
+
return span;
|
|
357
|
+
}
|
|
358
|
+
function decodeScope(r) {
|
|
359
|
+
const scope = { name: "" };
|
|
360
|
+
r.forEachField((field, wireType) => {
|
|
361
|
+
if (wireType !== LENGTH_DELIMITED) return false;
|
|
362
|
+
if (field === 1) scope.name = r.string();
|
|
363
|
+
else if (field === 2) scope.version = r.string() || void 0;
|
|
364
|
+
else return false;
|
|
365
|
+
return true;
|
|
366
|
+
});
|
|
367
|
+
return scope;
|
|
368
|
+
}
|
|
369
|
+
function decodeScopeSpans(r) {
|
|
370
|
+
const scopeSpans = {
|
|
371
|
+
scope: void 0,
|
|
372
|
+
spans: []
|
|
373
|
+
};
|
|
374
|
+
r.forEachField((field, wireType) => {
|
|
375
|
+
if (wireType !== LENGTH_DELIMITED) return false;
|
|
376
|
+
if (field === 1) scopeSpans.scope = r.message(decodeScope);
|
|
377
|
+
else if (field === 2) scopeSpans.spans.push(r.message(decodeSpan));
|
|
378
|
+
else return false;
|
|
379
|
+
return true;
|
|
380
|
+
});
|
|
381
|
+
return scopeSpans;
|
|
382
|
+
}
|
|
383
|
+
function decodeResource(r) {
|
|
384
|
+
return { attributes: decodeRepeated(decodeKeyValue)(r) };
|
|
385
|
+
}
|
|
386
|
+
function decodeResourceSpans(r) {
|
|
387
|
+
const resourceSpans = {
|
|
388
|
+
resource: { attributes: [] },
|
|
389
|
+
scopeSpans: []
|
|
390
|
+
};
|
|
391
|
+
r.forEachField((field, wireType) => {
|
|
392
|
+
if (wireType !== LENGTH_DELIMITED) return false;
|
|
393
|
+
if (field === 1) resourceSpans.resource = r.message(decodeResource);
|
|
394
|
+
else if (field === 2) resourceSpans.scopeSpans.push(r.message(decodeScopeSpans));
|
|
395
|
+
else return false;
|
|
396
|
+
return true;
|
|
397
|
+
});
|
|
398
|
+
return resourceSpans;
|
|
399
|
+
}
|
|
290
400
|
/**
|
|
291
401
|
* Decodes an OTLP/protobuf `ExportTraceServiceRequest` payload into the same
|
|
292
402
|
* plain-object shape as the OTLP/JSON encoding (camelCase keys, hex trace/span
|
|
293
403
|
* ids, stringified 64-bit values) — so `../otlp/normalize.ts` can walk either
|
|
294
|
-
* with one function.
|
|
404
|
+
* with one function. Throws on a payload that isn't well-formed protobuf.
|
|
295
405
|
*/
|
|
296
406
|
function decodeOtlpProtobuf(buf) {
|
|
297
|
-
|
|
298
|
-
return { resourceSpans: (ExportTraceServiceRequest.toObject(decoded, {
|
|
299
|
-
longs: String,
|
|
300
|
-
bytes: Array,
|
|
301
|
-
defaults: false,
|
|
302
|
-
oneofs: true
|
|
303
|
-
}).resourceSpans ?? []).map((rs) => ({
|
|
304
|
-
resource: rs.resource ? { attributes: (rs.resource.attributes ?? []).map(convertKeyValue) } : { attributes: [] },
|
|
305
|
-
scopeSpans: (rs.scopeSpans ?? []).map((ss) => ({
|
|
306
|
-
scope: ss.scope ? {
|
|
307
|
-
name: ss.scope.name ?? "",
|
|
308
|
-
version: ss.scope.version
|
|
309
|
-
} : void 0,
|
|
310
|
-
spans: (ss.spans ?? []).map(convertSpan)
|
|
311
|
-
}))
|
|
312
|
-
})) };
|
|
407
|
+
return { resourceSpans: decodeRepeated(decodeResourceSpans)(new Reader(buf)) };
|
|
313
408
|
}
|
|
314
409
|
//#endregion
|
|
315
410
|
//#region src/trace/span-merge.ts
|
|
@@ -368,14 +463,52 @@ const KNOWN_KINDS = [
|
|
|
368
463
|
];
|
|
369
464
|
/**
|
|
370
465
|
* Reads a span's {@link SpanKind} from its attributes: the explicit
|
|
371
|
-
* `evalution.span.type` attribute if present,
|
|
372
|
-
*
|
|
466
|
+
* `evalution.span.type` attribute if present, then Claude Code's
|
|
467
|
+
* `span.type: llm_request`, otherwise a mapping from the OTel GenAI semconv
|
|
468
|
+
* `gen_ai.operation.name`. Falls back to `'DEFAULT'`.
|
|
373
469
|
*/
|
|
374
470
|
function readKind(attributes) {
|
|
375
471
|
attributes = liftTelemetryMetadata(attributes);
|
|
376
|
-
const raw = attributes[SPAN_KIND_ATTRIBUTE] ?? otelOperationToSpanKind(attributes["gen_ai.operation.name"]);
|
|
472
|
+
const raw = attributes[SPAN_KIND_ATTRIBUTE] ?? (isClaudeCodeLLMRequest(attributes) ? "LLM" : otelOperationToSpanKind(attributes["gen_ai.operation.name"]));
|
|
377
473
|
return typeof raw === "string" && KNOWN_KINDS.includes(raw) ? raw : "DEFAULT";
|
|
378
474
|
}
|
|
475
|
+
/**
|
|
476
|
+
* Whether a span is a Claude Code model call, which it marks with
|
|
477
|
+
* `span.type: llm_request` rather than a `gen_ai.operation.name`.
|
|
478
|
+
*/
|
|
479
|
+
function isClaudeCodeLLMRequest(attributes) {
|
|
480
|
+
return attributes["span.type"] === "llm_request";
|
|
481
|
+
}
|
|
482
|
+
/**
|
|
483
|
+
* A Claude Code model call's token usage, from its own attribute names.
|
|
484
|
+
* Anthropic counts `input_tokens` apart from the cache reads and writes, so
|
|
485
|
+
* they're added back in to make `promptTokens` every input token, as
|
|
486
|
+
* {@link LLMSpanDetails} counts it. Read only off an `llm_request` span, as
|
|
487
|
+
* the bare names could mean anything elsewhere.
|
|
488
|
+
*/
|
|
489
|
+
function readClaudeCodeUsage(attributes) {
|
|
490
|
+
if (!isClaudeCodeLLMRequest(attributes)) return {};
|
|
491
|
+
const input = num(attributes.input_tokens);
|
|
492
|
+
const cacheReadTokens = num(attributes.cache_read_tokens);
|
|
493
|
+
const cacheWriteTokens = num(attributes.cache_creation_tokens);
|
|
494
|
+
return {
|
|
495
|
+
...input !== void 0 && { promptTokens: input + (cacheReadTokens ?? 0) + (cacheWriteTokens ?? 0) },
|
|
496
|
+
completionTokens: num(attributes.output_tokens),
|
|
497
|
+
cacheReadTokens,
|
|
498
|
+
cacheWriteTokens
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* The prompt that started a Claude Code interaction, recorded (when
|
|
503
|
+
* `OTEL_LOG_USER_PROMPTS` is set) as `user_prompt` on its `interaction` span.
|
|
504
|
+
*/
|
|
505
|
+
function readClaudeCodeUserPrompt(attributes) {
|
|
506
|
+
const prompt = str(attributes.user_prompt);
|
|
507
|
+
return attributes["span.type"] === "interaction" && prompt ? [{
|
|
508
|
+
role: "user",
|
|
509
|
+
content: prompt
|
|
510
|
+
}] : void 0;
|
|
511
|
+
}
|
|
379
512
|
/** Where the Vercel AI SDK (≤ v6) records `experimental_telemetry.metadata`. */
|
|
380
513
|
const TELEMETRY_METADATA_PREFIX = "ai.telemetry.metadata.";
|
|
381
514
|
/** The attributes evalution itself defines, which may arrive as metadata. */
|
|
@@ -593,14 +726,16 @@ function readLLM(attributes) {
|
|
|
593
726
|
const provider = str(attributes["gen_ai.provider.name"]) ?? str(attributes["gen_ai.system"]);
|
|
594
727
|
const model = str(attributes["gen_ai.response.model"]) ?? str(attributes["gen_ai.request.model"]);
|
|
595
728
|
const finishReason = readFinishReason(attributes);
|
|
596
|
-
const
|
|
597
|
-
const
|
|
598
|
-
const
|
|
599
|
-
const
|
|
729
|
+
const effort = isClaudeCodeLLMRequest(attributes) ? str(attributes.effort) : void 0;
|
|
730
|
+
const claudeCode = readClaudeCodeUsage(attributes);
|
|
731
|
+
const promptTokens = num(attributes["gen_ai.usage.input_tokens"]) ?? num(attributes["gen_ai.usage.prompt_tokens"]) ?? num(attributes["ai.usage.promptTokens"]) ?? claudeCode.promptTokens;
|
|
732
|
+
const completionTokens = num(attributes["gen_ai.usage.output_tokens"]) ?? num(attributes["gen_ai.usage.completion_tokens"]) ?? num(attributes["ai.usage.completionTokens"]) ?? claudeCode.completionTokens;
|
|
733
|
+
const cacheReadTokens = num(attributes["gen_ai.usage.cache_read.input_tokens"]) ?? claudeCode.cacheReadTokens;
|
|
734
|
+
const cacheWriteTokens = num(attributes["gen_ai.usage.cache_creation.input_tokens"]) ?? claudeCode.cacheWriteTokens;
|
|
600
735
|
const jsonInput = parseJsonObject(attributes["evalution.llm.input"]);
|
|
601
736
|
const messages = parseMessages(attributes["gen_ai.input.messages"] ?? attributes["ai.prompt.messages"]);
|
|
602
737
|
const evaluation = readEvaluation(attributes);
|
|
603
|
-
const input = jsonInput ?? evaluation.input ?? messages;
|
|
738
|
+
const input = jsonInput ?? evaluation.input ?? messages ?? readClaudeCodeUserPrompt(attributes);
|
|
604
739
|
const jsonOutput = tryParseJson(attributes["evalution.llm.output"]) ?? evaluation.output;
|
|
605
740
|
const text = parseOutput(attributes["gen_ai.output.messages"]) ?? str(attributes["ai.response.text"]);
|
|
606
741
|
const toolCalls = readOutputToolCalls(attributes);
|
|
@@ -609,11 +744,12 @@ function readLLM(attributes) {
|
|
|
609
744
|
const paramEntries = PARAM_ATTRIBUTES.map((key) => [key.replace("gen_ai.request.", ""), attributes[key]]).filter(([, v]) => v !== void 0);
|
|
610
745
|
const modelParameters = paramEntries.length > 0 ? Object.fromEntries(paramEntries) : void 0;
|
|
611
746
|
const totalTokens = promptTokens !== void 0 && completionTokens !== void 0 ? promptTokens + completionTokens : void 0;
|
|
612
|
-
if (!provider && !model && !finishReason && !promptTokens && !completionTokens && !input && (output === void 0 || output === "") && !reasoning && !modelParameters) return;
|
|
747
|
+
if (!provider && !model && !finishReason && !effort && !promptTokens && !completionTokens && !input && (output === void 0 || output === "") && !reasoning && !modelParameters) return;
|
|
613
748
|
return {
|
|
614
749
|
...provider && { provider },
|
|
615
750
|
...model && { model },
|
|
616
751
|
...finishReason && { finishReason },
|
|
752
|
+
...effort && { effort },
|
|
617
753
|
...input && { input },
|
|
618
754
|
...output !== void 0 && output !== "" && { output },
|
|
619
755
|
...reasoning && { reasoning },
|
|
@@ -43,7 +43,7 @@ declare function normalizeOtlpRequest(body: Raw): NormalizedOtlpSpan[];
|
|
|
43
43
|
* Decodes an OTLP/protobuf `ExportTraceServiceRequest` payload into the same
|
|
44
44
|
* plain-object shape as the OTLP/JSON encoding (camelCase keys, hex trace/span
|
|
45
45
|
* ids, stringified 64-bit values) — so `../otlp/normalize.ts` can walk either
|
|
46
|
-
* with one function.
|
|
46
|
+
* with one function. Throws on a payload that isn't well-formed protobuf.
|
|
47
47
|
*/
|
|
48
48
|
declare function decodeOtlpProtobuf(buf: Uint8Array): {
|
|
49
49
|
resourceSpans: any[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "evalution",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
4
4
|
"description": "TypeScript AI Prompt Playground - Edit and execute AI prompts with live preview",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"exports": {
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"node": ">=22.18.0"
|
|
44
44
|
},
|
|
45
45
|
"dependencies": {
|
|
46
|
-
"@evalution/sdk": "2.0.
|
|
46
|
+
"@evalution/sdk": "2.0.5",
|
|
47
47
|
"@hono/node-server": "^2.0.4",
|
|
48
48
|
"@lydell/node-pty": "^1.2.0-beta.12",
|
|
49
49
|
"@modelcontextprotocol/client": "^2.2.0",
|
|
@@ -60,7 +60,6 @@
|
|
|
60
60
|
"esbuild": "^0.21.5",
|
|
61
61
|
"hono": "^4.12.23",
|
|
62
62
|
"minimatch": "^10.2.4",
|
|
63
|
-
"protobufjs": "^7.5.3",
|
|
64
63
|
"remark-breaks": "^4.0.0",
|
|
65
64
|
"ts-proppy": "0.3.3",
|
|
66
65
|
"ws": "^8.21.0",
|
|
@@ -98,9 +97,9 @@
|
|
|
98
97
|
"@ai-sdk/openai": "^4.0.73",
|
|
99
98
|
"@ai-sdk/typesafe-ai": "^3.0.5",
|
|
100
99
|
"@biomejs/biome": "^2.5.0",
|
|
101
|
-
"@evalution/gemini-interactions-sdk": "2.0.
|
|
102
|
-
"@evalution/typesafe-sdk": "2.0.
|
|
103
|
-
"@evalution/vercel-ai-sdk": "2.0.
|
|
100
|
+
"@evalution/gemini-interactions-sdk": "2.0.5",
|
|
101
|
+
"@evalution/typesafe-sdk": "2.0.5",
|
|
102
|
+
"@evalution/vercel-ai-sdk": "2.0.5",
|
|
104
103
|
"@glideapps/glide-data-grid": "6.0.4-alpha24",
|
|
105
104
|
"@google/genai": "^2.9.0",
|
|
106
105
|
"@playwright/experimental-ct-react": "^1.58.2",
|
|
@@ -119,6 +118,7 @@
|
|
|
119
118
|
"concurrently": "^9.2.1",
|
|
120
119
|
"drizzle-kit": "1.0.0-rc.4",
|
|
121
120
|
"lucide-react": "^1.43.0",
|
|
121
|
+
"protobufjs": "^7.6.4",
|
|
122
122
|
"react": "^19.2.0",
|
|
123
123
|
"react-dom": "^19.2.0",
|
|
124
124
|
"streamdown": "^2.6.0",
|