evalution 1.0.6 → 1.0.8

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.
Files changed (25) hide show
  1. package/LICENSING.md +1 -0
  2. package/dist/{check-BTg6THHB.d.ts → check-CR4fU1S5.d.ts} +43 -15
  3. package/dist/checks/index.d.ts +1 -1
  4. package/dist/cli/index.js +116 -69
  5. package/dist/client/assets/DatasetView-BqSWI_pm.js +15 -0
  6. package/dist/client/assets/EvalRunView-CR6ZksSu.js +2 -0
  7. package/dist/client/assets/EvalView-JPEM5IY8.js +1 -0
  8. package/dist/client/assets/{data-grid-overlay-editor-CBtkQufd.js → data-grid-overlay-editor-B_nPhXKR.js} +1 -1
  9. package/dist/client/assets/{highlighted-body-KPVGNVTW-DyudWmoO.js → highlighted-body-KPVGNVTW-dPpneB8R.js} +1 -1
  10. package/dist/client/assets/{index-B7OFMd2c.css → index-BGcZZetP.css} +1 -1
  11. package/dist/client/assets/{index-aypgoZcG.js → index-CwjMcK6S.js} +150 -150
  12. package/dist/client/assets/{number-overlay-editor-CXHiTLsp.js → number-overlay-editor-CRWFlaQs.js} +1 -1
  13. package/dist/client/index.html +2 -2
  14. package/dist/{dataset-types-CSjbM_Vz.d.ts → dataset-types-Dqi5vVg-.d.ts} +20 -5
  15. package/dist/index.d.ts +169 -9
  16. package/dist/index.js +24 -13
  17. package/dist/{trace-Dn6Pfcc5.d.ts → trace-DGj5oW7z.d.ts} +1 -1
  18. package/dist/{otlp-trace-ingestor-V8_bbpUG.js → trace-event-ingestor-BghQcCHe.js} +566 -75
  19. package/dist/views/datasets/index.d.ts +1 -1
  20. package/dist/views/index.d.ts +2 -2
  21. package/dist/views/react/index.d.ts +1 -1
  22. package/package.json +2 -2
  23. package/dist/client/assets/DatasetView-CyX0mCj8.js +0 -15
  24. package/dist/client/assets/EvalRunView-5IZp_6Ob.js +0 -2
  25. package/dist/client/assets/EvalView-DBTK6rCe.js +0 -1
package/LICENSING.md CHANGED
@@ -58,6 +58,7 @@ permissively licensed code:
58
58
  [`src/trace/trace-types.ts`](./src/trace/trace-types.ts),
59
59
  [`src/trace/trace-sink.ts`](./src/trace/trace-sink.ts),
60
60
  [`src/trace/trace-ingestor.ts`](./src/trace/trace-ingestor.ts),
61
+ [`src/trace/http-trace-sink.ts`](./src/trace/http-trace-sink.ts),
61
62
  [`src/trace/evaluation-answers.ts`](./src/trace/evaluation-answers.ts), and
62
63
  [`src/sdk/vercel-ai-sdk/telemetry.ts`](./src/sdk/vercel-ai-sdk/telemetry.ts).
63
64
  Each is **dual-licensed `MIT OR AGPL-3.0-only`** (see its SPDX header),
@@ -107,9 +107,19 @@ interface SpanToolResultPart {
107
107
  /** Whether the result reports a failure (an error, or a denied call). */
108
108
  isError?: boolean;
109
109
  }
110
+ /**
111
+ * The reasoning (thinking) a model produced ahead of its answer, within a
112
+ * multi-part {@link SpanMessage} content — how a conversation's earlier
113
+ * assistant turns carry theirs. The turn a span records keeps its own in
114
+ * {@link LLMSpanDetails.reasoning}.
115
+ */
116
+ interface SpanReasoningPart {
117
+ type: "reasoning";
118
+ text: string;
119
+ }
110
120
  type SpanMessageRole = "user" | "assistant" | "system" | "tool" | (string & {});
111
121
  /** One segment of a multi-part {@link SpanMessage} content. */
112
- type SpanContentPart = SpanTextPart | SpanImagePart | SpanToolCallPart | SpanToolResultPart;
122
+ type SpanContentPart = SpanTextPart | SpanImagePart | SpanToolCallPart | SpanToolResultPart | SpanReasoningPart;
113
123
  /**
114
124
  * A single message within an LLM span's input/output.
115
125
  *
@@ -148,6 +158,11 @@ interface LLMSpanDetails {
148
158
  * output and for any model whose answer is data rather than prose.
149
159
  */
150
160
  output?: unknown;
161
+ /**
162
+ * The reasoning the model produced on the way to {@link output}, kept apart
163
+ * from it so an output stays the answer that checks and agents read.
164
+ */
165
+ reasoning?: string;
151
166
  /** Input tokens, counting any read from or written to a prompt cache. */
152
167
  promptTokens?: number;
153
168
  completionTokens?: number;
@@ -276,6 +291,20 @@ interface TraceSummary extends TraceBase {
276
291
  * and the runs in flight.
277
292
  */
278
293
  evalRun?: TraceEvalRun;
294
+ /**
295
+ * How the checks recorded against the trace break down, once it has any.
296
+ * Filled in by the server alongside {@link TraceSummary.evalRun}.
297
+ */
298
+ checkCounts?: EvalCounts;
299
+ }
300
+ /** How a run's, or a trace's, check results break down. */
301
+ interface EvalCounts {
302
+ pass: number;
303
+ fail: number;
304
+ error: number;
305
+ skipped: number;
306
+ /** Scores reported without a threshold, so neither pass nor fail. */
307
+ scored: number;
279
308
  }
280
309
  /** The eval run a trace came from — what the trace list groups by. */
281
310
  interface TraceEvalRun {
@@ -287,6 +316,10 @@ interface TraceEvalRun {
287
316
  runId: string;
288
317
  /** When the run started (ms). */
289
318
  startedAt: number;
319
+ /** The arm of the run that produced the trace. */
320
+ armId: string;
321
+ /** That arm's label: the version it ran, as the run view names it. */
322
+ armLabel: string;
290
323
  }
291
324
  /**
292
325
  * The OpenTelemetry semantic-convention resource attribute naming the
@@ -470,15 +503,6 @@ interface EvalArm {
470
503
  }
471
504
  /** A run's lifecycle. */
472
505
  type EvalRunStatus = "running" | "done" | "cancelled" | "error";
473
- /** How a run's check results break down. */
474
- interface EvalCounts {
475
- pass: number;
476
- fail: number;
477
- error: number;
478
- skipped: number;
479
- /** Scores reported without a threshold, so neither pass nor fail. */
480
- scored: number;
481
- }
482
506
  /** What `EvalProvider.createRun` takes. */
483
507
  interface NewEvalRun {
484
508
  /** The eval as it was when the run started — runs keep meaning what they measured. */
@@ -600,11 +624,15 @@ interface TraceCheckResult extends EvalCheckResult {
600
624
  /** The check's label as the run's definition had it. */
601
625
  checkLabel: string;
602
626
  armLabel: string;
627
+ /** When the run started (ms). */
628
+ startedAt: number;
603
629
  }
604
630
  /** A trace an eval run produced, with the run — see `EvalProvider.listTraceRuns`. */
605
631
  interface EvalTraceRun extends Omit<TraceEvalRun, "providerId"> {
606
632
  traceProviderId: string;
607
633
  traceId: string;
634
+ /** How the trace's check results break down, once it has any. */
635
+ checkCounts?: EvalCounts;
608
636
  }
609
637
  /** The kind of change an {@link EvalChangeEvent} describes. */
610
638
  type EvalChangeType = "add" | "update" | "remove";
@@ -1362,10 +1390,10 @@ interface DatasetField {
1362
1390
  /** Name, type, description — the checker's view of the slot this field came from. */
1363
1391
  def: PropDefinition$1;
1364
1392
  /**
1365
- * Set on a field added by hand (`DatasetProvider.addField`) rather than
1366
- * derived when the dataset was created. Such a field never came from the
1367
- * linked prompt, so it isn't flagged when it matches none of its
1368
- * parameters.
1393
+ * Set on a field added by hand — through `DatasetProvider.addField`, or
1394
+ * given as `{ name, type }` or `{ from }` when the dataset was created —
1395
+ * rather than derived from the linked prompt. Such a field never came from
1396
+ * that prompt, so it isn't flagged when it matches none of its parameters.
1369
1397
  */
1370
1398
  added?: true;
1371
1399
  }
@@ -1922,4 +1950,4 @@ declare function check<const N extends ResourceInputs = Record<string, never>>(d
1922
1950
  /** Whether `value` was produced by {@link check}. */
1923
1951
  declare function isCheck(value: unknown): value is Check;
1924
1952
  //#endregion
1925
- export { NormalizedPromptBase as $, TraceCheckResult as $t, DatasetRowsOverview as A, TraceWithSpans as An, EvalArm as At, ChatPromptUpdates as B, EvalInputs as Bt, DatasetFieldShape as C, TraceChangeEvent as Cn, ValueCatalogPreset as Ct, DatasetRow as D, TraceProviderInfo as Dn, VariationInfo as Dt, DatasetProviderInfo as E, TraceLiveEvent as En, VariationId as Et, KnownColumnSpec as F, EvalCheckOutcome as Ft, ExecutionInput as G, EvalRun as Gt, ConflictChoices as H, EvalResults as Ht, AddPromptContext as I, EvalCheckResult as It, InputLayout as J, EvalRunSummary as Jt, ExtractedProps as K, EvalRunProgress as Kt, AddPromptField as L, EvalCounts as Lt, ColumnPath as M, spanMessages as Mn, EvalChangeEvent as Mt, DatasetColumnSpec as N, EvalChangeType as Nt, DatasetRowSource as O, TraceStreamEvent as On, VersionId as Ot, ForeignColumnSpec as P, EvalCheck as Pt, NormalizedPrompt as Q, NewEvalRun as Qt, CalleeBinding as R, EvalDefinition as Rt, DatasetField as S, Trace as Sn, ValueCatalogGroup as St, DatasetPathChild as T, TraceEvalRun as Tn, VariationConflict as Tt, ExecuteRequest as U, EvalRowResult as Ut, CheckInfo as V, EvalProviderInfo as Vt, ExecuteResponse as W, EvalRowStatus as Wt, NormalizedMessage as X, EvalTraceRun as Xt, NormalizedChatPrompt as Y, EvalSummary as Yt, NormalizedParameter as Z, NewEvalDefinition as Zt, isStandardSchema as _, SpanMessageRole as _n, ResourceScope as _t, check as a, AnnotationSource as an, PromptChangeEvent as at, DatasetChangeEvent as b, SpanToolResultPart as bn, UpdatePromptResponse as bt, ResolvedResourceInputs as c, LLMSpanDetails as cn, PromptRef as ct, ResourceInput as d, SERVICE_NAME_ATTRIBUTE as dn, PropType as dt, Annotation as en, NormalizedPromptUpdates as et, ResourceInputs as f, Span as fn, PropValue$1 as ft, isResource as g, SpanMessage as gn, ResourceInstanceInput as gt, StaticResourceDefinition as h, SpanKind as hn, ResourceInfo as ht, CheckRun as i, AnnotationKind as in, PendingConflicts as it, DatasetSummary as j, isCheckSpan as jn, EvalArmSpec as jt, DatasetRowUpdate as k, TraceSummary as kn, VersionInfo as kt, Resource as l, PLAYGROUND_ENVIRONMENT as ln, PromptStyle as lt, ResourceOutputDefinition as m, SpanImagePart as mn, RebaseResult as mt, CheckDefinition as n, AnnotationEvent as nn, NormalizedToolCall as nt, isCheck as o, CHECK_ATTRIBUTE as on, PromptInputSources as ot, ResourceInstance as p, SpanContentPart as pn, QuestionsPromptUpdates as pt, FieldValues as q, EvalRunStatus as qt, CheckOutcome as r, AnnotationEventOp as rn, ParsedPrompt as rt, DynamicResourceDefinition as s, DEPLOYMENT_ENVIRONMENT_ATTRIBUTE as sn, PromptProviderInfo as st, Check as t, AnnotationChanges as tn, NormalizedQuestionsPrompt as tt, ResourceDefinition as u, PromptID as un, PropDefinition$1 as ut, resource as v, SpanTextPart as vn, RunResources as vt, DatasetInstanceShape as w, TraceChangeType as wn, ValueFactory$1 as wt, DatasetChangeType as x, ToolSpanDetails as xn, ValueCatalog as xt, Dataset as y, SpanToolCallPart as yn, SourceSpan as yt, ChangeEventType as z, EvalDefinitionPatch as zt };
1953
+ export { NormalizedPromptBase as $, Annotation as $t, DatasetRowsOverview as A, TraceSummary as An, EvalArm as At, ChatPromptUpdates as B, EvalProviderInfo as Bt, DatasetFieldShape as C, Trace as Cn, ValueCatalogPreset as Ct, DatasetRow as D, TraceLiveEvent as Dn, VariationInfo as Dt, DatasetProviderInfo as E, TraceEvalRun as En, VariationId as Et, KnownColumnSpec as F, EvalCheckOutcome as Ft, ExecutionInput as G, EvalRunProgress as Gt, ConflictChoices as H, EvalRowResult as Ht, AddPromptContext as I, EvalCheckResult as It, InputLayout as J, EvalSummary as Jt, ExtractedProps as K, EvalRunStatus as Kt, AddPromptField as L, EvalDefinition as Lt, ColumnPath as M, isCheckSpan as Mn, EvalChangeEvent as Mt, DatasetColumnSpec as N, spanMessages as Nn, EvalChangeType as Nt, DatasetRowSource as O, TraceProviderInfo as On, VersionId as Ot, ForeignColumnSpec as P, EvalCheck as Pt, NormalizedPrompt as Q, TraceCheckResult as Qt, CalleeBinding as R, EvalDefinitionPatch as Rt, DatasetField as S, ToolSpanDetails as Sn, ValueCatalogGroup as St, DatasetPathChild as T, TraceChangeType as Tn, VariationConflict as Tt, ExecuteRequest as U, EvalRowStatus as Ut, CheckInfo as V, EvalResults as Vt, ExecuteResponse as W, EvalRun as Wt, NormalizedMessage as X, NewEvalDefinition as Xt, NormalizedChatPrompt as Y, EvalTraceRun as Yt, NormalizedParameter as Z, NewEvalRun as Zt, isStandardSchema as _, SpanMessageRole as _n, ResourceScope as _t, check as a, CHECK_ATTRIBUTE as an, PromptChangeEvent as at, DatasetChangeEvent as b, SpanToolCallPart as bn, UpdatePromptResponse as bt, ResolvedResourceInputs as c, LLMSpanDetails as cn, PromptRef as ct, ResourceInput as d, SERVICE_NAME_ATTRIBUTE as dn, PropType as dt, AnnotationChanges as en, NormalizedPromptUpdates as et, ResourceInputs as f, Span as fn, PropValue$1 as ft, isResource as g, SpanMessage as gn, ResourceInstanceInput as gt, StaticResourceDefinition as h, SpanKind as hn, ResourceInfo as ht, CheckRun as i, AnnotationSource as in, PendingConflicts as it, DatasetSummary as j, TraceWithSpans as jn, EvalArmSpec as jt, DatasetRowUpdate as k, TraceStreamEvent as kn, VersionInfo as kt, Resource as l, PLAYGROUND_ENVIRONMENT as ln, PromptStyle as lt, ResourceOutputDefinition as m, SpanImagePart as mn, RebaseResult as mt, CheckDefinition as n, AnnotationEventOp as nn, NormalizedToolCall as nt, isCheck as o, DEPLOYMENT_ENVIRONMENT_ATTRIBUTE as on, PromptInputSources as ot, ResourceInstance as p, SpanContentPart as pn, QuestionsPromptUpdates as pt, FieldValues as q, EvalRunSummary as qt, CheckOutcome as r, AnnotationKind as rn, ParsedPrompt as rt, DynamicResourceDefinition as s, EvalCounts as sn, PromptProviderInfo as st, Check as t, AnnotationEvent as tn, NormalizedQuestionsPrompt as tt, ResourceDefinition as u, PromptID as un, PropDefinition$1 as ut, resource as v, SpanReasoningPart as vn, RunResources as vt, DatasetInstanceShape as w, TraceChangeEvent as wn, ValueFactory$1 as wt, DatasetChangeType as x, SpanToolResultPart as xn, ValueCatalog as xt, Dataset as y, SpanTextPart as yn, SourceSpan as yt, ChangeEventType as z, EvalInputs as zt };
@@ -1,4 +1,4 @@
1
- import { An as TraceWithSpans, V as CheckInfo, i as CheckRun, t as Check } from "../check-BTg6THHB.js";
1
+ import { V as CheckInfo, i as CheckRun, jn as TraceWithSpans, t as Check } from "../check-CR4fU1S5.js";
2
2
  import { StandardSchemaV1 } from "@standard-schema/spec";
3
3
 
4
4
  //#region src/checks/index.d.ts
package/dist/cli/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { $ as isPrimitiveFieldType, $t as CONFIG_FILE_RELATIVE_PATH, A as SqlQueryError, B as EvalRunRefusedError, D as EvalNotFoundError, E as normalizeOtlpRequest, Et as isPromptStyle, F as pathField, G as InvalidCellError, H as emptyCounts, I as pathInstance, J as parseCell, K as fitsPrimitiveBase, L as DatasetNotFoundError, M as isPathColumn, Mt as PLAYGROUND_RESOURCE, N as parseColumnPath, Ot as TypeSafeSDK, P as parseColumnSpecs, Q as fieldsForPrompt, R as DatasetValidationError, S as VariationConflictError, T as decodeOtlpProtobuf, Tt as isNonEmptyStringArray, U as CheckScopeTraceSink, V as EvalRunner, W as evalProblems, X as primitiveBase, Y as parseResources, Z as PRIMITIVE_FIELD_TYPES, b as rollupSpans, bt as VercelAISDK, c as LocalEvalProvider, en as setupStepCommand, et as portableDef, f as LocalDirectoryDatasetProvider, j as InvalidColumnPathError, k as DEFAULT_QUERY_TIMEOUT_MS, n as LocalDatabaseTraceProvider, nt as runPrompt, o as isTraceSink, q as parseBinding, rn as registerVariationLoaderHook, t as OtlpTraceIngestor, tn as LocalFileProvider, tt as InputResolutionError, ut as instanceNames, x as datasetQueryColumns, y as mkdirSelfIgnoring } from "../otlp-trace-ingestor-V8_bbpUG.js";
1
+ import { $ as fieldsForPrompt, A as DEFAULT_QUERY_TIMEOUT_MS, At as isPromptStyle, C as VariationConflictError, D as normalizeOtlpRequest, E as decodeOtlpProtobuf, F as parseColumnSpecs, G as evalProblems, H as EvalRunner, I as pathField, It as PLAYGROUND_RESOURCE, J as parseBinding, K as InvalidCellError, L as pathInstance, M as InvalidColumnPathError, Mt as TypeSafeSDK, N as isPathColumn, O as EvalNotFoundError, P as parseColumnPath, Q as PRIMITIVE_FIELD_TYPES, R as DatasetNotFoundError, S as datasetQueryColumns, Tt as TRACE_EVENTS_PATH, U as emptyCounts, V as EvalRunRefusedError, W as CheckScopeTraceSink, X as parseResources, Y as parseCell, Z as primitiveBase, an as LocalFileProvider, b as mkdirSelfIgnoring, dt as instanceNames, et as isPrimitiveFieldType, in as setupStepCommand, j as SqlQueryError, kt as isNonEmptyStringArray, l as LocalEvalProvider, ln as registerFreshImportHook, n as OtlpTraceIngestor, nt as InputResolutionError, p as LocalDirectoryDatasetProvider, q as fitsPrimitiveBase, r as LocalDatabaseTraceProvider, rn as CONFIG_FILE_RELATIVE_PATH, rt as runPrompt, s as isTraceSink, sn as registerVariationLoaderHook, t as TraceEventIngestor, tt as portableDef, un as registerBundlerResolutionFallback, x as rollupSpans, yt as VercelAISDK, z as DatasetValidationError } from "../trace-event-ingestor-BghQcCHe.js";
2
2
  import { r as builtinCheckInfos } from "../checks-Cq97JU-h.js";
3
3
  import module, { builtinModules } from "node:module";
4
4
  import path, { join, resolve } from "node:path";
@@ -10,8 +10,8 @@ import { Hono } from "hono";
10
10
  import { WebSocketServer } from "ws";
11
11
  import fs, { link, readFile, rename, stat, unlink, writeFile } from "node:fs/promises";
12
12
  import chokidar from "chokidar";
13
- import { createHash } from "node:crypto";
14
13
  import fs$1, { readFileSync, unlinkSync } from "node:fs";
14
+ import { createHash } from "node:crypto";
15
15
  import { trace } from "@opentelemetry/api";
16
16
  import { valueToSourceText } from "ts-proppy";
17
17
  import ts from "typescript";
@@ -23,7 +23,7 @@ import { StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
23
23
  import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
24
24
  import { spawn } from "node:child_process";
25
25
  //#region package.json
26
- var version = "1.0.6";
26
+ var version = "1.0.8";
27
27
  //#endregion
28
28
  //#region src/agent/command-builder.ts
29
29
  /** Characters an argument may consist of to be left unquoted. */
@@ -889,7 +889,8 @@ async function parseFields(value, lookupPrompt) {
889
889
  for (const [i, field] of value.entries()) {
890
890
  const def = isRecord$1(field) ? field.def : void 0;
891
891
  let parsed;
892
- if (def === void 0 && lookupPrompt && isRecord$1(field)) try {
892
+ const byHand = def === void 0 && !!lookupPrompt && isRecord$1(field);
893
+ if (byHand) try {
893
894
  parsed = await parseNewField(field, lookupPrompt);
894
895
  } catch (err) {
895
896
  throw err instanceof BadRequest$1 ? new BadRequest$1(`fields[${i}]: ${err.message}`) : err;
@@ -899,7 +900,10 @@ async function parseFields(value, lookupPrompt) {
899
900
  const key = `${parsed.name}\u0000${parsed.type.syntax}`;
900
901
  if (seen.has(key)) throw new BadRequest$1(`fields[${i}] duplicates "${parsed.name}: ${parsed.type.syntax}"`);
901
902
  seen.add(key);
902
- fields.push({ def: parsed });
903
+ fields.push({
904
+ def: parsed,
905
+ ...byHand && { added: true }
906
+ });
903
907
  }
904
908
  return fields;
905
909
  }
@@ -1860,6 +1864,59 @@ function summarizePrompt(provider, prompt) {
1860
1864
  };
1861
1865
  }
1862
1866
  //#endregion
1867
+ //#region src/server/handlers/trace-events-ingest.ts
1868
+ function isObject(value) {
1869
+ return typeof value === "object" && value !== null;
1870
+ }
1871
+ function isSpanLike(value) {
1872
+ return isObject(value) && typeof value.id === "string" && typeof value.traceId === "string" && typeof value.startTime === "number";
1873
+ }
1874
+ /** Whether `value` is a {@link TraceSinkEvent} the ingestor can replay. */
1875
+ function isTraceSinkEvent(value) {
1876
+ if (!isObject(value)) return false;
1877
+ switch (value.type) {
1878
+ case "span-start":
1879
+ case "span-end": return isSpanLike(value.span);
1880
+ case "trace-fail": return typeof value.traceId === "string" && typeof value.errorMessage === "string";
1881
+ default: return false;
1882
+ }
1883
+ }
1884
+ /**
1885
+ * Host-neutral handler for a batch of trace events an app's `HttpTraceSink`
1886
+ * sends (`POST /api/traces`). Takes the request body as text and
1887
+ * returns plain `{status, body}`, like `handleOtlpTraces`, so it stays usable
1888
+ * from Hono, a Worker, or a test.
1889
+ */
1890
+ async function handleTraceEvents(body, ingestor) {
1891
+ let events;
1892
+ try {
1893
+ events = JSON.parse(body)?.events;
1894
+ } catch (err) {
1895
+ return {
1896
+ status: 400,
1897
+ body: { error: `Malformed JSON: ${err?.message ?? err}` }
1898
+ };
1899
+ }
1900
+ if (!Array.isArray(events)) return {
1901
+ status: 400,
1902
+ body: { error: "Expected an `events` array" }
1903
+ };
1904
+ const invalid = events.findIndex((e) => !isTraceSinkEvent(e));
1905
+ if (invalid >= 0) return {
1906
+ status: 400,
1907
+ body: { error: `Malformed event at ${invalid}` }
1908
+ };
1909
+ if (!ingestor) return {
1910
+ status: 404,
1911
+ body: { error: "No trace ingestor available for this request" }
1912
+ };
1913
+ await ingestor.ingest(events);
1914
+ return {
1915
+ status: 200,
1916
+ body: {}
1917
+ };
1918
+ }
1919
+ //#endregion
1863
1920
  //#region src/server/handlers/trace-stream.ts
1864
1921
  /**
1865
1922
  * Streams live updates for one trace over SSE: replays its current state
@@ -1910,11 +1967,18 @@ const QUERY_UNSUPPORTED = errorResult(405, "This trace provider does not support
1910
1967
  /**
1911
1968
  * Each trace an eval run produced, keyed `traceProviderId:traceId`. Never
1912
1969
  * throws: a provider that can't answer just leaves its traces ungrouped.
1970
+ * A run in flight only knows its traces, so what's recorded of their checks
1971
+ * survives it being added after the providers.
1913
1972
  */
1914
1973
  async function traceEvalRuns(sources) {
1915
1974
  const found = /* @__PURE__ */ new Map();
1916
- const add = ({ traceProviderId, traceId, ...run }) => {
1917
- found.set(`${traceProviderId}:${traceId}`, run);
1975
+ const add = ({ traceProviderId, traceId, checkCounts, ...evalRun }) => {
1976
+ const key = `${traceProviderId}:${traceId}`;
1977
+ const counts = checkCounts ?? found.get(key)?.checkCounts;
1978
+ found.set(key, {
1979
+ evalRun,
1980
+ ...counts && { checkCounts: counts }
1981
+ });
1918
1982
  };
1919
1983
  await Promise.all(Array.from(sources.providers, async (provider) => {
1920
1984
  try {
@@ -1932,7 +1996,7 @@ async function traceEvalRuns(sources) {
1932
1996
  /**
1933
1997
  * `GET /api/traces` — summaries of every trace across `providers`, per
1934
1998
  * provider newest first. With `evals`, each trace an eval run produced
1935
- * carries its `evalRun`.
1999
+ * carries its `evalRun` and `checkCounts`.
1936
2000
  */
1937
2001
  async function handleListTraces(providers, evals) {
1938
2002
  try {
@@ -1944,13 +2008,10 @@ async function handleListTraces(providers, evals) {
1944
2008
  };
1945
2009
  return {
1946
2010
  status: 200,
1947
- body: traces.map((trace) => {
1948
- const evalRun = evalRuns.get(`${trace.providerId}:${trace.id}`);
1949
- return evalRun ? {
1950
- ...trace,
1951
- evalRun
1952
- } : trace;
1953
- })
2011
+ body: traces.map((trace) => ({
2012
+ ...trace,
2013
+ ...evalRuns.get(`${trace.providerId}:${trace.id}`)
2014
+ }))
1954
2015
  };
1955
2016
  } catch (error) {
1956
2017
  return errorResult(500, error.message);
@@ -2118,7 +2179,7 @@ function errorResponse(c, error, status) {
2118
2179
  * Registers every REST route on `app`, answering through the neutral handlers
2119
2180
  * in `./handlers/` from `context` — which a host can serve over MCP too.
2120
2181
  */
2121
- function setupRoutes({ app, context, hotReloadSubscribers, hasConfig, setupTasks, agents, otlpIngestor, views }) {
2182
+ function setupRoutes({ app, context, hotReloadSubscribers, hasConfig, setupTasks, agents, otlpIngestor, traceEventIngestor, views }) {
2122
2183
  const { promptProviders, traceProviders, datasetProviders, rootPath, resolveSpanPrompt, resolvePromptLink } = context;
2123
2184
  mountConfigRoute(app, rootPath, hasConfig);
2124
2185
  app.get("/api/setup-tasks", (c) => c.json(setupTasks ? setupTasks.resolve(rootPath) : {
@@ -2486,6 +2547,10 @@ function setupRoutes({ app, context, hotReloadSubscribers, hasConfig, setupTasks
2486
2547
  };
2487
2548
  app.post("/v1/traces", otlpRoute);
2488
2549
  app.post("/otel/v1/traces", otlpRoute);
2550
+ app.post(TRACE_EVENTS_PATH, async (c) => {
2551
+ const result = await handleTraceEvents(await c.req.text(), traceEventIngestor);
2552
+ return c.json(result.body, result.status);
2553
+ });
2489
2554
  app.get("/api/views", async (c) => c.json(views ? await views.list() : {
2490
2555
  version: 0,
2491
2556
  views: [],
@@ -2581,6 +2646,20 @@ function propValueToJson(value) {
2581
2646
  default: return;
2582
2647
  }
2583
2648
  }
2649
+ /**
2650
+ * Whether a `PropValue` holds an `undefined` at any depth. JSON can't say so,
2651
+ * and {@link propValueToJson} reads one as `null` — a different value to a
2652
+ * schema — so whoever must preserve the difference asks here first.
2653
+ */
2654
+ function holdsUndefined(value) {
2655
+ switch (value.kind) {
2656
+ case "primitive": return value.value === void 0;
2657
+ case "array":
2658
+ case "tuple": return value.elements.some(holdsUndefined);
2659
+ case "object": return Object.values(value.properties).some(holdsUndefined);
2660
+ default: return false;
2661
+ }
2662
+ }
2584
2663
  //#endregion
2585
2664
  //#region src/eval/run-summary.ts
2586
2665
  /**
@@ -2709,8 +2788,10 @@ function withReferencedInstances(inputs, own, stored) {
2709
2788
  return Object.keys(out).length > 0 ? out : void 0;
2710
2789
  }
2711
2790
  /**
2712
- * Proposes bindings for every unbound slot and check parameter, never
2713
- * touching one already set (`specs/evals.md` §F.1):
2791
+ * Proposes bindings for every unbound slot and check parameter in `scope`,
2792
+ * never touching one already set (`specs/evals.md` §F.1). Meant for setting
2793
+ * an eval up, not for every time it's opened: a slot left unbound on purpose
2794
+ * would be bound again.
2714
2795
  *
2715
2796
  * - A prompt slot takes a column that matches it by name and type, else
2716
2797
  * what the playground last ran it with.
@@ -2721,8 +2802,9 @@ function withReferencedInstances(inputs, own, stored) {
2721
2802
  * that fits": a confident wrong binding is worse than an obvious empty one.
2722
2803
  */
2723
2804
  function prefillBindings(input) {
2724
- const { prompt, fields, stored } = input;
2805
+ const { prompt, fields, stored, scope = "all" } = input;
2725
2806
  const matched = [];
2807
+ const checkIds = scope === "all" ? void 0 : new Set(scope.checkIds);
2726
2808
  const fillHalf = (params, current, storedHalf, prefix) => {
2727
2809
  const out = { ...current };
2728
2810
  for (const param of params) {
@@ -2731,15 +2813,18 @@ function prefillBindings(input) {
2731
2813
  }
2732
2814
  return out;
2733
2815
  };
2734
- const inputs = {
2816
+ const inputs = checkIds ? input.inputs : {
2735
2817
  functionInputs: fillHalf(prompt.functionParameters, input.inputs.functionInputs, stored?.functionInputs, "fn"),
2736
2818
  executeInputs: fillHalf(prompt.executeParameters ?? [], input.inputs.executeInputs, stored?.executeInputs, "exec")
2737
2819
  };
2738
- const resources = withReferencedInstances(inputs, input.inputs.resources, stored?.resources);
2739
- if (resources) inputs.resources = resources;
2820
+ if (!checkIds) {
2821
+ const resources = withReferencedInstances(inputs, input.inputs.resources, stored?.resources);
2822
+ if (resources) inputs.resources = resources;
2823
+ }
2740
2824
  return {
2741
2825
  inputs,
2742
2826
  checks: input.checks.map((check) => {
2827
+ if (checkIds && !checkIds.has(check.id)) return check;
2743
2828
  const info = input.checkInfos.find((c) => c.uri === check.uri);
2744
2829
  if (!info) return check;
2745
2830
  const args = { ...check.args };
@@ -2998,6 +3083,7 @@ function describeBinding(input, fields) {
2998
3083
  return column ? { column } : input;
2999
3084
  }
3000
3085
  case "value": {
3086
+ if (holdsUndefined(input.value)) return input;
3001
3087
  const plain = propValueToJson(input.value);
3002
3088
  return plain === void 0 ? input : { json: plain };
3003
3089
  }
@@ -3036,7 +3122,7 @@ function checkIdFor(uri, taken) {
3036
3122
  taken.add(id);
3037
3123
  return id;
3038
3124
  }
3039
- const binding = z.record(z.string(), z.unknown()).describe("How to fill a slot: {column: \"<dataset field name>\"} for the row's value (a field sharing its name with an earlier one goes by its query column, e.g. \"city#3\"), {json: <plain JSON>} for a fixed value, {kind: \"input\", half: \"function\" | \"execute\", path} for what the run bound to one of the prompt's own slots, {kind: \"object\", properties: {name: binding}} to fill an object property by property, or {kind: \"instance\", name, output?} for one of the eval's (or each row's) named resource instances, or an output of it.");
3125
+ const binding = z.record(z.string(), z.unknown()).describe("How to fill a slot: {column: \"<dataset field name>\"} for the row's value (a field sharing its name with an earlier one goes by its query column, e.g. \"city#3\"), {json: <plain JSON>} for a fixed value, {kind: \"value\", value: {kind: \"primitive\"}} for a value left undefined, {kind: \"input\", half: \"function\" | \"execute\", path} for what the run bound to one of the prompt's own slots, {kind: \"object\", properties: {name: binding}} to fill an object property by property, or {kind: \"instance\", name, output?} for one of the eval's (or each row's) named resource instances, or an output of it.");
3040
3126
  const bindings = z.record(z.string(), binding).describe("Parameter name → binding.");
3041
3127
  const resourceSpec = z.object({
3042
3128
  uri: z.string().describe("The resource's uri (`<module>#<export>`), never an output's."),
@@ -4830,7 +4916,7 @@ var ViewRegistry = class {
4830
4916
  //#endregion
4831
4917
  //#region src/server/index.ts
4832
4918
  async function startServer(options) {
4833
- const { promptProviders, traceProviders, datasetProviders = [], evalProviders = [], port, hostname = DEFAULT_HOST, publicUrl: givenPublicUrl, rootPath, hasConfig, terminalSessions, otlpIngestor, version } = options;
4919
+ const { promptProviders, traceProviders, datasetProviders = [], evalProviders = [], port, hostname = DEFAULT_HOST, publicUrl: givenPublicUrl, rootPath, hasConfig, terminalSessions, otlpIngestor, traceEventIngestor, version } = options;
4834
4920
  const views = options.views ?? new ViewRegistry({
4835
4921
  fileProvider: new LocalFileProvider(),
4836
4922
  rootDir: rootPath
@@ -4870,6 +4956,7 @@ async function startServer(options) {
4870
4956
  },
4871
4957
  agents,
4872
4958
  otlpIngestor,
4959
+ traceEventIngestor,
4873
4960
  views
4874
4961
  });
4875
4962
  const unwatchViews = views.watch((version) => broadcast({
@@ -4963,50 +5050,6 @@ function parseCliArgs(argv) {
4963
5050
  };
4964
5051
  }
4965
5052
  //#endregion
4966
- //#region src/cli/bundler-resolution-hook.ts
4967
- const RESOLVABLE_EXTENSIONS = [
4968
- ".ts",
4969
- ".tsx",
4970
- ".mts",
4971
- ".js",
4972
- ".jsx",
4973
- ".mjs",
4974
- ".cjs"
4975
- ];
4976
- function isFileSpecifier(specifier) {
4977
- return specifier.startsWith("./") || specifier.startsWith("../") || specifier.startsWith("/") || specifier.startsWith("file://");
4978
- }
4979
- function candidateSpecifiers(specifier) {
4980
- return [...RESOLVABLE_EXTENSIONS.map((ext) => specifier + ext), ...RESOLVABLE_EXTENSIONS.map((ext) => `${specifier}/index${ext}`)];
4981
- }
4982
- /**
4983
- * Registers an in-thread module-resolution hook that falls back to
4984
- * bundler-style resolution — appending an extension (`./foo` → `./foo.ts`)
4985
- * or a directory's index file (`./tools` → `./tools/index.ts`) — when
4986
- * Node's strict ESM resolver rejects a relative or absolute specifier that
4987
- * has neither.
4988
- *
4989
- * Prompt files (and whatever they import) run through Node's own loader,
4990
- * but consumer projects are commonly authored for a bundler
4991
- * (`moduleResolution: "bundler"`), which allows omitting both. Only retried
4992
- * for specifiers Node itself couldn't resolve, and only for relative or
4993
- * absolute ones — bare package specifiers are left to normal resolution.
4994
- */
4995
- function registerBundlerResolutionFallback() {
4996
- module.registerHooks({ resolve(specifier, context, nextResolve) {
4997
- if (!isFileSpecifier(specifier)) return nextResolve(specifier, context);
4998
- try {
4999
- return nextResolve(specifier, context);
5000
- } catch (err) {
5001
- if (err?.code !== "ERR_MODULE_NOT_FOUND" && err?.code !== "ERR_UNSUPPORTED_DIR_IMPORT") throw err;
5002
- for (const candidate of candidateSpecifiers(specifier)) try {
5003
- return nextResolve(candidate, context);
5004
- } catch {}
5005
- throw err;
5006
- }
5007
- } });
5008
- }
5009
- //#endregion
5010
5053
  //#region src/cli/config-loader-hooks.ts
5011
5054
  /**
5012
5055
  * Registers an in-thread module-resolution hook so a project's
@@ -5902,6 +5945,8 @@ async function setUpProject(rootDir, config) {
5902
5945
  for (const ingestor of ingestors) ingestor.setResource?.(PLAYGROUND_RESOURCE);
5903
5946
  const otlpIngestor = new OtlpTraceIngestor();
5904
5947
  ingestors.push(otlpIngestor);
5948
+ const traceEventIngestor = new TraceEventIngestor();
5949
+ ingestors.push(traceEventIngestor);
5905
5950
  const costSink = new CostFetchingTraceSink();
5906
5951
  const traceSinks = traceProviders.filter((p) => isTraceSink(p));
5907
5952
  for (const sink of traceSinks) costSink.addSink(sink);
@@ -5913,7 +5958,8 @@ async function setUpProject(rootDir, config) {
5913
5958
  traceProviders,
5914
5959
  datasetProviders,
5915
5960
  evalProviders,
5916
- otlpIngestor
5961
+ otlpIngestor,
5962
+ traceEventIngestor
5917
5963
  };
5918
5964
  }
5919
5965
  //#endregion
@@ -5996,6 +6042,7 @@ function registerTypeScriptTransformFallback() {
5996
6042
  const VERSION = version;
5997
6043
  registerEvalutionResolver(import.meta.url);
5998
6044
  registerBundlerResolutionFallback();
6045
+ registerFreshImportHook();
5999
6046
  registerVariationLoaderHook();
6000
6047
  registerTypeScriptTransformFallback();
6001
6048
  async function startConfiguredServer(rootDir, config, hasConfig, port, host, terminalSessions) {