evalution 2.0.4 → 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.
@@ -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 ExportTraceServiceRequest = protobuf.parse(`
150
- syntax = "proto3";
151
- package otlp;
152
-
153
- message AnyValue {
154
- oneof value {
155
- string string_value = 1;
156
- bool bool_value = 2;
157
- int64 int_value = 3;
158
- double double_value = 4;
159
- ArrayValue array_value = 5;
160
- KeyValueList kvlist_value = 6;
161
- bytes bytes_value = 7;
162
- }
163
- }
164
- message ArrayValue { repeated AnyValue values = 1; }
165
- message KeyValueList { repeated KeyValue values = 1; }
166
- message KeyValue { string key = 1; AnyValue value = 2; }
167
- message InstrumentationScope {
168
- string name = 1;
169
- string version = 2;
170
- repeated KeyValue attributes = 3;
171
- uint32 dropped_attributes_count = 4;
172
- }
173
- message Resource {
174
- repeated KeyValue attributes = 1;
175
- uint32 dropped_attributes_count = 2;
176
- }
177
- message Status {
178
- reserved 1;
179
- string message = 2;
180
- enum StatusCode {
181
- STATUS_CODE_UNSET = 0;
182
- STATUS_CODE_OK = 1;
183
- STATUS_CODE_ERROR = 2;
184
- }
185
- StatusCode code = 3;
186
- }
187
- message Span {
188
- bytes trace_id = 1;
189
- bytes span_id = 2;
190
- string trace_state = 3;
191
- bytes parent_span_id = 4;
192
- fixed32 flags = 16;
193
- string name = 5;
194
- enum SpanKind {
195
- SPAN_KIND_UNSPECIFIED = 0;
196
- SPAN_KIND_INTERNAL = 1;
197
- SPAN_KIND_SERVER = 2;
198
- SPAN_KIND_CLIENT = 3;
199
- SPAN_KIND_PRODUCER = 4;
200
- SPAN_KIND_CONSUMER = 5;
201
- }
202
- SpanKind kind = 6;
203
- fixed64 start_time_unix_nano = 7;
204
- fixed64 end_time_unix_nano = 8;
205
- repeated KeyValue attributes = 9;
206
- uint32 dropped_attributes_count = 10;
207
- repeated Event events = 11;
208
- uint32 dropped_events_count = 12;
209
- repeated Link links = 13;
210
- uint32 dropped_links_count = 14;
211
- Status status = 15;
212
- message Event {
213
- fixed64 time_unix_nano = 1;
214
- string name = 2;
215
- repeated KeyValue attributes = 3;
216
- uint32 dropped_attributes_count = 4;
217
- }
218
- message Link {
219
- bytes trace_id = 1;
220
- bytes span_id = 2;
221
- string trace_state = 3;
222
- repeated KeyValue attributes = 4;
223
- uint32 dropped_attributes_count = 5;
224
- fixed32 flags = 6;
225
- }
226
- }
227
- message ScopeSpans {
228
- InstrumentationScope scope = 1;
229
- repeated Span spans = 2;
230
- string schema_url = 3;
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 convertAnyValue(v) {
248
- if (v == null) return void 0;
249
- if (v.stringValue !== void 0 || v.value === "stringValue") return { stringValue: v.stringValue ?? "" };
250
- if (v.boolValue !== void 0 || v.value === "boolValue") return { boolValue: v.boolValue ?? false };
251
- if (v.intValue !== void 0 || v.value === "intValue") return { intValue: String(v.intValue ?? 0) };
252
- if (v.doubleValue !== void 0 || v.value === "doubleValue") return { doubleValue: v.doubleValue ?? 0 };
253
- if (v.bytesValue !== void 0 || v.value === "bytesValue") return { stringValue: bytesToHex(v.bytesValue) ?? "" };
254
- if (v.arrayValue !== void 0 || v.value === "arrayValue") return { arrayValue: { values: (v.arrayValue?.values ?? []).map(convertAnyValue) } };
255
- if (v.kvlistValue !== void 0 || v.value === "kvlistValue") return { kvlistValue: { values: (v.kvlistValue?.values ?? []).map(convertKeyValue) } };
256
- }
257
- function convertKeyValue(kv) {
258
- return {
259
- key: kv.key ?? "",
260
- value: convertAnyValue(kv.value)
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 convertSpan(s) {
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
- traceId: bytesToHex(s.traceId) ?? "",
266
- spanId: bytesToHex(s.spanId) ?? "",
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
- const decoded = ExportTraceServiceRequest.decode(buf);
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
@@ -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.4",
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.4",
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.4",
102
- "@evalution/typesafe-sdk": "2.0.4",
103
- "@evalution/vercel-ai-sdk": "2.0.4",
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",