evalution 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSING.md +16 -6
- package/dist/cli/index.js +40 -31
- package/dist/client/assets/{index-C4XXh0na.js → index-BAk2IWAg.js} +34 -34
- package/dist/client/index.html +1 -1
- package/dist/index.d.ts +552 -313
- package/dist/index.js +56 -25
- package/dist/{vercel-ai-sdk-B8ivuOzP.js → vercel-ai-sdk-JhQ1efcg.js} +594 -211
- package/package.json +21 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { AttributeValue, Attributes, Tracer } from "@opentelemetry/api";
|
|
2
|
-
import { SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
3
2
|
import { CalleeBinding, ExtractedProps, PropDefinition, PropDefinition as PropDefinition$1, PropValue, PropValue as PropValue$1, SourceSpan } from "ts-proppy";
|
|
4
|
-
import {
|
|
3
|
+
import { Telemetry } from "ai";
|
|
4
|
+
import { SpanProcessor } from "@opentelemetry/sdk-trace-base";
|
|
5
5
|
|
|
6
|
-
//#region src/
|
|
6
|
+
//#region src/trace/trace-types.d.ts
|
|
7
7
|
/**
|
|
8
8
|
* A reference to a prompt.
|
|
9
9
|
*
|
|
@@ -17,7 +17,135 @@ interface PromptID {
|
|
|
17
17
|
id: string;
|
|
18
18
|
/** When set, {@link id} is scoped to this prompt provider. */
|
|
19
19
|
providerId?: string;
|
|
20
|
+
/** Positional arguments the prompt function was called with. */
|
|
21
|
+
functionParameters?: unknown[];
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Classification of a {@link Span}. See also:
|
|
25
|
+
* - `lmnr.span.type` from https://laminar.sh/docs/tracing/otel
|
|
26
|
+
* - `mlflow.spanType` from https://mlflow.org/docs/latest/genai/tracing/opentelemetry/attribute-mapping/#translated-span-attributes
|
|
27
|
+
*
|
|
28
|
+
* Mapped from `gen_ai.operation.name`.
|
|
29
|
+
*/
|
|
30
|
+
type SpanKind = "LLM" | "TOOL" | "AGENT" | "EMBEDDING" | "DEFAULT";
|
|
31
|
+
/** A single message within an LLM span's input/output. */
|
|
32
|
+
interface SpanMessage {
|
|
33
|
+
role: string;
|
|
34
|
+
content: string;
|
|
35
|
+
}
|
|
36
|
+
/** LLM-specific attributes attached to `LLM` spans. */
|
|
37
|
+
interface LLMSpanDetails {
|
|
38
|
+
provider?: string;
|
|
39
|
+
model?: string;
|
|
40
|
+
/** Model parameters (temperature, max_tokens, …). */
|
|
41
|
+
modelParameters?: Record<string, unknown>;
|
|
42
|
+
messages?: SpanMessage[];
|
|
43
|
+
output?: string;
|
|
44
|
+
promptTokens?: number;
|
|
45
|
+
completionTokens?: number;
|
|
46
|
+
totalTokens?: number;
|
|
47
|
+
/** Dollar cost of the call, if known. */
|
|
48
|
+
cost?: number;
|
|
49
|
+
}
|
|
50
|
+
interface ToolSpanDetails {
|
|
51
|
+
toolName: string;
|
|
52
|
+
input: unknown;
|
|
53
|
+
output?: unknown;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* A span in a {@link Trace}. Spans form a tree via {@link parentId}.
|
|
57
|
+
* Durations are derived from `startTime` and `endTime`; an in-progress span has
|
|
58
|
+
* no `endTime` yet.
|
|
59
|
+
*/
|
|
60
|
+
interface Span {
|
|
61
|
+
id: string;
|
|
62
|
+
traceId: string;
|
|
63
|
+
/** `undefined` for the root span of the trace. */
|
|
64
|
+
parentId?: string;
|
|
65
|
+
name: string;
|
|
66
|
+
kind: SpanKind;
|
|
67
|
+
/** Start timestamp in milliseconds since epoch. */
|
|
68
|
+
startTime: number;
|
|
69
|
+
/** End timestamp in milliseconds since epoch, or `undefined` while running. */
|
|
70
|
+
endTime?: number;
|
|
71
|
+
status?: "ok" | "error";
|
|
72
|
+
/** Error message if `status` is `'error'`. */
|
|
73
|
+
errorMessage?: string;
|
|
74
|
+
/** Free-form attributes to show in the span's details pane. */
|
|
75
|
+
attributes?: Record<string, unknown>;
|
|
76
|
+
/** LLM-specific details (present for `chat`/`completion`/`embedding` spans). */
|
|
77
|
+
llm?: LLMSpanDetails;
|
|
78
|
+
/**
|
|
79
|
+
* The prompt this span is attributed to, if any.
|
|
80
|
+
*
|
|
81
|
+
* Stored as emitted (`evalution.prompt.id` plus optional
|
|
82
|
+
* `evalution.prompt.provider.id`): a {@link PromptID} whose `id` is global
|
|
83
|
+
* unless `providerId` is set. The server resolves it against the prompt
|
|
84
|
+
* registry to a provider-scoped reference when a trace is served.
|
|
85
|
+
*/
|
|
86
|
+
prompt?: PromptID;
|
|
87
|
+
tool?: ToolSpanDetails;
|
|
88
|
+
}
|
|
89
|
+
interface TraceBase {
|
|
90
|
+
id: string;
|
|
91
|
+
providerId?: string;
|
|
92
|
+
name: string;
|
|
93
|
+
/** Start timestamp (ms). */
|
|
94
|
+
startTime: number;
|
|
95
|
+
/** End timestamp (ms), or `undefined` while the trace is still running. */
|
|
96
|
+
endTime?: number;
|
|
97
|
+
status: "running" | "ok" | "error";
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Top-level trace for a single invocation (e.g. one prompt execution).
|
|
101
|
+
*/
|
|
102
|
+
interface Trace extends TraceBase {
|
|
103
|
+
/** Free-form attributes (e.g. prompt ID, function params). */
|
|
104
|
+
attributes?: Record<string, unknown>;
|
|
105
|
+
}
|
|
106
|
+
/** Compact trace entry for listings (sidebar / `GET /api/traces`). */
|
|
107
|
+
interface TraceSummary extends TraceBase {
|
|
108
|
+
providerId: string;
|
|
109
|
+
/** Number of spans currently associated with the trace. */
|
|
110
|
+
spanCount: number;
|
|
111
|
+
}
|
|
112
|
+
/** A trace together with all of its spans. */
|
|
113
|
+
interface TraceWithSpans {
|
|
114
|
+
trace: Trace;
|
|
115
|
+
spans: Span[];
|
|
20
116
|
}
|
|
117
|
+
/** The kind of change that occurred to a trace. */
|
|
118
|
+
type TraceChangeType = "add" | "update" | "remove";
|
|
119
|
+
/** Describes a single change emitted by `TraceProvider.watch`. */
|
|
120
|
+
interface TraceChangeEvent {
|
|
121
|
+
type: TraceChangeType;
|
|
122
|
+
traceId: string;
|
|
123
|
+
}
|
|
124
|
+
/** Real-time event pushed over the per-trace SSE subscription. */
|
|
125
|
+
type TraceStreamEvent = {
|
|
126
|
+
type: "span-start";
|
|
127
|
+
span: Span;
|
|
128
|
+
} | {
|
|
129
|
+
type: "span-end";
|
|
130
|
+
span: Span;
|
|
131
|
+
} | {
|
|
132
|
+
type: "span-update";
|
|
133
|
+
span: Span;
|
|
134
|
+
} | {
|
|
135
|
+
type: "trace-update";
|
|
136
|
+
trace: Trace;
|
|
137
|
+
} | {
|
|
138
|
+
type: "trace-end";
|
|
139
|
+
trace: Trace;
|
|
140
|
+
};
|
|
141
|
+
/** Information about a registered trace provider, returned by `GET /api/trace-providers`. */
|
|
142
|
+
interface TraceProviderInfo {
|
|
143
|
+
id: string;
|
|
144
|
+
displayName?: string;
|
|
145
|
+
description?: string;
|
|
146
|
+
}
|
|
147
|
+
//#endregion
|
|
148
|
+
//#region src/shared/types.d.ts
|
|
21
149
|
/**
|
|
22
150
|
* Low-level prompt representation produced by a
|
|
23
151
|
* {@link PromptFileType}. It exposes the raw `extractedProps` from the parser
|
|
@@ -205,127 +333,6 @@ interface ExecuteResponse {
|
|
|
205
333
|
/** Span ID of the root span for this execution. */
|
|
206
334
|
rootSpanId: string;
|
|
207
335
|
}
|
|
208
|
-
/**
|
|
209
|
-
* Classification of a {@link Span}. See also:
|
|
210
|
-
* - `lmnr.span.type` from https://laminar.sh/docs/tracing/otel
|
|
211
|
-
* - `mlflow.spanType` from https://mlflow.org/docs/latest/genai/tracing/opentelemetry/attribute-mapping/#translated-span-attributes
|
|
212
|
-
*
|
|
213
|
-
* Mapped from `gen_ai.operation.name`.
|
|
214
|
-
*/
|
|
215
|
-
type SpanKind = "LLM" | "TOOL" | "AGENT" | "EMBEDDING" | "DEFAULT";
|
|
216
|
-
/** A single message within an LLM span's input/output. */
|
|
217
|
-
interface SpanMessage {
|
|
218
|
-
role: string;
|
|
219
|
-
content: string;
|
|
220
|
-
}
|
|
221
|
-
/** LLM-specific attributes attached to `LLM` spans. */
|
|
222
|
-
interface LLMSpanDetails {
|
|
223
|
-
provider?: string;
|
|
224
|
-
model?: string;
|
|
225
|
-
messages?: SpanMessage[];
|
|
226
|
-
output?: string;
|
|
227
|
-
promptTokens?: number;
|
|
228
|
-
completionTokens?: number;
|
|
229
|
-
totalTokens?: number;
|
|
230
|
-
/** Dollar cost of the call, if known. */
|
|
231
|
-
cost?: number;
|
|
232
|
-
/** Model parameters (temperature, max_tokens, …). */
|
|
233
|
-
modelParameters?: Record<string, unknown>;
|
|
234
|
-
}
|
|
235
|
-
/**
|
|
236
|
-
* A span in a {@link Trace}. Spans form a tree via {@link parentId}.
|
|
237
|
-
* Durations are derived from `startTime` and `endTime`; an in-progress span has
|
|
238
|
-
* no `endTime` yet.
|
|
239
|
-
*/
|
|
240
|
-
interface Span {
|
|
241
|
-
id: string;
|
|
242
|
-
traceId: string;
|
|
243
|
-
/** `undefined` for the root span of the trace. */
|
|
244
|
-
parentId?: string;
|
|
245
|
-
name: string;
|
|
246
|
-
kind: SpanKind;
|
|
247
|
-
/** Start timestamp in milliseconds since epoch. */
|
|
248
|
-
startTime: number;
|
|
249
|
-
/** End timestamp in milliseconds since epoch, or `undefined` while running. */
|
|
250
|
-
endTime?: number;
|
|
251
|
-
status?: "ok" | "error";
|
|
252
|
-
/** Error message if `status` is `'error'`. */
|
|
253
|
-
errorMessage?: string;
|
|
254
|
-
/** Free-form attributes to show in the span's details pane. */
|
|
255
|
-
attributes?: Record<string, unknown>;
|
|
256
|
-
/** LLM-specific details (present for `chat`/`completion`/`embedding` spans). */
|
|
257
|
-
llm?: LLMSpanDetails;
|
|
258
|
-
/**
|
|
259
|
-
* The prompt this span is attributed to, if any.
|
|
260
|
-
*
|
|
261
|
-
* Stored as emitted (`evalution.prompt.id` plus optional
|
|
262
|
-
* `evalution.prompt.provider.id`): a {@link PromptID} whose `id` is global
|
|
263
|
-
* unless `providerId` is set. The server resolves it against the prompt
|
|
264
|
-
* registry to a provider-scoped reference when a trace is served.
|
|
265
|
-
*/
|
|
266
|
-
prompt?: PromptID;
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Top-level trace for a single invocation (e.g. one prompt execution).
|
|
270
|
-
*/
|
|
271
|
-
interface Trace {
|
|
272
|
-
id: string;
|
|
273
|
-
providerId?: string;
|
|
274
|
-
name: string;
|
|
275
|
-
/** Start timestamp (ms). */
|
|
276
|
-
startTime: number;
|
|
277
|
-
/** End timestamp (ms), or `undefined` while the trace is still running. */
|
|
278
|
-
endTime?: number;
|
|
279
|
-
status: "running" | "ok" | "error";
|
|
280
|
-
/** Free-form attributes (e.g. prompt ID, function params). */
|
|
281
|
-
attributes?: Record<string, unknown>;
|
|
282
|
-
}
|
|
283
|
-
/** Compact trace entry for listings (sidebar / `GET /api/traces`). */
|
|
284
|
-
interface TraceSummary {
|
|
285
|
-
id: string;
|
|
286
|
-
providerId: string;
|
|
287
|
-
name: string;
|
|
288
|
-
startTime: number;
|
|
289
|
-
endTime?: number;
|
|
290
|
-
status: "running" | "ok" | "error";
|
|
291
|
-
/** Number of spans currently associated with the trace. */
|
|
292
|
-
spanCount: number;
|
|
293
|
-
}
|
|
294
|
-
/** A trace together with all of its spans. */
|
|
295
|
-
interface TraceWithSpans {
|
|
296
|
-
trace: Trace;
|
|
297
|
-
spans: Span[];
|
|
298
|
-
}
|
|
299
|
-
/** The kind of change that occurred to a trace. */
|
|
300
|
-
type TraceChangeType = "add" | "update" | "remove";
|
|
301
|
-
/** Describes a single change emitted by `TraceProvider.watch`. */
|
|
302
|
-
interface TraceChangeEvent {
|
|
303
|
-
type: TraceChangeType;
|
|
304
|
-
traceId: string;
|
|
305
|
-
}
|
|
306
|
-
/** Real-time event pushed over the per-trace SSE subscription. */
|
|
307
|
-
type TraceStreamEvent = {
|
|
308
|
-
type: "span-start";
|
|
309
|
-
span: Span;
|
|
310
|
-
} | {
|
|
311
|
-
type: "span-end";
|
|
312
|
-
span: Span;
|
|
313
|
-
} | {
|
|
314
|
-
type: "span-update";
|
|
315
|
-
span: Span;
|
|
316
|
-
} | {
|
|
317
|
-
type: "trace-update";
|
|
318
|
-
trace: Trace;
|
|
319
|
-
} | {
|
|
320
|
-
type: "trace-end";
|
|
321
|
-
trace: Trace;
|
|
322
|
-
};
|
|
323
|
-
/** Information about a registered trace provider, returned by `GET /api/trace-providers`. */
|
|
324
|
-
interface TraceProviderInfo {
|
|
325
|
-
id: string;
|
|
326
|
-
displayName?: string;
|
|
327
|
-
description?: string;
|
|
328
|
-
}
|
|
329
336
|
/**
|
|
330
337
|
* Catalog-only variant of {@link PropValue} where `functionCall.binding` may
|
|
331
338
|
* carry multiple candidate bindings (e.g. a parameter-destructure form *and* a
|
|
@@ -362,135 +369,42 @@ interface ModelInfo {
|
|
|
362
369
|
* Values to use when selecting this model in different modes (as defined by {@link ModelCatalog.modelValueTypes}).
|
|
363
370
|
* If a value is undefined for a particular mode, this model is not offered as a quick-select option in that mode.
|
|
364
371
|
*/
|
|
365
|
-
values: Record<string, ModelPropValue | undefined>;
|
|
366
|
-
}
|
|
367
|
-
/** Describes a model selection mode exposed by the SDK adapter (e.g. "Provider" or "Gateway"). */
|
|
368
|
-
interface ModelValueType {
|
|
369
|
-
/** Label shown in the UI toggle (e.g. "Provider", "Gateway"). */
|
|
370
|
-
readonly label: string;
|
|
371
|
-
/** Optional tooltip / helper text. */
|
|
372
|
-
readonly description?: string;
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* Per-group metadata for constructing custom model values in the UI.
|
|
376
|
-
*
|
|
377
|
-
* `customValueTemplates` is a `PropValue` template per mode. Any primitive
|
|
378
|
-
* string value containing `$input` is replaced with the user's custom model
|
|
379
|
-
* ID at runtime.
|
|
380
|
-
*/
|
|
381
|
-
interface ModelGroupInfo {
|
|
382
|
-
customValueTemplates?: Record<string, ModelPropValue>;
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* Model catalog returned by {@link SDKAdapter.getModelCatalog}.
|
|
386
|
-
* Contains the set of known providers and a curated list of models.
|
|
387
|
-
*/
|
|
388
|
-
interface ModelCatalog {
|
|
389
|
-
/** List of known models. */
|
|
390
|
-
models: readonly ModelInfo[];
|
|
391
|
-
/**
|
|
392
|
-
* Available model selection modes.
|
|
393
|
-
*
|
|
394
|
-
* When this is an object, the UI renders a toggle so the user can switch between them.
|
|
395
|
-
* The keys of this object are used in {@link ModelInfo.values}, and the values provide
|
|
396
|
-
* metadata for how to render each mode in the UI.
|
|
397
|
-
*/
|
|
398
|
-
modelValueTypes?: Record<string, ModelValueType>;
|
|
399
|
-
/** Per-group metadata for constructing custom model PropValues. Keyed by group name. */
|
|
400
|
-
groups?: Record<string, ModelGroupInfo>;
|
|
401
|
-
}
|
|
402
|
-
//#endregion
|
|
403
|
-
//#region src/prompt/prompt-provider.d.ts
|
|
404
|
-
/**
|
|
405
|
-
* A source of prompts that the playground can display and execute.
|
|
406
|
-
*
|
|
407
|
-
* Implement this interface to add a custom prompt source — for example,
|
|
408
|
-
* prompts stored in a database or fetched from a remote API. If you simply
|
|
409
|
-
* need to support a file format other than TypeScript, use {@link FilePromptProvider}
|
|
410
|
-
* with a custom {@link PromptFileType}.
|
|
411
|
-
*/
|
|
412
|
-
interface PromptProvider<TPrompt extends NormalizedPrompt = NormalizedPrompt> {
|
|
413
|
-
/** Uniquely identifies this provider when multiple providers are used. */
|
|
414
|
-
readonly id: string;
|
|
415
|
-
/** Human-readable name shown when choosing between providers. */
|
|
416
|
-
readonly displayName?: string;
|
|
417
|
-
/** Short description of what this provider offers. */
|
|
418
|
-
readonly description?: string;
|
|
419
|
-
/** SVG icon markup for this provider. */
|
|
420
|
-
readonly icon?: string;
|
|
421
|
-
/** Returns all prompts currently available from this provider. */
|
|
422
|
-
getAllPrompts(): Promise<TPrompt[]>;
|
|
423
|
-
/**
|
|
424
|
-
* Returns the prompt with the given ID, or `null` if not found.
|
|
425
|
-
* @param id - The prompt's unique identifier.
|
|
426
|
-
*/
|
|
427
|
-
getPrompt(id: string): Promise<TPrompt | null>;
|
|
428
|
-
/**
|
|
429
|
-
* Applies normalized updates to a prompt's source and returns the fresh
|
|
430
|
-
* prompt. Setting any field of `updates` to `null` removes the corresponding
|
|
431
|
-
* property from the underlying source.
|
|
432
|
-
*
|
|
433
|
-
* This method is optional; providers that do not support in-place editing
|
|
434
|
-
* may omit it.
|
|
435
|
-
*
|
|
436
|
-
* @param promptId - ID of the prompt to update.
|
|
437
|
-
* @param updates - Updates expressed in the normalized vocabulary.
|
|
438
|
-
*/
|
|
439
|
-
updatePromptProperties?(promptId: string, updates: NormalizedPromptUpdates): Promise<TPrompt>;
|
|
440
|
-
/**
|
|
441
|
-
* Executes a prompt.
|
|
442
|
-
*
|
|
443
|
-
* @param promptId - ID of the prompt to run.
|
|
444
|
-
* @param params - Positional arguments forwarded to the prompt function.
|
|
445
|
-
*/
|
|
446
|
-
execute(promptId: string, params: any[]): Promise<void>;
|
|
447
|
-
/**
|
|
448
|
-
* Returns the model catalog (known providers and popular models) for this
|
|
449
|
-
* provider's underlying SDK.
|
|
450
|
-
*
|
|
451
|
-
* Optional — providers that do not expose model info may omit it.
|
|
452
|
-
*/
|
|
453
|
-
getModelCatalog?(): Promise<ModelCatalog>;
|
|
454
|
-
/**
|
|
455
|
-
* Returns the list of editable model parameters exposed by this provider's
|
|
456
|
-
* underlying SDK (e.g. `temperature`, `maxTokens`).
|
|
457
|
-
*
|
|
458
|
-
* Optional — providers that do not expose model parameters may omit it.
|
|
459
|
-
*/
|
|
460
|
-
getModelParameters?(): PropDefinition[];
|
|
461
|
-
/**
|
|
462
|
-
* Registers a callback that is invoked whenever a prompt changes.
|
|
463
|
-
* Returns a cleanup function that stops the watcher when called.
|
|
464
|
-
*
|
|
465
|
-
* Optional — providers that cannot detect live changes may omit it.
|
|
466
|
-
*
|
|
467
|
-
* @param callback - Invoked with a {@link PromptChangeEvent} for each change.
|
|
468
|
-
* @returns A no-argument function that unregisters the watcher.
|
|
469
|
-
*/
|
|
470
|
-
watch?(callback: (event: PromptChangeEvent) => void): () => void;
|
|
471
|
-
/**
|
|
472
|
-
* Creates a new prompt from the given partial, or returns an
|
|
473
|
-
* {@link AddPromptContext} describing what additional inputs are needed.
|
|
474
|
-
*
|
|
475
|
-
* When `partial` contains enough information the provider creates the
|
|
476
|
-
* prompt and returns the full {@link NormalizedPrompt}. Otherwise it returns
|
|
477
|
-
* an {@link AddPromptContext} whose `fields` describe the form the UI
|
|
478
|
-
* should present to the user.
|
|
479
|
-
*
|
|
480
|
-
* Optional — providers that do not support creating prompts may omit it.
|
|
481
|
-
*
|
|
482
|
-
* @param partial - Partially filled prompt data.
|
|
483
|
-
*/
|
|
484
|
-
addPrompt?(partial: Partial<TPrompt>): Promise<TPrompt | AddPromptContext>;
|
|
372
|
+
values: Record<string, ModelPropValue | undefined>;
|
|
373
|
+
}
|
|
374
|
+
/** Describes a model selection mode exposed by the SDK adapter (e.g. "Provider" or "Gateway"). */
|
|
375
|
+
interface ModelValueType {
|
|
376
|
+
/** Label shown in the UI toggle (e.g. "Provider", "Gateway"). */
|
|
377
|
+
readonly label: string;
|
|
378
|
+
/** Optional tooltip / helper text. */
|
|
379
|
+
readonly description?: string;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* Per-group metadata for constructing custom model values in the UI.
|
|
383
|
+
*
|
|
384
|
+
* `customValueTemplates` is a `PropValue` template per mode. Any primitive
|
|
385
|
+
* string value containing `$input` is replaced with the user's custom model
|
|
386
|
+
* ID at runtime.
|
|
387
|
+
*/
|
|
388
|
+
interface ModelGroupInfo {
|
|
389
|
+
customValueTemplates?: Record<string, ModelPropValue>;
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Model catalog returned by {@link SDKAdapter.getModelCatalog}.
|
|
393
|
+
* Contains the set of known providers and a curated list of models.
|
|
394
|
+
*/
|
|
395
|
+
interface ModelCatalog {
|
|
396
|
+
/** List of known models. */
|
|
397
|
+
models: readonly ModelInfo[];
|
|
485
398
|
/**
|
|
486
|
-
*
|
|
487
|
-
*
|
|
488
|
-
* Optional — providers that do not support renaming may omit it.
|
|
399
|
+
* Available model selection modes.
|
|
489
400
|
*
|
|
490
|
-
*
|
|
491
|
-
*
|
|
401
|
+
* When this is an object, the UI renders a toggle so the user can switch between them.
|
|
402
|
+
* The keys of this object are used in {@link ModelInfo.values}, and the values provide
|
|
403
|
+
* metadata for how to render each mode in the UI.
|
|
492
404
|
*/
|
|
493
|
-
|
|
405
|
+
modelValueTypes?: Record<string, ModelValueType>;
|
|
406
|
+
/** Per-group metadata for constructing custom model PropValues. Keyed by group name. */
|
|
407
|
+
groups?: Record<string, ModelGroupInfo>;
|
|
494
408
|
}
|
|
495
409
|
//#endregion
|
|
496
410
|
//#region src/trace/prompt-tracer.d.ts
|
|
@@ -533,9 +447,12 @@ declare const PROMPT_PROVIDER_ID_ATTRIBUTE = "evalution.prompt.provider.id";
|
|
|
533
447
|
*/
|
|
534
448
|
declare const PROMPT_INPUTS_ATTRIBUTE = "evalution.prompt.inputs";
|
|
535
449
|
interface PromptSpanInfo {
|
|
536
|
-
name
|
|
450
|
+
/** Globally-unique prompt id (e.g. `${groupId}#${name}`). */
|
|
537
451
|
id?: string;
|
|
538
|
-
|
|
452
|
+
/** Human-readable prompt name. */
|
|
453
|
+
name: string;
|
|
454
|
+
/** Positional arguments the prompt function was called with. */
|
|
455
|
+
functionParameters?: unknown[];
|
|
539
456
|
}
|
|
540
457
|
declare function getPromptSpanAttributes(prompt: PromptSpanInfo, attributes?: Attributes): Record<string, AttributeValue>;
|
|
541
458
|
/**
|
|
@@ -566,14 +483,15 @@ declare function createTracerForPrompt(prompt: PromptSpanInfo, tracer?: Tracer):
|
|
|
566
483
|
* subscribe to in real time. Implement this interface to integrate a tracing
|
|
567
484
|
* backend.
|
|
568
485
|
*
|
|
569
|
-
*
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
* an implementation detail (e.g. by registering a
|
|
573
|
-
* `@opentelemetry/sdk-trace-base` `SpanProcessor`).
|
|
486
|
+
* `TraceProvider` is a pure read interface — populating the store is the job
|
|
487
|
+
* of a `TraceIngestor`, which feeds normalized spans into the provider's
|
|
488
|
+
* write side (`TraceSink`, implemented by `BaseTraceProvider`).
|
|
574
489
|
*/
|
|
575
490
|
interface TraceProvider {
|
|
576
|
-
/**
|
|
491
|
+
/**
|
|
492
|
+
* Uniquely identifies this instance, even when multiple providers of the
|
|
493
|
+
* same type are used.
|
|
494
|
+
*/
|
|
577
495
|
readonly id: string;
|
|
578
496
|
/** Human-readable name shown when choosing between providers. */
|
|
579
497
|
readonly displayName?: string;
|
|
@@ -594,9 +512,11 @@ interface TraceProvider {
|
|
|
594
512
|
* invoked for every {@link Span} change on this trace, for as long as the
|
|
595
513
|
* returned cleanup function has not been called.
|
|
596
514
|
*
|
|
515
|
+
* Optional — providers that cannot track live changes may omit it.
|
|
516
|
+
*
|
|
597
517
|
* @returns A no-argument function that cancels the subscription.
|
|
598
518
|
*/
|
|
599
|
-
subscribeTrace(traceId: string, callback: (event: TraceStreamEvent) => void): () => void;
|
|
519
|
+
subscribeTrace?(traceId: string, callback: (event: TraceStreamEvent) => void): () => void;
|
|
600
520
|
/**
|
|
601
521
|
* Registers a callback invoked whenever a trace is added, updated, or
|
|
602
522
|
* removed. Used by the sidebar to stay in sync without polling.
|
|
@@ -606,16 +526,222 @@ interface TraceProvider {
|
|
|
606
526
|
* @returns A no-argument function that unregisters the watcher.
|
|
607
527
|
*/
|
|
608
528
|
watch?(callback: (event: TraceChangeEvent) => void): () => void;
|
|
529
|
+
}
|
|
530
|
+
//#endregion
|
|
531
|
+
//#region src/trace/trace-sink.d.ts
|
|
532
|
+
/**
|
|
533
|
+
* The write side of a {@link TraceProvider}. A {@link TraceIngestor} feeds
|
|
534
|
+
* normalized spans in; the sink owns root detection, trace creation, and
|
|
535
|
+
* event emission.
|
|
536
|
+
*/
|
|
537
|
+
interface TraceSink {
|
|
538
|
+
/**
|
|
539
|
+
* Records a span start. Creates a `running` trace for a new root. Returns
|
|
540
|
+
* the stored (merged) span. Emits `span-start` (+ watch `add` for a new
|
|
541
|
+
* trace).
|
|
542
|
+
*/
|
|
543
|
+
recordSpanStart(span: Span): Promise<Span>;
|
|
544
|
+
/**
|
|
545
|
+
* Records a span end. For a root span, finalizes the trace and emits
|
|
546
|
+
* `trace-end` (+ watch `update`). Returns the stored (merged) span.
|
|
547
|
+
*/
|
|
548
|
+
recordSpanEnd(span: Span): Promise<Span>;
|
|
549
|
+
/**
|
|
550
|
+
* Finalizes a trace as `error` when execution fails before any span is
|
|
551
|
+
* produced (e.g. a bad model id throws before `onStart`).
|
|
552
|
+
*/
|
|
553
|
+
failTrace(traceId: string, errorMessage: string): Promise<void>;
|
|
554
|
+
}
|
|
555
|
+
/**
|
|
556
|
+
* Source-agnostic base class for a {@link TraceProvider}. Owns storage
|
|
557
|
+
* delegation, subscriptions, watchers, and the generic trace lifecycle that
|
|
558
|
+
* every concrete provider shares, regardless of how spans are produced.
|
|
559
|
+
*
|
|
560
|
+
* Subclasses implement the abstract storage hooks; ingestion is handled by
|
|
561
|
+
* one or more {@link TraceIngestor}s that call {@link recordSpanStart} /
|
|
562
|
+
* {@link recordSpanEnd} / {@link failTrace} on this instance (via
|
|
563
|
+
* {@link TraceSink}).
|
|
564
|
+
*/
|
|
565
|
+
declare abstract class BaseTraceProvider implements TraceProvider, TraceSink {
|
|
566
|
+
readonly id: string;
|
|
567
|
+
readonly displayName?: string;
|
|
568
|
+
readonly description?: string;
|
|
569
|
+
private subscribers;
|
|
570
|
+
private watchers;
|
|
571
|
+
constructor(options: {
|
|
572
|
+
id: string;
|
|
573
|
+
displayName: string;
|
|
574
|
+
description: string;
|
|
575
|
+
});
|
|
576
|
+
abstract getAllTraces(): Promise<TraceSummary[]>;
|
|
577
|
+
abstract hasTrace(traceId: string): Promise<boolean>;
|
|
578
|
+
protected abstract getTraceWithoutSpans(traceId: string): Promise<Trace | undefined>;
|
|
579
|
+
protected abstract getTraceSpans(traceId: string): Promise<Span[]>;
|
|
580
|
+
protected abstract addOrUpdateTrace(trace: Trace): Promise<void>;
|
|
581
|
+
/**
|
|
582
|
+
* Stores a span, merging it into any existing span with the same ID (via
|
|
583
|
+
* the `mergeSpans` helper). Returns the resulting stored span so callers
|
|
584
|
+
* can stream the merged view rather than the partial snapshot they passed
|
|
585
|
+
* in.
|
|
586
|
+
*/
|
|
587
|
+
protected abstract addOrUpdateSpan(span: Span): Promise<Span>;
|
|
588
|
+
getTrace(traceId: string): Promise<TraceWithSpans | undefined>;
|
|
589
|
+
subscribeTrace(traceId: string, callback: (event: TraceStreamEvent) => void): () => void;
|
|
590
|
+
watch(callback: (event: TraceChangeEvent) => void): () => void;
|
|
591
|
+
recordSpanStart(span: Span): Promise<Span>;
|
|
592
|
+
recordSpanEnd(span: Span): Promise<Span>;
|
|
593
|
+
failTrace(traceId: string, errorMessage: string): Promise<void>;
|
|
594
|
+
private emitStream;
|
|
595
|
+
private emitChange;
|
|
596
|
+
}
|
|
597
|
+
//#endregion
|
|
598
|
+
//#region src/trace/trace-ingestor.d.ts
|
|
599
|
+
/**
|
|
600
|
+
* A source of trace data. Translates some upstream signal (OTel spans, native
|
|
601
|
+
* AI SDK telemetry, an external collector) into normalized {@link Span}s and
|
|
602
|
+
* feeds the {@link TraceSink}(s) it is connected to.
|
|
603
|
+
*/
|
|
604
|
+
interface TraceIngestor {
|
|
605
|
+
/**
|
|
606
|
+
* Add a sink. May be called multiple times; the ingestor writes to every
|
|
607
|
+
* added sink.
|
|
608
|
+
*/
|
|
609
|
+
addSink(sink: TraceSink): void;
|
|
610
|
+
/**
|
|
611
|
+
* Remove a previously-added sink. Returns `true` if the given sink was found
|
|
612
|
+
* and removed, otherwise `false`.
|
|
613
|
+
*/
|
|
614
|
+
removeSink(sink: TraceSink): boolean;
|
|
615
|
+
/**
|
|
616
|
+
* Optional: returns true if `other` is made redundant by this ingestor and
|
|
617
|
+
* should be excluded from the collected set. The decision may depend on
|
|
618
|
+
* this ingestor's own configuration. Used by the server to consolidate
|
|
619
|
+
* overlapping ingestors — e.g. `OTelTraceIngestor` reports any other
|
|
620
|
+
* `OTelTraceIngestor` redundant because OTel is a single process-global
|
|
621
|
+
* pipeline.
|
|
622
|
+
*/
|
|
623
|
+
isRedundant?(other: TraceIngestor): boolean;
|
|
624
|
+
}
|
|
625
|
+
/**
|
|
626
|
+
* Base class that holds the added sinks and fans each normalized record out
|
|
627
|
+
* to all of them. Concrete ingestors translate their source into
|
|
628
|
+
* {@link Span}/{@link Trace} records and call these protected helpers.
|
|
629
|
+
*/
|
|
630
|
+
declare abstract class BaseTraceIngestor implements TraceIngestor {
|
|
631
|
+
protected sinks: TraceSink[];
|
|
632
|
+
addSink(sink: TraceSink): void;
|
|
633
|
+
removeSink(sink: TraceSink): boolean;
|
|
634
|
+
protected recordSpanStart(span: Span): Promise<void>;
|
|
635
|
+
protected recordSpanEnd(span: Span): Promise<void>;
|
|
636
|
+
protected failTrace(traceId: string, msg: string): Promise<void>;
|
|
637
|
+
}
|
|
638
|
+
//#endregion
|
|
639
|
+
//#region src/prompt/prompt-provider.d.ts
|
|
640
|
+
/**
|
|
641
|
+
* Optional settings for {@link PromptProvider.execute}.
|
|
642
|
+
*/
|
|
643
|
+
interface ExecuteOptions {
|
|
644
|
+
/** The ID to use for the trace created by this execution, if any. */
|
|
645
|
+
traceId?: string;
|
|
646
|
+
}
|
|
647
|
+
/**
|
|
648
|
+
* A source of prompts that the playground can display and execute.
|
|
649
|
+
*
|
|
650
|
+
* Implement this interface to add a custom prompt source — for example,
|
|
651
|
+
* prompts stored in a database or fetched from a remote API. If you simply
|
|
652
|
+
* need to support a file format other than TypeScript, use {@link FilePromptProvider}
|
|
653
|
+
* with a custom {@link PromptFileType}.
|
|
654
|
+
*/
|
|
655
|
+
interface PromptProvider<TPrompt extends NormalizedPrompt = NormalizedPrompt> {
|
|
656
|
+
/** Uniquely identifies this provider when multiple providers are used. */
|
|
657
|
+
readonly id: string;
|
|
658
|
+
/** Human-readable name shown when choosing between providers. */
|
|
659
|
+
readonly displayName?: string;
|
|
660
|
+
/** Short description of what this provider offers. */
|
|
661
|
+
readonly description?: string;
|
|
662
|
+
/** SVG icon markup for this provider. */
|
|
663
|
+
readonly icon?: string;
|
|
664
|
+
/** Returns all prompts currently available from this provider. */
|
|
665
|
+
getAllPrompts(): Promise<TPrompt[]>;
|
|
666
|
+
/**
|
|
667
|
+
* Returns the prompt with the given ID, or `null` if not found.
|
|
668
|
+
* @param id - The prompt's unique identifier.
|
|
669
|
+
*/
|
|
670
|
+
getPrompt(id: string): Promise<TPrompt | null>;
|
|
671
|
+
/**
|
|
672
|
+
* Applies normalized updates to a prompt's source and returns the fresh
|
|
673
|
+
* prompt. Setting any field of `updates` to `null` removes the corresponding
|
|
674
|
+
* property from the underlying source.
|
|
675
|
+
*
|
|
676
|
+
* This method is optional; providers that do not support in-place editing
|
|
677
|
+
* may omit it.
|
|
678
|
+
*
|
|
679
|
+
* @param promptId - ID of the prompt to update.
|
|
680
|
+
* @param updates - Updates expressed in the normalized vocabulary.
|
|
681
|
+
*/
|
|
682
|
+
updatePromptProperties?(promptId: string, updates: NormalizedPromptUpdates): Promise<TPrompt>;
|
|
683
|
+
/**
|
|
684
|
+
* Executes a prompt.
|
|
685
|
+
*
|
|
686
|
+
* @param promptId - ID of the prompt to run.
|
|
687
|
+
* @param params - Positional arguments forwarded to the prompt function.
|
|
688
|
+
* @param options - Optional execution settings; see {@link ExecuteOptions}.
|
|
689
|
+
*/
|
|
690
|
+
execute(promptId: string, params: any[], options?: ExecuteOptions): Promise<void>;
|
|
691
|
+
/**
|
|
692
|
+
* Performs whatever process-global setup this provider's tracing mechanism
|
|
693
|
+
* needs and returns the resulting {@link TraceIngestor}.
|
|
694
|
+
*
|
|
695
|
+
* Optional — providers with no tracing support may omit it.
|
|
696
|
+
*/
|
|
697
|
+
setupTraceIngestion?(): Promise<TraceIngestor | undefined>;
|
|
698
|
+
/**
|
|
699
|
+
* Returns the model catalog (known providers and popular models) for this
|
|
700
|
+
* provider's underlying SDK.
|
|
701
|
+
*
|
|
702
|
+
* Optional — providers that do not expose model info may omit it.
|
|
703
|
+
*/
|
|
704
|
+
getModelCatalog?(): Promise<ModelCatalog>;
|
|
705
|
+
/**
|
|
706
|
+
* Returns the list of editable model parameters exposed by this provider's
|
|
707
|
+
* underlying SDK (e.g. `temperature`, `maxTokens`).
|
|
708
|
+
*
|
|
709
|
+
* Optional — providers that do not expose model parameters may omit it.
|
|
710
|
+
*/
|
|
711
|
+
getModelParameters?(): PropDefinition[];
|
|
712
|
+
/**
|
|
713
|
+
* Registers a callback that is invoked whenever a prompt changes.
|
|
714
|
+
* Returns a cleanup function that stops the watcher when called.
|
|
715
|
+
*
|
|
716
|
+
* Optional — providers that cannot detect live changes may omit it.
|
|
717
|
+
*
|
|
718
|
+
* @param callback - Invoked with a {@link PromptChangeEvent} for each change.
|
|
719
|
+
* @returns A no-argument function that unregisters the watcher.
|
|
720
|
+
*/
|
|
721
|
+
watch?(callback: (event: PromptChangeEvent) => void): () => void;
|
|
722
|
+
/**
|
|
723
|
+
* Creates a new prompt from the given partial, or returns an
|
|
724
|
+
* {@link AddPromptContext} describing what additional inputs are needed.
|
|
725
|
+
*
|
|
726
|
+
* When `partial` contains enough information the provider creates the
|
|
727
|
+
* prompt and returns the full {@link NormalizedPrompt}. Otherwise it returns
|
|
728
|
+
* an {@link AddPromptContext} whose `fields` describe the form the UI
|
|
729
|
+
* should present to the user.
|
|
730
|
+
*
|
|
731
|
+
* Optional — providers that do not support creating prompts may omit it.
|
|
732
|
+
*
|
|
733
|
+
* @param partial - Partially filled prompt data.
|
|
734
|
+
*/
|
|
735
|
+
addPrompt?(partial: Partial<TPrompt>): Promise<TPrompt | AddPromptContext>;
|
|
609
736
|
/**
|
|
610
|
-
*
|
|
611
|
-
*
|
|
612
|
-
*
|
|
613
|
-
* server's tracer land here.
|
|
737
|
+
* Renames a prompt and returns the updated prompt with its new ID.
|
|
738
|
+
*
|
|
739
|
+
* Optional — providers that do not support renaming may omit it.
|
|
614
740
|
*
|
|
615
|
-
*
|
|
616
|
-
*
|
|
741
|
+
* @param promptId - ID of the prompt to rename.
|
|
742
|
+
* @param newName - The new name for the prompt.
|
|
617
743
|
*/
|
|
618
|
-
|
|
744
|
+
renamePrompt?(promptId: string, newName: string): Promise<TPrompt>;
|
|
619
745
|
}
|
|
620
746
|
//#endregion
|
|
621
747
|
//#region src/config.d.ts
|
|
@@ -802,6 +928,17 @@ declare class MemoryFileProvider implements FileProvider {
|
|
|
802
928
|
}
|
|
803
929
|
//#endregion
|
|
804
930
|
//#region src/sdk/sdk-adapter.d.ts
|
|
931
|
+
/** Options for {@link SDKAdapter.executeConfig}. */
|
|
932
|
+
interface ExecuteConfigOptions {
|
|
933
|
+
/** The ID to use for the trace created by this execution, if any. */
|
|
934
|
+
traceId?: string;
|
|
935
|
+
/**
|
|
936
|
+
* The prompt's identity (id, name, parameters). Used to name and link the
|
|
937
|
+
* trace when the config wasn't built by the `prompts()` helper (which would
|
|
938
|
+
* otherwise carry that identity itself).
|
|
939
|
+
*/
|
|
940
|
+
identity?: PromptSpanInfo;
|
|
941
|
+
}
|
|
805
942
|
/**
|
|
806
943
|
* Adapter that provides values and execution for a particular AI SDK.
|
|
807
944
|
*
|
|
@@ -839,8 +976,23 @@ interface SDKAdapter {
|
|
|
839
976
|
* Executes a prompt config object.
|
|
840
977
|
*
|
|
841
978
|
* @param config - The config object returned by the prompt function.
|
|
979
|
+
* @param options - Optional execution options (trace id, prompt identity).
|
|
980
|
+
*/
|
|
981
|
+
executeConfig(config: any, options?: ExecuteConfigOptions): Promise<void>;
|
|
982
|
+
/**
|
|
983
|
+
* Performs whatever process-global setup this SDK's tracing mechanism
|
|
984
|
+
* needs (e.g. registering a native telemetry integration, or standing up an
|
|
985
|
+
* OpenTelemetry pipeline) and returns the resulting {@link TraceIngestor}.
|
|
986
|
+
*
|
|
987
|
+
* Called once during server startup, before any prompt config is built, so
|
|
988
|
+
* registration is guaranteed to happen before the first call.
|
|
989
|
+
*
|
|
990
|
+
* Optional — adapters with no tracing support may omit it.
|
|
991
|
+
*
|
|
992
|
+
* @returns The ingestor to feed into the default trace provider, or
|
|
993
|
+
* `undefined` if this SDK has no tracing support.
|
|
842
994
|
*/
|
|
843
|
-
|
|
995
|
+
setupTraceIngestion?(): Promise<TraceIngestor | undefined>;
|
|
844
996
|
/**
|
|
845
997
|
* Convert a low-level {@link ParsedPrompt} produced by a
|
|
846
998
|
* {@link PromptFileType} into a {@link NormalizedPrompt} that the UI can
|
|
@@ -1037,7 +1189,10 @@ declare class FilePromptProvider implements PromptProvider<NormalizedFilePrompt>
|
|
|
1037
1189
|
private normalizeFilePrompt;
|
|
1038
1190
|
getModelCatalog(): Promise<ModelCatalog>;
|
|
1039
1191
|
getModelParameters(): PropDefinition[];
|
|
1040
|
-
execute(promptId: string, params: any[]
|
|
1192
|
+
execute(promptId: string, params: any[], {
|
|
1193
|
+
traceId
|
|
1194
|
+
}?: ExecuteOptions): Promise<void>;
|
|
1195
|
+
setupTraceIngestion(): Promise<TraceIngestor | undefined>;
|
|
1041
1196
|
renamePrompt(promptId: string, newName: string): Promise<NormalizedFilePrompt>;
|
|
1042
1197
|
addPrompt(partial: Partial<NormalizedFilePrompt>): Promise<NormalizedFilePrompt | AddPromptContext>;
|
|
1043
1198
|
watch(callback: (event: PromptChangeEvent) => void): () => void;
|
|
@@ -1070,7 +1225,7 @@ declare class TSPromptFileType implements PromptFileType {
|
|
|
1070
1225
|
}
|
|
1071
1226
|
//#endregion
|
|
1072
1227
|
//#region src/sdk/gemini-interactions-sdk.d.ts
|
|
1073
|
-
type BaseCreateInteractionParams = Parameters<typeof GoogleGenAI.prototype.interactions.create>[0];
|
|
1228
|
+
type BaseCreateInteractionParams = Parameters<typeof import("@google/genai").GoogleGenAI.prototype.interactions.create>[0];
|
|
1074
1229
|
/**
|
|
1075
1230
|
* {@link SDKAdapter} implementation for the Google GenAI
|
|
1076
1231
|
* [Interactions API](https://ai.google.dev/gemini-api/docs/interactions)
|
|
@@ -1343,7 +1498,7 @@ interface SetupTask {
|
|
|
1343
1498
|
steps: SetupStep[];
|
|
1344
1499
|
}
|
|
1345
1500
|
//#endregion
|
|
1346
|
-
//#region src/sdk/vercel-ai-sdk.d.ts
|
|
1501
|
+
//#region src/sdk/vercel-ai-sdk/index.d.ts
|
|
1347
1502
|
/**
|
|
1348
1503
|
* {@link SDKAdapter} implementation for the
|
|
1349
1504
|
* [Vercel AI SDK](https://sdk.vercel.ai/).
|
|
@@ -1390,74 +1545,118 @@ declare class VercelAISDK implements SDKAdapter {
|
|
|
1390
1545
|
models: ModelInfo[];
|
|
1391
1546
|
}>;
|
|
1392
1547
|
getModelParameters(rootDir: string): PropDefinition$1[];
|
|
1393
|
-
executeConfig(config: any
|
|
1548
|
+
executeConfig(config: any, {
|
|
1549
|
+
traceId,
|
|
1550
|
+
identity
|
|
1551
|
+
}?: ExecuteConfigOptions): Promise<void>;
|
|
1552
|
+
setupTraceIngestion(): Promise<TraceIngestor | undefined>;
|
|
1553
|
+
private doSetupTraceIngestion;
|
|
1394
1554
|
normalizePrompt(prompt: ParsedPrompt): NormalizedPrompt;
|
|
1395
1555
|
denormalizeUpdates(updates: NormalizedPromptUpdates, _currentValues?: Record<string, PropValue$1>): Record<string, ModelPropValue | null>;
|
|
1396
1556
|
}
|
|
1397
1557
|
//#endregion
|
|
1398
|
-
//#region src/
|
|
1558
|
+
//#region src/sdk/vercel-ai-sdk/telemetry.d.ts
|
|
1559
|
+
interface PerPromptTelemetry extends Telemetry {
|
|
1560
|
+
/**
|
|
1561
|
+
* Returns a new instance that will use the given trace ID.
|
|
1562
|
+
*/
|
|
1563
|
+
withTraceId(traceId: string): PerTraceTelemetry;
|
|
1564
|
+
}
|
|
1565
|
+
interface PerTraceTelemetry extends PerPromptTelemetry {
|
|
1566
|
+
/**
|
|
1567
|
+
* Marks this run's trace as failed. Used by `executeConfig` to surface a
|
|
1568
|
+
* `generateText` rejection that happens before `onStart` fires (e.g. a
|
|
1569
|
+
* bad model id) — without this, the trace pre-created for the route's
|
|
1570
|
+
* synchronous response would otherwise hang in `running` forever. If spans
|
|
1571
|
+
* were already opened before the rejection, they are closed as `error` too.
|
|
1572
|
+
*/
|
|
1573
|
+
fail(message: string): Promise<void>;
|
|
1574
|
+
}
|
|
1575
|
+
interface VercelAISDKTelemetryOptions {
|
|
1576
|
+
/**
|
|
1577
|
+
* Native telemetry collection: `"auto"` (default) collects natively unless
|
|
1578
|
+
* an OpenTelemetry integration is also active for the call, in which case
|
|
1579
|
+
* it defers to OTel; `"always"` forces native telemetry collection, even
|
|
1580
|
+
* alongside OTel; `"never"` always defers.
|
|
1581
|
+
*/
|
|
1582
|
+
nativeTelemetry?: "auto" | "always" | "never";
|
|
1583
|
+
}
|
|
1584
|
+
type Callbacks = Required<Telemetry>;
|
|
1399
1585
|
/**
|
|
1400
|
-
*
|
|
1586
|
+
* Native v7 AI SDK `Telemetry` integration that records evalution traces
|
|
1587
|
+
* without going through OpenTelemetry.
|
|
1401
1588
|
*
|
|
1402
|
-
*
|
|
1403
|
-
* `
|
|
1589
|
+
* When your app starts, register this globally via `registerTelemetry(new Evalution())` to capture
|
|
1590
|
+
* every `generateText`/`streamText` call as a fallback (events are keyed by
|
|
1591
|
+
* `callId`, so concurrent calls stay correctly separated, though the fallback
|
|
1592
|
+
* lacks prompt identity). The `prompts()` helper additionally swaps in a
|
|
1593
|
+
* per-call integration from {@link createTelemetryForPrompt} so
|
|
1594
|
+
* helper-defined prompts are recorded with full identity.
|
|
1595
|
+
*
|
|
1596
|
+
* When an OpenTelemetry integration is also active, this class
|
|
1597
|
+
* defers to it by default (see {@link VercelAISDKTelemetryOptions.nativeTelemetry}) rather
|
|
1598
|
+
* than emitting a duplicate, parallel trace.
|
|
1404
1599
|
*/
|
|
1405
|
-
declare
|
|
1406
|
-
readonly id: string;
|
|
1407
|
-
readonly displayName?: string;
|
|
1408
|
-
readonly description?: string;
|
|
1409
|
-
private subscribers;
|
|
1410
|
-
private watchers;
|
|
1411
|
-
private spanPromises;
|
|
1412
|
-
constructor(options: {
|
|
1413
|
-
id: string;
|
|
1414
|
-
displayName: string;
|
|
1415
|
-
description: string;
|
|
1416
|
-
});
|
|
1417
|
-
abstract getAllTraces(): Promise<TraceSummary[]>;
|
|
1418
|
-
abstract hasTrace(traceId: string): Promise<boolean>;
|
|
1419
|
-
protected abstract getTraceWithoutSpans(traceId: string): Promise<Trace | undefined>;
|
|
1420
|
-
protected abstract getTraceSpans(traceId: string): Promise<Span[]>;
|
|
1421
|
-
protected abstract addOrUpdateTrace(trace: Trace): Promise<void>;
|
|
1600
|
+
declare class VercelAISDKTelemetry extends BaseTraceIngestor implements Telemetry {
|
|
1422
1601
|
/**
|
|
1423
|
-
*
|
|
1424
|
-
*
|
|
1425
|
-
*
|
|
1602
|
+
* This instance's configured {@link VercelAISDKTelemetryOptions.nativeTelemetry}.
|
|
1603
|
+
* Read by the `prompts()` helper to decide whether to defer to a sibling
|
|
1604
|
+
* OpenTelemetry integration for a given call.
|
|
1426
1605
|
*/
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1606
|
+
readonly nativeTelemetry: "auto" | "always" | "never";
|
|
1607
|
+
private readonly runs;
|
|
1608
|
+
constructor(options?: VercelAISDKTelemetryOptions);
|
|
1609
|
+
private shouldDeferGlobally;
|
|
1610
|
+
onStart: Callbacks["onStart"];
|
|
1611
|
+
onStepStart: Callbacks["onStepStart"];
|
|
1612
|
+
onToolExecutionStart: Callbacks["onToolExecutionStart"];
|
|
1613
|
+
onToolExecutionEnd: Callbacks["onToolExecutionEnd"];
|
|
1614
|
+
onStepEnd: Callbacks["onStepEnd"];
|
|
1615
|
+
onEnd: Callbacks["onEnd"];
|
|
1616
|
+
onAbort: Callbacks["onAbort"];
|
|
1431
1617
|
/**
|
|
1432
|
-
*
|
|
1433
|
-
*
|
|
1618
|
+
* Mints a `PerPromptTelemetry` integration bound to the given prompt identity.
|
|
1619
|
+
* Used by the `prompts()` helper so a helper-defined prompt is recorded with
|
|
1620
|
+
* full identity. Called with no `identity` (e.g. by the playground for a raw,
|
|
1621
|
+
* non-helper config) it still binds a trace id but records without prompt
|
|
1622
|
+
* identity — the same data the global fallback would, just under a known id.
|
|
1434
1623
|
*/
|
|
1435
|
-
|
|
1624
|
+
createTelemetryForPrompt(identity?: PromptSpanInfo): PerPromptTelemetry;
|
|
1436
1625
|
private handleStart;
|
|
1626
|
+
private handleStepStart;
|
|
1627
|
+
private handleToolExecutionStart;
|
|
1628
|
+
private handleToolExecutionEnd;
|
|
1629
|
+
private handleStepEnd;
|
|
1437
1630
|
private handleEnd;
|
|
1438
|
-
private
|
|
1439
|
-
|
|
1440
|
-
|
|
1631
|
+
private handleAbort;
|
|
1632
|
+
/**
|
|
1633
|
+
* Closes a run's still-open spans (tools, then step, then root) as `error`.
|
|
1634
|
+
* Ending the root finalizes the trace as `error`. Used by both `onAbort` and
|
|
1635
|
+
* the `fail()` path so a mid-flight rejection doesn't leave spans hanging in
|
|
1636
|
+
* `running`.
|
|
1637
|
+
*/
|
|
1638
|
+
private endOpenSpansAsError;
|
|
1639
|
+
private handleFail;
|
|
1441
1640
|
}
|
|
1442
1641
|
//#endregion
|
|
1443
1642
|
//#region src/trace/memory-trace-provider.d.ts
|
|
1444
1643
|
/**
|
|
1445
|
-
* In-memory {@link TraceProvider} populated by
|
|
1446
|
-
*
|
|
1447
|
-
* Register the processor returned by {@link getSpanProcessor} on a
|
|
1448
|
-
* `BasicTracerProvider` (from `@opentelemetry/sdk-trace-base`).
|
|
1644
|
+
* In-memory {@link TraceProvider}, populated by one or more
|
|
1645
|
+
* {@link TraceIngestor}s connected at construction time.
|
|
1449
1646
|
*/
|
|
1450
|
-
declare class MemoryTraceProvider extends
|
|
1647
|
+
declare class MemoryTraceProvider extends BaseTraceProvider {
|
|
1451
1648
|
private traces;
|
|
1452
1649
|
private spansByTrace;
|
|
1453
1650
|
constructor({
|
|
1454
1651
|
id,
|
|
1455
1652
|
displayName,
|
|
1456
|
-
description
|
|
1653
|
+
description,
|
|
1654
|
+
ingestors
|
|
1457
1655
|
}?: {
|
|
1458
1656
|
id?: string;
|
|
1459
1657
|
displayName?: string;
|
|
1460
|
-
description?: string;
|
|
1658
|
+
description?: string; /** Ingestors to connect to this provider as a sink. */
|
|
1659
|
+
ingestors?: TraceIngestor[];
|
|
1461
1660
|
});
|
|
1462
1661
|
getAllTraces(): Promise<TraceSummary[]>;
|
|
1463
1662
|
hasTrace(traceId: string): Promise<boolean>;
|
|
@@ -1467,4 +1666,44 @@ declare class MemoryTraceProvider extends BaseOTelTraceProvider {
|
|
|
1467
1666
|
protected addOrUpdateSpan(span: Span): Promise<Span>;
|
|
1468
1667
|
}
|
|
1469
1668
|
//#endregion
|
|
1470
|
-
|
|
1669
|
+
//#region src/trace/otel-trace-ingestor.d.ts
|
|
1670
|
+
/**
|
|
1671
|
+
* {@link TraceIngestor} populated by OpenTelemetry spans. Register the
|
|
1672
|
+
* processor returned by {@link getSpanProcessor} on a `BasicTracerProvider`
|
|
1673
|
+
* (from `@opentelemetry/sdk-trace-base`).
|
|
1674
|
+
*
|
|
1675
|
+
* Because OpenTelemetry is a single process-global pipeline, at most one
|
|
1676
|
+
* `OTelTraceIngestor` should be active per server — {@link isRedundant}
|
|
1677
|
+
* reports any other instance redundant so server wiring can consolidate.
|
|
1678
|
+
*/
|
|
1679
|
+
declare class OTelTraceIngestor extends BaseTraceIngestor {
|
|
1680
|
+
private spanPromises;
|
|
1681
|
+
isRedundant(other: TraceIngestor): boolean;
|
|
1682
|
+
/**
|
|
1683
|
+
* Returns a `SpanProcessor` that funnels every OpenTelemetry span the
|
|
1684
|
+
* caller's tracer produces into this ingestor's sinks.
|
|
1685
|
+
*/
|
|
1686
|
+
getSpanProcessor(): SpanProcessor;
|
|
1687
|
+
private handleStart;
|
|
1688
|
+
private handleEnd;
|
|
1689
|
+
/**
|
|
1690
|
+
* Waits for every in-flight `onStart`/`onEnd` handler to settle. Used by
|
|
1691
|
+
* tests to deterministically assert on the resulting trace store.
|
|
1692
|
+
*/
|
|
1693
|
+
drainPendingHandlers(): Promise<void>;
|
|
1694
|
+
}
|
|
1695
|
+
//#endregion
|
|
1696
|
+
//#region src/trace/span-merge.d.ts
|
|
1697
|
+
/**
|
|
1698
|
+
* Merges a later snapshot of a span into an earlier one.
|
|
1699
|
+
*
|
|
1700
|
+
* OpenTelemetry reports each span twice — at `onStart` (creation-time
|
|
1701
|
+
* attributes only) and at `onEnd` (the full set) — and the two snapshots can
|
|
1702
|
+
* carry complementary data. This unions their `attributes` and lets any
|
|
1703
|
+
* *defined* field on `incoming` update `existing`, so nothing recorded at start
|
|
1704
|
+
* is lost when the span ends, and end-only fields (status, timings, token
|
|
1705
|
+
* usage, …) are filled in.
|
|
1706
|
+
*/
|
|
1707
|
+
declare function mergeSpans(existing: Span, incoming: Span): Span;
|
|
1708
|
+
//#endregion
|
|
1709
|
+
export { type AddPromptContext, type AddPromptField, BaseTraceIngestor, BaseTraceProvider, type CalleeBinding, type ChangeEventType, type EvalutionConfig, type ExecuteConfigOptions, type ExecuteOptions, type ExecuteRequest, type ExecuteResponse, type ExtractedProps, type FilePromptMetadata, FilePromptProvider, type FilePromptProviderOptions, type FileProvider, type FileWatchCallback, type FileWatchOptions, GeminiInteractionsSDK, type GlobOptions, type LLMSpanDetails, LocalFileProvider, MemoryFileProvider, MemoryTraceProvider, type ModelCatalog, type ModelGroupInfo, type ModelInfo, type ModelPropValue, type ModelValueType, type NormalizedFilePrompt, type NormalizedMessage, type NormalizedParameter, type NormalizedPrompt, type NormalizedPromptUpdates, type NormalizedToolCall, OTelTraceIngestor, PROMPT_ID_ATTRIBUTE, PROMPT_INPUTS_ATTRIBUTE, PROMPT_NAME_ATTRIBUTE, PROMPT_PROVIDER_ID_ATTRIBUTE, type ParsedFilePrompt, type ParsedPrompt, type PerPromptTelemetry, type PerTraceTelemetry, type PromptChangeEvent, type PromptFileType, type PromptID, type PromptProvider, type PromptProviderInfo, type PromptSpanInfo, type PromptsFactory, type PromptsHelper, type PromptsHelperOptions, type PropDefinition, type PropValue, type SDKAdapter, SPAN_KIND_ATTRIBUTE, type SourceSpan, type Span, type SpanKind, type SpanMessage, TSPromptFileType, type ToolSpanDetails, type Trace, type TraceChangeEvent, type TraceChangeType, type TraceIngestor, type TraceProvider, type TraceProviderInfo, type TraceSink, type TraceStreamEvent, type TraceSummary, type TraceWithSpans, VercelAISDK, VercelAISDKTelemetry, type VercelAISDKTelemetryOptions, createTracerForPrompt, getPromptSpanAttributes, mergeSpans };
|