evalution 2.0.0 → 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/README.md +11 -11
- package/dist/{check-ci7RhMcB.d.ts → check-BKU5_IhU.d.ts} +7 -2
- package/dist/checks/index.d.ts +1 -1
- package/dist/cli/index.js +622 -336
- 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-8cDpOFYi.d.ts → dataset-types-D-Fsbg8B.d.ts} +5 -0
- package/dist/index.d.ts +517 -121
- package/dist/index.js +29 -10
- package/dist/ingest.d.ts +119 -0
- package/dist/ingest.js +3 -0
- package/dist/{trace-event-ingestor-DwI1hxGX.js → local-database-trace-provider-87-WGqfS.js} +1795 -1086
- package/dist/{trace-BlnjMp7o.d.ts → trace-BLjFYF9G.d.ts} +1 -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 +2 -2
- package/dist/views/react/index.d.ts +1 -1
- package/package.json +23 -24
- package/dist/client/assets/index-BGcZZetP.css +0 -32
package/dist/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as promptIdOf, Ct as registerFreshImportHook, D as DEFAULT_QUERY_TIMEOUT_MS, E as DEFAULT_MAX_QUERY_ROWS, F as DatasetNotFoundError, I as DatasetValidationError, L as DEFAULT_EVAL_CONCURRENCY, O as SqlQueryError, R as EvalRunRefusedError, S as VariationConflictError, St as isFreshImportHookRegistered, T as EvalNotFoundError, _ as assertSqliteFile, _t as isStandardSchema, a as CloudTraceProvider, at as collectInputSlots, b as rollupSpans, bt as isVariationLoaderHookRegistered, c as LocalEvalProvider, d as runEvalMigrations, dt as DEFAULT_PLAYGROUND_INCLUDE_PATTERNS, f as LocalDirectoryDatasetProvider, ft as ResourceRegistry, g as runMigrations, gt as isResource, h as MIGRATIONS_TABLE, ht as isValidInstanceName, i as BaseTraceProvider, it as stampReceipts, l as openLocalEvalProvider, lt as namedBindings, m as runDatasetMigrations, mt as resourceParameterNames, n as TursoTraceProvider, nt as resolveExecutionInput, o as WorkspaceSync, ot as findInputCycle, p as TursoDatasetProvider, pt as parameterDetails, r as TRACE_QUERY_SCHEMA, rt as resolveExecutionInputs, s as DatabaseSync, st as inputReferenceProblems, t as LocalDatabaseTraceProvider, tt as matchSourcesToSlots, u as TursoEvalProvider, ut as DEFAULT_PLAYGROUND_IGNORE_PATTERNS, v as createLocalTursoClient, vt as resource, w as toPromptRef, xt as registerVariationLoaderHook, y as mkdirSelfIgnoring, yt as LocalFileProvider, z as EvalRunner } from "./local-database-trace-provider-87-WGqfS.js";
|
|
2
2
|
import { _ as isCheck, g as check, n as builtinCheck, r as builtinCheckInfos } from "./checks-Cq97JU-h.js";
|
|
3
|
+
import { a as readKind, c as normalizeOtlpRequest, f as shortId, i as mapStatus, l as isEditable, n as OtlpTraceIngestor, o as mergeSpans, r as llmAndPrompt, s as decodeOtlpProtobuf, t as TraceEventIngestor } from "./trace-event-ingestor-B1DYEg2H.js";
|
|
3
4
|
import "node:module";
|
|
4
5
|
import path, { dirname } from "node:path";
|
|
5
6
|
import { access, realpath } from "node:fs/promises";
|
|
@@ -7,12 +8,12 @@ import { minimatch } from "minimatch";
|
|
|
7
8
|
import { createHash } from "node:crypto";
|
|
8
9
|
import { SpanStatusCode } from "@opentelemetry/api";
|
|
9
10
|
import { addProperty, buildPropTypeFromType, extractPropertiesFromObjectLiteral, extractPropertiesFromParameters, isOpaqueType, removeProperty, resolveBindings, updateProperty } from "ts-proppy";
|
|
10
|
-
import { BaseTraceIngestor, BaseTraceIngestor as BaseTraceIngestor$1, CHECK_ATTRIBUTE, DEPLOYMENT_ENVIRONMENT_ATTRIBUTE, Evalution, HttpTraceSink, PLAYGROUND_ENVIRONMENT, PLAYGROUND_RESOURCE, PROMPT_ID_ATTRIBUTE, PROMPT_INPUTS_ATTRIBUTE, PROMPT_NAME_ATTRIBUTE, PROMPT_PROVIDER_ID_ATTRIBUTE, PROMPT_VARIATION_ATTRIBUTE, PROMPT_VERSION_ATTRIBUTE, SERVICE_NAME_ATTRIBUTE, SPAN_KIND_ATTRIBUTE, TRACE_EVENTS_PATH, createTracerForPrompt, getPromptSpanAttributes, isCheckSpan, mergePromptIdentity, spanMessages } from "@evalution/sdk";
|
|
11
|
+
import { BaseTraceIngestor, BaseTraceIngestor as BaseTraceIngestor$1, CHECK_ATTRIBUTE, DEPLOYMENT_ENVIRONMENT_ATTRIBUTE, Evalution, HttpTraceSink, PLAYGROUND_ENVIRONMENT, PLAYGROUND_RESOURCE, PROMPT_ID_ATTRIBUTE, PROMPT_INPUTS_ATTRIBUTE, PROMPT_NAME_ATTRIBUTE, PROMPT_PROVIDER_ID_ATTRIBUTE, PROMPT_VARIATION_ATTRIBUTE, PROMPT_VERSION_ATTRIBUTE, SERVICE_NAME_ATTRIBUTE, SPAN_KIND_ATTRIBUTE, TRACE_EVENTS_PATH, createTracerForPrompt, filterTraces, getPromptSpanAttributes, isCheckSpan, mergePromptIdentity, spanMessages } from "@evalution/sdk";
|
|
12
|
+
import ts from "typescript";
|
|
11
13
|
import { spawn } from "node:child_process";
|
|
12
14
|
import { drizzle } from "drizzle-orm/tursodatabase-sync";
|
|
13
15
|
import { and, asc, desc, eq, inArray, or, sql } from "drizzle-orm";
|
|
14
16
|
import { integer, primaryKey, real, sqliteTable, text, uniqueIndex } from "drizzle-orm/sqlite-core";
|
|
15
|
-
import ts from "typescript";
|
|
16
17
|
import { assertUpdateStyle } from "@evalution/sdk/adapter";
|
|
17
18
|
//#region \0rolldown/runtime.js
|
|
18
19
|
var __defProp = Object.defineProperty;
|
|
@@ -1575,10 +1576,25 @@ const FALLBACK_OPTIONS = {
|
|
|
1575
1576
|
};
|
|
1576
1577
|
/** Parsed declaration files that are stable for the lifetime of the process. */
|
|
1577
1578
|
const immutableSourceFiles = /* @__PURE__ */ new Map();
|
|
1578
|
-
|
|
1579
|
+
/**
|
|
1580
|
+
* Where TypeScript's own `lib.*.d.ts` files are, once asked for, or `null`
|
|
1581
|
+
* where TypeScript can't say. It can't outside Node, where it throws: this
|
|
1582
|
+
* module also runs in the marketing site's in-browser demo, so it isn't asked
|
|
1583
|
+
* at module scope.
|
|
1584
|
+
*/
|
|
1585
|
+
let tsLibDir;
|
|
1586
|
+
function libDir() {
|
|
1587
|
+
if (tsLibDir === void 0) try {
|
|
1588
|
+
tsLibDir = path.dirname(ts.getDefaultLibFilePath({}));
|
|
1589
|
+
} catch {
|
|
1590
|
+
tsLibDir = null;
|
|
1591
|
+
}
|
|
1592
|
+
return tsLibDir;
|
|
1593
|
+
}
|
|
1579
1594
|
/** Whether `fileName` names a file that will not change while we run. */
|
|
1580
1595
|
function isImmutable(fileName) {
|
|
1581
|
-
|
|
1596
|
+
const lib = libDir();
|
|
1597
|
+
return lib !== null && fileName.startsWith(lib) || fileName.includes("/node_modules/");
|
|
1582
1598
|
}
|
|
1583
1599
|
/**
|
|
1584
1600
|
* Load the compiler options from the nearest `tsconfig.json` at or above
|
|
@@ -1586,6 +1602,7 @@ function isImmutable(fileName) {
|
|
|
1586
1602
|
* `moduleResolution` settings resolve the way they do for the user's own build.
|
|
1587
1603
|
*/
|
|
1588
1604
|
function compilerOptionsFor(fromPath) {
|
|
1605
|
+
if (!ts.sys) return FALLBACK_OPTIONS;
|
|
1589
1606
|
const configPath = ts.findConfigFile(path.dirname(fromPath), ts.sys.fileExists);
|
|
1590
1607
|
if (!configPath) return FALLBACK_OPTIONS;
|
|
1591
1608
|
const { config, error } = ts.readConfigFile(configPath, ts.sys.readFile);
|
|
@@ -2205,6 +2222,8 @@ function moduleFingerprint(rootDir, probes) {
|
|
|
2205
2222
|
for (const module of probe.modules) specifiers.add(module);
|
|
2206
2223
|
addImports(probe.produces);
|
|
2207
2224
|
}
|
|
2225
|
+
const { sys } = ts;
|
|
2226
|
+
if (!sys) return "";
|
|
2208
2227
|
const parts = [];
|
|
2209
2228
|
for (const specifier of [...specifiers].sort()) {
|
|
2210
2229
|
if (specifier.startsWith(".")) continue;
|
|
@@ -2213,8 +2232,8 @@ function moduleFingerprint(rootDir, probes) {
|
|
|
2213
2232
|
let found = "missing";
|
|
2214
2233
|
for (let dir = rootDir;; dir = path.dirname(dir)) {
|
|
2215
2234
|
const manifest = path.join(dir, "node_modules", pkg, "package.json");
|
|
2216
|
-
if (
|
|
2217
|
-
found = `${manifest}@${
|
|
2235
|
+
if (sys.fileExists(manifest)) {
|
|
2236
|
+
found = `${manifest}@${sys.getModifiedTime?.(manifest)?.getTime() ?? 0}`;
|
|
2218
2237
|
break;
|
|
2219
2238
|
}
|
|
2220
2239
|
if (path.dirname(dir) === dir) break;
|
|
@@ -3971,7 +3990,7 @@ var MemoryTraceProvider = class extends BaseTraceProvider {
|
|
|
3971
3990
|
description
|
|
3972
3991
|
});
|
|
3973
3992
|
}
|
|
3974
|
-
async getAllTraces() {
|
|
3993
|
+
async getAllTraces(query) {
|
|
3975
3994
|
const summaries = Array.from(this.traces.values()).map((t) => {
|
|
3976
3995
|
const spans = this.spansByTrace.get(t.id) ?? [];
|
|
3977
3996
|
return {
|
|
@@ -3991,7 +4010,7 @@ var MemoryTraceProvider = class extends BaseTraceProvider {
|
|
|
3991
4010
|
};
|
|
3992
4011
|
});
|
|
3993
4012
|
summaries.sort((a, b) => b.startTime - a.startTime);
|
|
3994
|
-
return summaries;
|
|
4013
|
+
return filterTraces(summaries, query);
|
|
3995
4014
|
}
|
|
3996
4015
|
async hasTrace(traceId) {
|
|
3997
4016
|
return this.traces.has(traceId);
|
|
@@ -4026,4 +4045,4 @@ var MemoryTraceProvider = class extends BaseTraceProvider {
|
|
|
4026
4045
|
}
|
|
4027
4046
|
};
|
|
4028
4047
|
//#endregion
|
|
4029
|
-
export { BaseTraceIngestor, BaseTraceProvider, CHECK_ATTRIBUTE, DEFAULT_EVAL_CONCURRENCY, DEFAULT_MAX_QUERY_ROWS, DEFAULT_PLAYGROUND_IGNORE_PATTERNS, DEFAULT_PLAYGROUND_INCLUDE_PATTERNS, DEFAULT_QUERY_TIMEOUT_MS, DEPLOYMENT_ENVIRONMENT_ATTRIBUTE, DatasetNotFoundError, DatasetValidationError, EvalNotFoundError, EvalRunRefusedError, EvalRunner, Evalution, FilePromptProvider, GitVersioning, HttpTraceSink, LocalDatabaseTraceProvider, LocalDirectoryDatasetProvider, LocalEvalProvider, LocalFileProvider, LocalVariationStore, MIGRATIONS_TABLE, MemoryFileProvider, MemoryTraceProvider, OTelTraceIngestor, OtlpTraceIngestor, OverlayFileProvider, PLAYGROUND_ENVIRONMENT, PLAYGROUND_RESOURCE, PROMPT_FIELD, PROMPT_ID_ATTRIBUTE, PROMPT_INPUTS_ATTRIBUTE, PROMPT_NAME_ATTRIBUTE, PROMPT_PROVIDER_ID_ATTRIBUTE, PROMPT_VARIATION_ATTRIBUTE, PROMPT_VERSION_ATTRIBUTE, ResourceRegistry, SERVICE_NAME_ATTRIBUTE, SPAN_KIND_ATTRIBUTE, SqlQueryError, TRACE_EVENTS_PATH, TRACE_QUERY_SCHEMA, TSPromptFileType, TraceEventIngestor, TursoDatasetProvider, TursoEvalProvider, TursoTraceProvider, TursoVariationStore, VariationConflictError, assertUpdateStyle, canonicalizeUpdates, check, collectInputSlots, createLocalTursoClient, createTracerForPrompt, decodeOtlpProtobuf, fieldValuesOf, findInputCycle, getPromptSpanAttributes, inputReferenceProblems, isCheck, isCheckSpan, isFreshImportHookRegistered, isResource, isStandardSchema, isValidInstanceName, isVariationLoaderHookRegistered, matchSourcesToSlots, mergeIntoWip, mergePromptIdentity, mergeSpans, mergeUpdates, namedBindings, normalizeOtlpRequest, openLocalEvalProvider, openLocalVariationStore, promptIdOf, rebaseUpdates, registerFreshImportHook, registerVariationLoaderHook, resolveConflicts, resolveExecutionInput, resolveExecutionInputs, resource, resourceParameterNames, runDatasetMigrations, runEvalMigrations, runMigrations, runVariationMigrations, serializeUpdates, setupGlobalOTelPipeline, spanMessages, stampReceipts, toPromptRef };
|
|
4048
|
+
export { BaseTraceIngestor, BaseTraceProvider, CHECK_ATTRIBUTE, CloudTraceProvider, DEFAULT_EVAL_CONCURRENCY, DEFAULT_MAX_QUERY_ROWS, DEFAULT_PLAYGROUND_IGNORE_PATTERNS, DEFAULT_PLAYGROUND_INCLUDE_PATTERNS, DEFAULT_QUERY_TIMEOUT_MS, DEPLOYMENT_ENVIRONMENT_ATTRIBUTE, DatabaseSync, DatasetNotFoundError, DatasetValidationError, EvalNotFoundError, EvalRunRefusedError, EvalRunner, Evalution, FilePromptProvider, GitVersioning, HttpTraceSink, LocalDatabaseTraceProvider, LocalDirectoryDatasetProvider, LocalEvalProvider, LocalFileProvider, LocalVariationStore, MIGRATIONS_TABLE, MemoryFileProvider, MemoryTraceProvider, OTelTraceIngestor, OtlpTraceIngestor, OverlayFileProvider, PLAYGROUND_ENVIRONMENT, PLAYGROUND_RESOURCE, PROMPT_FIELD, PROMPT_ID_ATTRIBUTE, PROMPT_INPUTS_ATTRIBUTE, PROMPT_NAME_ATTRIBUTE, PROMPT_PROVIDER_ID_ATTRIBUTE, PROMPT_VARIATION_ATTRIBUTE, PROMPT_VERSION_ATTRIBUTE, ResourceRegistry, SERVICE_NAME_ATTRIBUTE, SPAN_KIND_ATTRIBUTE, SqlQueryError, TRACE_EVENTS_PATH, TRACE_QUERY_SCHEMA, TSPromptFileType, TraceEventIngestor, TursoDatasetProvider, TursoEvalProvider, TursoTraceProvider, TursoVariationStore, VariationConflictError, WorkspaceSync, assertUpdateStyle, canonicalizeUpdates, check, collectInputSlots, createLocalTursoClient, createTracerForPrompt, decodeOtlpProtobuf, fieldValuesOf, findInputCycle, getPromptSpanAttributes, inputReferenceProblems, isCheck, isCheckSpan, isFreshImportHookRegistered, isResource, isStandardSchema, isValidInstanceName, isVariationLoaderHookRegistered, matchSourcesToSlots, mergeIntoWip, mergePromptIdentity, mergeSpans, mergeUpdates, namedBindings, normalizeOtlpRequest, openLocalEvalProvider, openLocalVariationStore, promptIdOf, rebaseUpdates, registerFreshImportHook, registerVariationLoaderHook, resolveConflicts, resolveExecutionInput, resolveExecutionInputs, resource, resourceParameterNames, runDatasetMigrations, runEvalMigrations, runMigrations, runVariationMigrations, serializeUpdates, setupGlobalOTelPipeline, spanMessages, stampReceipts, toPromptRef };
|
package/dist/ingest.d.ts
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { a as NormalizedOtlpEvent, i as decodeOtlpProtobuf, n as mergeSpans, o as NormalizedOtlpSpan, r as OtlpTraceIngestor, s as normalizeOtlpRequest, t as TraceEventIngestor } from "./trace-event-ingestor-JNpe-OrX.js";
|
|
2
|
+
import { Span, TraceSink } from "@evalution/sdk";
|
|
3
|
+
|
|
4
|
+
//#region src/server/handlers/otlp-ingest.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Placeholder for cloud auth context. OSS has none; a cloud host's
|
|
7
|
+
* `resolveIngestor` narrows this to whatever it derives from the request's
|
|
8
|
+
* API key (project + environment). Kept as an extension point so
|
|
9
|
+
* {@link OtlpIngestDeps} doesn't need to change shape when cloud adds it.
|
|
10
|
+
*/
|
|
11
|
+
type AuthCtx = Record<string, unknown>;
|
|
12
|
+
/** What {@link handleOtlpTraces} needs from its host. */
|
|
13
|
+
interface OtlpIngestDeps {
|
|
14
|
+
/**
|
|
15
|
+
* Picks which {@link OtlpTraceIngestor} a batch should be recorded through.
|
|
16
|
+
* OSS resolves this to "the process's single ingestor" (optionally keying
|
|
17
|
+
* off an `x-evalution-provider` header when more than one trace provider is
|
|
18
|
+
* configured); a cloud host keys off `ctx.auth` instead. Returns `undefined`
|
|
19
|
+
* when nothing matches, in which case the request is rejected — this
|
|
20
|
+
* handler never guesses a target.
|
|
21
|
+
*/
|
|
22
|
+
resolveIngestor(ctx: {
|
|
23
|
+
headers: Record<string, string>;
|
|
24
|
+
auth?: AuthCtx;
|
|
25
|
+
}): OtlpTraceIngestor | undefined;
|
|
26
|
+
}
|
|
27
|
+
/** One OTLP export request, as {@link handleOtlpTraces} takes it. */
|
|
28
|
+
interface OtlpIngestRequest {
|
|
29
|
+
/** The request's `content-type` header, e.g. `application/x-protobuf`. */
|
|
30
|
+
contentType: string;
|
|
31
|
+
/** The request body, decompressed. */
|
|
32
|
+
body: ArrayBuffer;
|
|
33
|
+
/** The request's headers, with lowercase names. */
|
|
34
|
+
headers: Record<string, string>;
|
|
35
|
+
/** What the host authenticated the request as, if it did. */
|
|
36
|
+
auth?: AuthCtx;
|
|
37
|
+
}
|
|
38
|
+
/** What {@link handleOtlpTraces} answers: an HTTP status and a JSON body. */
|
|
39
|
+
interface OtlpIngestResult {
|
|
40
|
+
status: number;
|
|
41
|
+
body: unknown;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Host-neutral handler for an OTLP trace export request (`POST /v1/traces`).
|
|
45
|
+
* Decodes protobuf or JSON, normalizes to `NormalizedOtlpSpan[]`, and hands
|
|
46
|
+
* the batch to whichever {@link OtlpTraceIngestor} {@link OtlpIngestDeps.resolveIngestor}
|
|
47
|
+
* picks. Takes and returns plain data (`ArrayBuffer` + headers, `{status,
|
|
48
|
+
* body}`) rather than a framework `Request`/`Response` so it stays usable
|
|
49
|
+
* from Hono, a Worker, or a test — no `Buffer`, no `fs`, no `process`.
|
|
50
|
+
*/
|
|
51
|
+
declare function handleOtlpTraces(req: OtlpIngestRequest, deps: OtlpIngestDeps): Promise<OtlpIngestResult>;
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/server/handlers/trace-events-ingest.d.ts
|
|
54
|
+
/** What {@link handleTraceEvents} answers: an HTTP status and a JSON body. */
|
|
55
|
+
interface TraceEventsIngestResult {
|
|
56
|
+
status: number;
|
|
57
|
+
body: unknown;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Host-neutral handler for a batch of trace events an app's `HttpTraceSink`
|
|
61
|
+
* sends (`POST /api/traces`). Takes the request body as text and
|
|
62
|
+
* returns plain `{status, body}`, like `handleOtlpTraces`, so it stays usable
|
|
63
|
+
* from Hono, a Worker, or a test.
|
|
64
|
+
*/
|
|
65
|
+
declare function handleTraceEvents(body: string, ingestor: TraceEventIngestor | undefined): Promise<TraceEventsIngestResult>;
|
|
66
|
+
//#endregion
|
|
67
|
+
//#region src/trace/cost-fetching-trace-sink.d.ts
|
|
68
|
+
/** Options for {@link CostFetchingTraceSink}. */
|
|
69
|
+
interface CostFetchingTraceSinkOptions {
|
|
70
|
+
/**
|
|
71
|
+
* Override for the global `fetch`, so tests can inject a mock instead of
|
|
72
|
+
* hitting the network. Defaults to the global `fetch`.
|
|
73
|
+
*/
|
|
74
|
+
fetch?: typeof fetch;
|
|
75
|
+
/**
|
|
76
|
+
* Whether to fetch pricing (and so stamp costs) at all. When `false`, spans
|
|
77
|
+
* pass through untouched and no request is ever made. Defaults to `true`
|
|
78
|
+
* unless the `EVALUTION_NO_COST_ESTIMATES` environment variable is set.
|
|
79
|
+
*/
|
|
80
|
+
fetchPricing?: boolean;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* A {@link TraceSink} that stamps `llm.cost` onto LLM spans with known token
|
|
84
|
+
* usage, then fans the span out to its own registered downstream sinks.
|
|
85
|
+
*
|
|
86
|
+
* Pricing is fetched once, lazily on the first relevant span, from Vercel AI
|
|
87
|
+
* Gateway's public model catalog — or, if that request fails, from
|
|
88
|
+
* OpenRouter's — and cached in memory for the life of the instance. Cache
|
|
89
|
+
* reads and writes are billed at the catalog's cache prices where it lists
|
|
90
|
+
* them. A fetch failure (or an offline environment) is logged to the console
|
|
91
|
+
* but never thrown at the caller; costs just don't get stamped.
|
|
92
|
+
*/
|
|
93
|
+
declare class CostFetchingTraceSink implements TraceSink {
|
|
94
|
+
private readonly fetchImpl;
|
|
95
|
+
private readonly fetchPricing;
|
|
96
|
+
private readonly sinks;
|
|
97
|
+
private prices;
|
|
98
|
+
constructor(options?: CostFetchingTraceSinkOptions);
|
|
99
|
+
/** Add a downstream sink. May be called multiple times. */
|
|
100
|
+
addSink(sink: TraceSink): void;
|
|
101
|
+
/**
|
|
102
|
+
* Remove a previously-added sink. Returns `true` if the given sink was
|
|
103
|
+
* found and removed, otherwise `false`.
|
|
104
|
+
*/
|
|
105
|
+
removeSink(sink: TraceSink): boolean;
|
|
106
|
+
recordSpanStart(span: Span): Promise<Span>;
|
|
107
|
+
recordSpanEnd(span: Span): Promise<Span>;
|
|
108
|
+
failTrace(traceId: string, errorMessage: string): Promise<void>;
|
|
109
|
+
private withCost;
|
|
110
|
+
private fetchPrices;
|
|
111
|
+
/**
|
|
112
|
+
* Fetches and parses one model catalog. Returns `undefined` if the request
|
|
113
|
+
* fails, so the caller can fall back to another — never throws for the
|
|
114
|
+
* caller over this.
|
|
115
|
+
*/
|
|
116
|
+
private fetchCatalog;
|
|
117
|
+
}
|
|
118
|
+
//#endregion
|
|
119
|
+
export { type AuthCtx, CostFetchingTraceSink, type CostFetchingTraceSinkOptions, type NormalizedOtlpEvent, type NormalizedOtlpSpan, type OtlpIngestDeps, type OtlpIngestRequest, type OtlpIngestResult, OtlpTraceIngestor, TraceEventIngestor, type TraceEventsIngestResult, decodeOtlpProtobuf, handleOtlpTraces, handleTraceEvents, mergeSpans, normalizeOtlpRequest };
|
package/dist/ingest.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { c as normalizeOtlpRequest, n as OtlpTraceIngestor, o as mergeSpans, s as decodeOtlpProtobuf, t as TraceEventIngestor } from "./trace-event-ingestor-B1DYEg2H.js";
|
|
2
|
+
import { n as handleTraceEvents, r as handleOtlpTraces, t as CostFetchingTraceSink } from "./cost-fetching-trace-sink-Dz8gniQ6.js";
|
|
3
|
+
export { CostFetchingTraceSink, OtlpTraceIngestor, TraceEventIngestor, decodeOtlpProtobuf, handleOtlpTraces, handleTraceEvents, mergeSpans, normalizeOtlpRequest };
|