evalution 1.0.8 → 2.0.1
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/LICENSING.md +26 -44
- package/README.md +11 -11
- package/dist/{check-CR4fU1S5.d.ts → check-BKU5_IhU.d.ts} +18 -868
- package/dist/checks/index.d.ts +2 -1
- package/dist/cli/index.js +809 -372
- package/dist/client/assets/{DatasetView-BqSWI_pm.js → DatasetView-DZ2uLHKV.js} +12 -10
- package/dist/client/assets/{EvalRunView-CR6ZksSu.js → EvalRunView-T610dLVw.js} +1 -1
- package/dist/client/assets/{EvalView-JPEM5IY8.js → EvalView-Cae68vPB.js} +1 -1
- package/dist/client/assets/{data-grid-overlay-editor-B_nPhXKR.js → data-grid-overlay-editor-PtH7A6E4.js} +1 -1
- package/dist/client/assets/{highlighted-body-KPVGNVTW-dPpneB8R.js → highlighted-body-KPVGNVTW-CPtwvSJb.js} +1 -1
- package/dist/client/assets/{index-CwjMcK6S.js → index-BFH07Ynk.js} +147 -147
- package/dist/client/assets/index-KCv8AeiY.css +32 -0
- package/dist/client/assets/{number-overlay-editor-CRWFlaQs.js → number-overlay-editor-BbQhagHP.js} +1 -1
- package/dist/client/index.html +2 -2
- package/dist/cost-fetching-trace-sink-Dz8gniQ6.js +262 -0
- package/dist/{dataset-types-Dqi5vVg-.d.ts → dataset-types-D-Fsbg8B.d.ts} +7 -247
- package/dist/index.d.ts +844 -1426
- package/dist/index.js +151 -480
- package/dist/ingest.d.ts +119 -0
- package/dist/ingest.js +3 -0
- package/dist/{trace-event-ingestor-BghQcCHe.js → local-database-trace-provider-87-WGqfS.js} +1976 -7362
- package/dist/{trace-DGj5oW7z.d.ts → trace-BLjFYF9G.d.ts} +2 -1
- package/dist/trace-event-ingestor-B1DYEg2H.js +798 -0
- package/dist/trace-event-ingestor-JNpe-OrX.d.ts +109 -0
- package/dist/views/datasets/index.d.ts +1 -1
- package/dist/views/index.d.ts +3 -2
- package/dist/views/index.js +0 -4
- package/dist/views/react/index.d.ts +1 -1
- package/package.json +32 -30
- package/dist/client/assets/index-BGcZZetP.css +0 -32
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
import { c as normalizeOtlpRequest, s as decodeOtlpProtobuf } from "./trace-event-ingestor-B1DYEg2H.js";
|
|
2
|
+
//#region src/server/handlers/otlp-ingest.ts
|
|
3
|
+
/**
|
|
4
|
+
* Host-neutral handler for an OTLP trace export request (`POST /v1/traces`).
|
|
5
|
+
* Decodes protobuf or JSON, normalizes to `NormalizedOtlpSpan[]`, and hands
|
|
6
|
+
* the batch to whichever {@link OtlpTraceIngestor} {@link OtlpIngestDeps.resolveIngestor}
|
|
7
|
+
* picks. Takes and returns plain data (`ArrayBuffer` + headers, `{status,
|
|
8
|
+
* body}`) rather than a framework `Request`/`Response` so it stays usable
|
|
9
|
+
* from Hono, a Worker, or a test — no `Buffer`, no `fs`, no `process`.
|
|
10
|
+
*/
|
|
11
|
+
async function handleOtlpTraces(req, deps) {
|
|
12
|
+
let normalized;
|
|
13
|
+
try {
|
|
14
|
+
const mediaType = req.contentType.split(";")[0]?.trim().toLowerCase();
|
|
15
|
+
if (mediaType === "application/x-protobuf" || mediaType === "application/protobuf") normalized = normalizeOtlpRequest(decodeOtlpProtobuf(new Uint8Array(req.body)));
|
|
16
|
+
else if (mediaType === "application/json") {
|
|
17
|
+
const text = new TextDecoder().decode(req.body);
|
|
18
|
+
normalized = normalizeOtlpRequest(JSON.parse(text));
|
|
19
|
+
} else return {
|
|
20
|
+
status: 415,
|
|
21
|
+
body: { error: `Unsupported content-type: ${req.contentType}` }
|
|
22
|
+
};
|
|
23
|
+
} catch (err) {
|
|
24
|
+
return {
|
|
25
|
+
status: 400,
|
|
26
|
+
body: { error: `Malformed OTLP payload: ${err?.message ?? err}` }
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
const ingestor = deps.resolveIngestor({
|
|
30
|
+
headers: req.headers,
|
|
31
|
+
auth: req.auth
|
|
32
|
+
});
|
|
33
|
+
if (!ingestor) return {
|
|
34
|
+
status: 404,
|
|
35
|
+
body: { error: "No trace ingestor available for this request" }
|
|
36
|
+
};
|
|
37
|
+
await ingestor.ingest(normalized);
|
|
38
|
+
return {
|
|
39
|
+
status: 200,
|
|
40
|
+
body: { partialSuccess: {} }
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
//#region src/server/handlers/trace-events-ingest.ts
|
|
45
|
+
function isObject(value) {
|
|
46
|
+
return typeof value === "object" && value !== null;
|
|
47
|
+
}
|
|
48
|
+
function isSpanLike(value) {
|
|
49
|
+
return isObject(value) && typeof value.id === "string" && typeof value.traceId === "string" && typeof value.startTime === "number";
|
|
50
|
+
}
|
|
51
|
+
/** Whether `value` is a {@link TraceSinkEvent} the ingestor can replay. */
|
|
52
|
+
function isTraceSinkEvent(value) {
|
|
53
|
+
if (!isObject(value)) return false;
|
|
54
|
+
switch (value.type) {
|
|
55
|
+
case "span-start":
|
|
56
|
+
case "span-end": return isSpanLike(value.span);
|
|
57
|
+
case "trace-fail": return typeof value.traceId === "string" && typeof value.errorMessage === "string";
|
|
58
|
+
default: return false;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Host-neutral handler for a batch of trace events an app's `HttpTraceSink`
|
|
63
|
+
* sends (`POST /api/traces`). Takes the request body as text and
|
|
64
|
+
* returns plain `{status, body}`, like `handleOtlpTraces`, so it stays usable
|
|
65
|
+
* from Hono, a Worker, or a test.
|
|
66
|
+
*/
|
|
67
|
+
async function handleTraceEvents(body, ingestor) {
|
|
68
|
+
let events;
|
|
69
|
+
try {
|
|
70
|
+
events = JSON.parse(body)?.events;
|
|
71
|
+
} catch (err) {
|
|
72
|
+
return {
|
|
73
|
+
status: 400,
|
|
74
|
+
body: { error: `Malformed JSON: ${err?.message ?? err}` }
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (!Array.isArray(events)) return {
|
|
78
|
+
status: 400,
|
|
79
|
+
body: { error: "Expected an `events` array" }
|
|
80
|
+
};
|
|
81
|
+
const invalid = events.findIndex((e) => !isTraceSinkEvent(e));
|
|
82
|
+
if (invalid >= 0) return {
|
|
83
|
+
status: 400,
|
|
84
|
+
body: { error: `Malformed event at ${invalid}` }
|
|
85
|
+
};
|
|
86
|
+
if (!ingestor) return {
|
|
87
|
+
status: 404,
|
|
88
|
+
body: { error: "No trace ingestor available for this request" }
|
|
89
|
+
};
|
|
90
|
+
await ingestor.ingest(events);
|
|
91
|
+
return {
|
|
92
|
+
status: 200,
|
|
93
|
+
body: {}
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
//#endregion
|
|
97
|
+
//#region src/trace/cost-fetching-trace-sink.ts
|
|
98
|
+
/** The catalogs to fetch prices from, in order — each only if the last fails. */
|
|
99
|
+
const CATALOGS = [{
|
|
100
|
+
url: "https://ai-gateway.vercel.sh/v1/models",
|
|
101
|
+
inputKey: "input",
|
|
102
|
+
outputKey: "output"
|
|
103
|
+
}, {
|
|
104
|
+
url: "https://openrouter.ai/api/v1/models",
|
|
105
|
+
inputKey: "prompt",
|
|
106
|
+
outputKey: "completion"
|
|
107
|
+
}];
|
|
108
|
+
/**
|
|
109
|
+
* Lowercases a model id and spells version dots as dashes, so a catalog's
|
|
110
|
+
* `claude-sonnet-4.5` and a provider SDK's `claude-sonnet-4-5` meet.
|
|
111
|
+
*/
|
|
112
|
+
function normalizeModelId(id) {
|
|
113
|
+
return id.toLowerCase().replaceAll(".", "-");
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Looks up `model`'s price by the longest known id it starts with, cut only at
|
|
117
|
+
* `-` boundaries: `gpt-4o-2024-11-20` resolves to `gpt-4o`, never to `gpt-4`,
|
|
118
|
+
* and `o3` never resolves to a longer id like `o3-pro`.
|
|
119
|
+
*/
|
|
120
|
+
function findPrice(prices, model) {
|
|
121
|
+
const segments = normalizeModelId(model).split("-");
|
|
122
|
+
for (let n = segments.length; n > 0; n--) {
|
|
123
|
+
const price = prices.get(segments.slice(0, n).join("-"));
|
|
124
|
+
if (price) return price;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** Parses a catalog's $/token string; `undefined` if absent or malformed. */
|
|
128
|
+
function parseRate(value) {
|
|
129
|
+
if (value === void 0) return void 0;
|
|
130
|
+
const rate = parseFloat(value);
|
|
131
|
+
return Number.isFinite(rate) && rate >= 0 ? rate : void 0;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Indexes a catalog's models by both their full id and their id stripped of
|
|
135
|
+
* its provider prefix, so a span's bare model name (e.g. from a provider SDK
|
|
136
|
+
* that doesn't know about `provider/model` ids) still matches. The first
|
|
137
|
+
* entry for a bare name wins. Models with no input or output price (images,
|
|
138
|
+
* embeddings, free models) are skipped.
|
|
139
|
+
*/
|
|
140
|
+
function parsePrices(data, catalog) {
|
|
141
|
+
const prices = /* @__PURE__ */ new Map();
|
|
142
|
+
for (const m of data.data ?? []) {
|
|
143
|
+
if (!m.id || !m.pricing) continue;
|
|
144
|
+
const price = {
|
|
145
|
+
input: parseRate(m.pricing[catalog.inputKey]) ?? 0,
|
|
146
|
+
output: parseRate(m.pricing[catalog.outputKey]) ?? 0,
|
|
147
|
+
cacheRead: parseRate(m.pricing.input_cache_read),
|
|
148
|
+
cacheWrite: parseRate(m.pricing.input_cache_write)
|
|
149
|
+
};
|
|
150
|
+
if (price.input === 0 && price.output === 0) continue;
|
|
151
|
+
const id = normalizeModelId(m.id);
|
|
152
|
+
const shortId = id.slice(id.lastIndexOf("/") + 1);
|
|
153
|
+
prices.set(id, price);
|
|
154
|
+
if (!prices.has(shortId)) prices.set(shortId, price);
|
|
155
|
+
}
|
|
156
|
+
return prices;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* What a call cost. `promptTokens` counts every input token, cached or not,
|
|
160
|
+
* so the cache reads and writes are carved out of it and billed at their own
|
|
161
|
+
* rates — or at the input rate, if the catalog lists none. Their share of
|
|
162
|
+
* `prompt` is broken out only when the span reports cache usage.
|
|
163
|
+
*/
|
|
164
|
+
function callCost(llm, price) {
|
|
165
|
+
const cacheReadTokens = llm.cacheReadTokens ?? 0;
|
|
166
|
+
const cacheWriteTokens = llm.cacheWriteTokens ?? 0;
|
|
167
|
+
const uncachedTokens = Math.max(0, (llm.promptTokens ?? 0) - cacheReadTokens - cacheWriteTokens);
|
|
168
|
+
const cacheRead = cacheReadTokens * (price.cacheRead ?? price.input);
|
|
169
|
+
const cacheWrite = cacheWriteTokens * (price.cacheWrite ?? price.input);
|
|
170
|
+
return {
|
|
171
|
+
prompt: uncachedTokens * price.input + cacheRead + cacheWrite,
|
|
172
|
+
completion: (llm.completionTokens ?? 0) * price.output,
|
|
173
|
+
...llm.cacheReadTokens !== void 0 && { cacheRead },
|
|
174
|
+
...llm.cacheWriteTokens !== void 0 && { cacheWrite }
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* A {@link TraceSink} that stamps `llm.cost` onto LLM spans with known token
|
|
179
|
+
* usage, then fans the span out to its own registered downstream sinks.
|
|
180
|
+
*
|
|
181
|
+
* Pricing is fetched once, lazily on the first relevant span, from Vercel AI
|
|
182
|
+
* Gateway's public model catalog — or, if that request fails, from
|
|
183
|
+
* OpenRouter's — and cached in memory for the life of the instance. Cache
|
|
184
|
+
* reads and writes are billed at the catalog's cache prices where it lists
|
|
185
|
+
* them. A fetch failure (or an offline environment) is logged to the console
|
|
186
|
+
* but never thrown at the caller; costs just don't get stamped.
|
|
187
|
+
*/
|
|
188
|
+
var CostFetchingTraceSink = class {
|
|
189
|
+
fetchImpl;
|
|
190
|
+
fetchPricing;
|
|
191
|
+
sinks = [];
|
|
192
|
+
prices;
|
|
193
|
+
constructor(options = {}) {
|
|
194
|
+
this.fetchImpl = options.fetch ?? ((...args) => globalThis.fetch(...args));
|
|
195
|
+
this.fetchPricing = options.fetchPricing ?? !globalThis.process?.env?.EVALUTION_NO_COST_ESTIMATES;
|
|
196
|
+
}
|
|
197
|
+
/** Add a downstream sink. May be called multiple times. */
|
|
198
|
+
addSink(sink) {
|
|
199
|
+
this.sinks.push(sink);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Remove a previously-added sink. Returns `true` if the given sink was
|
|
203
|
+
* found and removed, otherwise `false`.
|
|
204
|
+
*/
|
|
205
|
+
removeSink(sink) {
|
|
206
|
+
const i = this.sinks.indexOf(sink);
|
|
207
|
+
if (i === -1) return false;
|
|
208
|
+
this.sinks.splice(i, 1);
|
|
209
|
+
return true;
|
|
210
|
+
}
|
|
211
|
+
async recordSpanStart(span) {
|
|
212
|
+
const stamped = await this.withCost(span);
|
|
213
|
+
await Promise.all(this.sinks.map((s) => s.recordSpanStart(stamped)));
|
|
214
|
+
return stamped;
|
|
215
|
+
}
|
|
216
|
+
async recordSpanEnd(span) {
|
|
217
|
+
const stamped = await this.withCost(span);
|
|
218
|
+
await Promise.all(this.sinks.map((s) => s.recordSpanEnd(stamped)));
|
|
219
|
+
return stamped;
|
|
220
|
+
}
|
|
221
|
+
async failTrace(traceId, errorMessage) {
|
|
222
|
+
await Promise.all(this.sinks.map((s) => s.failTrace(traceId, errorMessage)));
|
|
223
|
+
}
|
|
224
|
+
async withCost(span) {
|
|
225
|
+
const llm = span.llm;
|
|
226
|
+
if (!this.fetchPricing || span.kind !== "LLM" || !llm?.model || llm.promptTokens === void 0 && llm.completionTokens === void 0) return span;
|
|
227
|
+
this.prices ??= this.fetchPrices();
|
|
228
|
+
const price = findPrice(await this.prices, llm.model);
|
|
229
|
+
if (!price) return span;
|
|
230
|
+
return {
|
|
231
|
+
...span,
|
|
232
|
+
llm: {
|
|
233
|
+
...llm,
|
|
234
|
+
cost: callCost(llm, price)
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
async fetchPrices() {
|
|
239
|
+
for (const catalog of CATALOGS) {
|
|
240
|
+
const prices = await this.fetchCatalog(catalog);
|
|
241
|
+
if (prices) return prices;
|
|
242
|
+
}
|
|
243
|
+
return /* @__PURE__ */ new Map();
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Fetches and parses one model catalog. Returns `undefined` if the request
|
|
247
|
+
* fails, so the caller can fall back to another — never throws for the
|
|
248
|
+
* caller over this.
|
|
249
|
+
*/
|
|
250
|
+
async fetchCatalog(catalog) {
|
|
251
|
+
const { url } = catalog;
|
|
252
|
+
try {
|
|
253
|
+
const res = await this.fetchImpl(url);
|
|
254
|
+
if (res.ok) return parsePrices(await res.json(), catalog);
|
|
255
|
+
console.error(`Failed to fetch model pricing from ${url}: ${res.status} ${res.statusText}`);
|
|
256
|
+
} catch (err) {
|
|
257
|
+
console.error(`Failed to fetch model pricing from ${url}:`, err);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
//#endregion
|
|
262
|
+
export { handleTraceEvents as n, handleOtlpTraces as r, CostFetchingTraceSink as t };
|
|
@@ -1,251 +1,6 @@
|
|
|
1
|
+
import { PromptID } from "@evalution/sdk";
|
|
1
2
|
import { PropDefinition, PropValue } from "ts-proppy";
|
|
2
3
|
|
|
3
|
-
//#region src/trace/trace-types.d.ts
|
|
4
|
-
/**
|
|
5
|
-
* A reference to a prompt.
|
|
6
|
-
*
|
|
7
|
-
* `id` is interpreted as a globally-unique prompt ID unless `providerId` is
|
|
8
|
-
* present, in which case `id` is scoped to that specific prompt provider. This
|
|
9
|
-
* mirrors the OpenTelemetry attributes `evalution.prompt.id` (always present)
|
|
10
|
-
* and `evalution.prompt.provider.id` (optional, scoping).
|
|
11
|
-
*/
|
|
12
|
-
interface PromptID {
|
|
13
|
-
/** The prompt ID — global unless {@link providerId} scopes it. */
|
|
14
|
-
id: string;
|
|
15
|
-
/** When set, {@link id} is scoped to this prompt provider. */
|
|
16
|
-
providerId?: string;
|
|
17
|
-
/** Positional arguments the prompt function was called with. */
|
|
18
|
-
functionParameters?: unknown[];
|
|
19
|
-
/**
|
|
20
|
-
* The unresolved inputs the run was launched with — the recipe, not the
|
|
21
|
-
* resolution.
|
|
22
|
-
*
|
|
23
|
-
* Replaying them is only exactly faithful for the `value` kind. A `resource`
|
|
24
|
-
* re-runs its `create()`, producing an *equivalent* value rather than the
|
|
25
|
-
* same one — a fresh handle, a newly seeded row — so a UI must present it as
|
|
26
|
-
* something that will be re-created, never as a restored value.
|
|
27
|
-
*/
|
|
28
|
-
functionInputs?: unknown[];
|
|
29
|
-
/** The unresolved execute-parameter inputs, keyed by parameter name. */
|
|
30
|
-
executeInputs?: Record<string, unknown>;
|
|
31
|
-
/**
|
|
32
|
-
* The run's named resource instances, by name, with the receipt each
|
|
33
|
-
* `create()` produced. See `specs/resource-instances.md` §F.
|
|
34
|
-
*/
|
|
35
|
-
resources?: Record<string, unknown>;
|
|
36
|
-
/**
|
|
37
|
-
* The prompt's parameter definitions as they stood when the run was
|
|
38
|
-
* launched, so a replay can diff them against today's signature rather than
|
|
39
|
-
* guess whether the recorded inputs still fit.
|
|
40
|
-
*/
|
|
41
|
-
parameterDefinitions?: unknown[];
|
|
42
|
-
/**
|
|
43
|
-
* The prompt's execute-parameter definitions as they stood when the run was
|
|
44
|
-
* launched — the types of {@link executeInputs}, as
|
|
45
|
-
* {@link parameterDefinitions} is for {@link functionInputs}.
|
|
46
|
-
*/
|
|
47
|
-
executeParameterDefinitions?: unknown[];
|
|
48
|
-
/** The version the run executed against. */
|
|
49
|
-
version?: string;
|
|
50
|
-
/** The variation applied on top of {@link version}, if any. */
|
|
51
|
-
variation?: string;
|
|
52
|
-
}
|
|
53
|
-
/**
|
|
54
|
-
* Classification of a {@link Span}. See also:
|
|
55
|
-
* - `lmnr.span.type` from https://laminar.sh/docs/tracing/otel
|
|
56
|
-
* - `mlflow.spanType` from https://mlflow.org/docs/latest/genai/tracing/opentelemetry/attribute-mapping/#translated-span-attributes
|
|
57
|
-
*
|
|
58
|
-
* Mapped from `gen_ai.operation.name`. `CHECK` is evalution's own: an eval
|
|
59
|
-
* check that traced something while judging the run — see
|
|
60
|
-
* {@link CHECK_ATTRIBUTE}.
|
|
61
|
-
*/
|
|
62
|
-
type SpanKind = "LLM" | "TOOL" | "AGENT" | "EMBEDDING" | "CHECK" | "DEFAULT";
|
|
63
|
-
/** A text segment within a multi-part {@link SpanMessage} content. */
|
|
64
|
-
interface SpanTextPart {
|
|
65
|
-
type: "text";
|
|
66
|
-
text: string;
|
|
67
|
-
}
|
|
68
|
-
/** An image segment within a multi-part {@link SpanMessage} content. */
|
|
69
|
-
interface SpanImagePart {
|
|
70
|
-
type: "image";
|
|
71
|
-
/** A URL, or base64/data-URI image data. */
|
|
72
|
-
image: string;
|
|
73
|
-
/** MIME type (e.g. `image/png`), when known. */
|
|
74
|
-
mediaType?: string;
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* A tool call the assistant made, within a multi-part {@link SpanMessage}
|
|
78
|
-
* content. Matched to its {@link SpanToolResultPart} by `toolCallId`.
|
|
79
|
-
*/
|
|
80
|
-
interface SpanToolCallPart {
|
|
81
|
-
type: "tool-call";
|
|
82
|
-
toolCallId: string;
|
|
83
|
-
toolName: string;
|
|
84
|
-
/** The arguments the model passed, as JSON. */
|
|
85
|
-
input: unknown;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* A tool's result fed back to the model, within a multi-part
|
|
89
|
-
* {@link SpanMessage} content (usually a `tool` message).
|
|
90
|
-
*/
|
|
91
|
-
interface SpanToolResultPart {
|
|
92
|
-
type: "tool-result";
|
|
93
|
-
toolCallId: string;
|
|
94
|
-
toolName: string;
|
|
95
|
-
/** What the tool returned, unwrapped from the SDK's output envelope. */
|
|
96
|
-
output: unknown;
|
|
97
|
-
/** Whether the result reports a failure (an error, or a denied call). */
|
|
98
|
-
isError?: boolean;
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* The reasoning (thinking) a model produced ahead of its answer, within a
|
|
102
|
-
* multi-part {@link SpanMessage} content — how a conversation's earlier
|
|
103
|
-
* assistant turns carry theirs. The turn a span records keeps its own in
|
|
104
|
-
* {@link LLMSpanDetails.reasoning}.
|
|
105
|
-
*/
|
|
106
|
-
interface SpanReasoningPart {
|
|
107
|
-
type: "reasoning";
|
|
108
|
-
text: string;
|
|
109
|
-
}
|
|
110
|
-
type SpanMessageRole = "user" | "assistant" | "system" | "tool" | (string & {});
|
|
111
|
-
/** One segment of a multi-part {@link SpanMessage} content. */
|
|
112
|
-
type SpanContentPart = SpanTextPart | SpanImagePart | SpanToolCallPart | SpanToolResultPart | SpanReasoningPart;
|
|
113
|
-
/**
|
|
114
|
-
* A single message within an LLM span's input/output.
|
|
115
|
-
*
|
|
116
|
-
* `content` is a plain string for the common text-only case. It is an array
|
|
117
|
-
* of {@link SpanContentPart} when the message carries non-text content (e.g.
|
|
118
|
-
* an image, or a tool call or result) — the `string` form stays in the union so existing consumers and
|
|
119
|
-
* already-stored rows keep working unchanged.
|
|
120
|
-
*/
|
|
121
|
-
interface SpanMessage {
|
|
122
|
-
role: SpanMessageRole;
|
|
123
|
-
content: string | SpanContentPart[];
|
|
124
|
-
}
|
|
125
|
-
/** LLM-specific attributes attached to `LLM` spans. */
|
|
126
|
-
interface LLMSpanDetails {
|
|
127
|
-
provider?: string;
|
|
128
|
-
model?: string;
|
|
129
|
-
/** Model parameters (temperature, max_tokens, …). */
|
|
130
|
-
modelParameters?: Record<string, unknown>;
|
|
131
|
-
/**
|
|
132
|
-
* Why the model stopped generating, as the provider or SDK reports it
|
|
133
|
-
* (`stop`, `length`, `tool-calls`, …). Not normalized across providers.
|
|
134
|
-
*/
|
|
135
|
-
finishReason?: string;
|
|
136
|
-
/**
|
|
137
|
-
* What the model was given: a message list for a chat model, or any JSON
|
|
138
|
-
* for a model that takes something else (a System One call records
|
|
139
|
-
* `{ state, questions }`). Array-ness is the discriminant — see
|
|
140
|
-
* {@link spanMessages}.
|
|
141
|
-
*/
|
|
142
|
-
input?: SpanMessage[] | {
|
|
143
|
-
[key: string]: unknown;
|
|
144
|
-
};
|
|
145
|
-
/**
|
|
146
|
-
* What it returned: text for a chat model, the assistant message of a turn
|
|
147
|
-
* that called tools (see `toolCallingOutput`), or JSON for structured
|
|
148
|
-
* output and for any model whose answer is data rather than prose.
|
|
149
|
-
*/
|
|
150
|
-
output?: unknown;
|
|
151
|
-
/**
|
|
152
|
-
* The reasoning the model produced on the way to {@link output}, kept apart
|
|
153
|
-
* from it so an output stays the answer that checks and agents read.
|
|
154
|
-
*/
|
|
155
|
-
reasoning?: string;
|
|
156
|
-
/** Input tokens, counting any read from or written to a prompt cache. */
|
|
157
|
-
promptTokens?: number;
|
|
158
|
-
completionTokens?: number;
|
|
159
|
-
totalTokens?: number;
|
|
160
|
-
/** How many of {@link promptTokens} were read from a prompt cache. */
|
|
161
|
-
cacheReadTokens?: number;
|
|
162
|
-
/** How many of {@link promptTokens} were written to a prompt cache. */
|
|
163
|
-
cacheWriteTokens?: number;
|
|
164
|
-
/**
|
|
165
|
-
* Dollar cost of the call, broken down by token type, if known. The total
|
|
166
|
-
* cost is `cost.prompt + cost.completion`; `cost.prompt` includes cache
|
|
167
|
-
* reads and writes, each at its own price.
|
|
168
|
-
*/
|
|
169
|
-
cost?: {
|
|
170
|
-
prompt: number;
|
|
171
|
-
completion: number; /** The part of `prompt` spent on {@link cacheReadTokens}. */
|
|
172
|
-
cacheRead?: number; /** The part of `prompt` spent on {@link cacheWriteTokens}. */
|
|
173
|
-
cacheWrite?: number;
|
|
174
|
-
};
|
|
175
|
-
}
|
|
176
|
-
interface ToolSpanDetails {
|
|
177
|
-
toolName: string;
|
|
178
|
-
/**
|
|
179
|
-
* The id the model gave this call, when the integration reports it — the
|
|
180
|
-
* same id as the {@link SpanToolCallPart} that requested it.
|
|
181
|
-
*/
|
|
182
|
-
toolCallId?: string;
|
|
183
|
-
input: unknown;
|
|
184
|
-
output?: unknown;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* A span in a {@link Trace}. Spans form a tree via {@link parentId}.
|
|
188
|
-
* Durations are derived from `startTime` and `endTime`; an in-progress span has
|
|
189
|
-
* no `endTime` yet.
|
|
190
|
-
*/
|
|
191
|
-
interface Span {
|
|
192
|
-
id: string;
|
|
193
|
-
traceId: string;
|
|
194
|
-
/** `undefined` for the root span of the trace. */
|
|
195
|
-
parentId?: string;
|
|
196
|
-
name: string;
|
|
197
|
-
kind: SpanKind;
|
|
198
|
-
/** Start timestamp in milliseconds since epoch. */
|
|
199
|
-
startTime: number;
|
|
200
|
-
/** End timestamp in milliseconds since epoch, or `undefined` while running. */
|
|
201
|
-
endTime?: number;
|
|
202
|
-
status?: "ok" | "error";
|
|
203
|
-
/** Error message if `status` is `'error'`. */
|
|
204
|
-
errorMessage?: string;
|
|
205
|
-
/** Free-form attributes to show in the span's details pane. */
|
|
206
|
-
attributes?: Record<string, unknown>;
|
|
207
|
-
/**
|
|
208
|
-
* The OpenTelemetry resource that produced the span: attributes describing
|
|
209
|
-
* the process or service it ran in rather than the span itself
|
|
210
|
-
* (`service.name`, `deployment.environment.name`, …).
|
|
211
|
-
*/
|
|
212
|
-
resource?: Record<string, unknown>;
|
|
213
|
-
/** LLM-specific details (present for `chat`/`completion`/`embedding` spans). */
|
|
214
|
-
llm?: LLMSpanDetails;
|
|
215
|
-
/**
|
|
216
|
-
* The prompt this span is attributed to, if any.
|
|
217
|
-
*
|
|
218
|
-
* Stored as emitted (`evalution.prompt.id` plus optional
|
|
219
|
-
* `evalution.prompt.provider.id`): a {@link PromptID} whose `id` is global
|
|
220
|
-
* unless `providerId` is set. The server resolves it against the prompt
|
|
221
|
-
* registry to a provider-scoped reference when a trace is served.
|
|
222
|
-
*/
|
|
223
|
-
prompt?: PromptID;
|
|
224
|
-
tool?: ToolSpanDetails;
|
|
225
|
-
}
|
|
226
|
-
interface TraceBase {
|
|
227
|
-
id: string;
|
|
228
|
-
providerId?: string;
|
|
229
|
-
name: string;
|
|
230
|
-
/** Start timestamp (ms). */
|
|
231
|
-
startTime: number;
|
|
232
|
-
/** End timestamp (ms), or `undefined` while the trace is still running. */
|
|
233
|
-
endTime?: number;
|
|
234
|
-
status: "running" | "ok" | "error";
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Top-level trace for a single invocation (e.g. one prompt execution).
|
|
238
|
-
*/
|
|
239
|
-
interface Trace extends TraceBase {
|
|
240
|
-
/** Free-form attributes (e.g. prompt ID, function params). */
|
|
241
|
-
attributes?: Record<string, unknown>;
|
|
242
|
-
}
|
|
243
|
-
/** A trace together with all of its spans. */
|
|
244
|
-
interface TraceWithSpans {
|
|
245
|
-
trace: Trace;
|
|
246
|
-
spans: Span[];
|
|
247
|
-
}
|
|
248
|
-
//#endregion
|
|
249
4
|
//#region src/shared/types.d.ts
|
|
250
5
|
/**
|
|
251
6
|
* One prompt input, *before* resolution — the recipe rather than the value.
|
|
@@ -491,6 +246,11 @@ interface Dataset {
|
|
|
491
246
|
createdAt: number;
|
|
492
247
|
/** Timestamp (ms) of the last change to the dataset or its rows. */
|
|
493
248
|
updatedAt: number;
|
|
249
|
+
/**
|
|
250
|
+
* Synced with the linked project in Evalution Cloud: deleting it deletes
|
|
251
|
+
* the cloud's copy and every project member's.
|
|
252
|
+
*/
|
|
253
|
+
synced?: boolean;
|
|
494
254
|
}
|
|
495
255
|
/** One of the rows' resource instances, summarized across rows by name. */
|
|
496
256
|
interface DatasetInstanceShape {
|
|
@@ -576,4 +336,4 @@ interface DatasetRowsOverview {
|
|
|
576
336
|
instances: Record<string, DatasetInstanceShape>;
|
|
577
337
|
}
|
|
578
338
|
//#endregion
|
|
579
|
-
export { ResourceInstanceInput as _, ColumnPath as a,
|
|
339
|
+
export { ResourceInstanceInput as _, ColumnPath as a, PathRow as c, childInputs as d, fieldPath as f, ExecutionInput as g, resolveColumnPath as h, DatasetRowsOverview as i, PathValue as l, readColumnPath as m, DatasetRow as n, InstanceArgument as o, instancePath as p, DatasetRowUpdate as r, MAX_REFERENCE_HOPS as s, Dataset as t, ResolvedPath as u, RunResources as v };
|