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 CHANGED
@@ -52,13 +52,23 @@ permissively licensed code:
52
52
 
53
53
  - The package takes **no runtime dependency** on the AGPL core — only
54
54
  `peerDependencies` on `ai` and the `@ai-sdk/*` packages.
55
- - It does bundle one file from the core,
56
- [`src/trace/prompt-tracer.ts`](./src/trace/prompt-tracer.ts), via the build.
57
- That file is **dual-licensed `MIT OR AGPL-3.0-only`** (see its SPDX header),
55
+ - It does bundle a handful of files from the core, via the build:
56
+ [`src/trace/prompt-tracer.ts`](./src/trace/prompt-tracer.ts),
57
+ [`src/trace/trace-types.ts`](./src/trace/trace-types.ts),
58
+ [`src/trace/trace-sink.ts`](./src/trace/trace-sink.ts),
59
+ [`src/trace/trace-ingestor.ts`](./src/trace/trace-ingestor.ts), and
60
+ [`src/sdk/vercel-ai-sdk/telemetry.ts`](./src/sdk/vercel-ai-sdk/telemetry.ts).
61
+ Each is **dual-licensed `MIT OR AGPL-3.0-only`** (see its SPDX header),
58
62
  so the bytes that land in the MIT package are genuinely MIT.
59
- - `prompt-tracer.ts` must stay **self-contained** (only `@opentelemetry/api`).
60
- If it ever imports from elsewhere in the core, the bundler would pull
61
- AGPL-only code into the MIT artifact and break this guarantee.
63
+ - Those files must stay **self-contained** — only `@opentelemetry/api`, a
64
+ type-only `ai` import, and each other. If any of them ever imports from
65
+ elsewhere in the core, the bundler would pull AGPL-only code into the MIT
66
+ artifact and break this guarantee. (The AGPL-only `BaseTraceProvider`,
67
+ `OTelTraceIngestor`, `MemoryTraceProvider`, and `span-merge.ts` stay on the
68
+ core side of that boundary, even though `BaseTraceProvider` lives in the
69
+ same dual-licensed `trace-sink.ts` file as the `TraceSink` interface — it
70
+ has no AGPL-only dependencies of its own, so this holds without further
71
+ bookkeeping.)
62
72
 
63
73
  ## Contributing
64
74
 
package/dist/cli/index.js CHANGED
@@ -1,13 +1,11 @@
1
- import { a as MemoryTraceProvider, i as setupStepCommand, r as CONFIG_FILE_RELATIVE_PATH, t as VercelAISDK } from "../vercel-ai-sdk-B8ivuOzP.js";
1
+ import { g as MemoryTraceProvider, m as setupStepCommand, p as CONFIG_FILE_RELATIVE_PATH, t as VercelAISDK } from "../vercel-ai-sdk-JhQ1efcg.js";
2
2
  import module from "node:module";
3
3
  import fs from "node:fs/promises";
4
4
  import path from "node:path";
5
5
  import { fileURLToPath, pathToFileURL } from "node:url";
6
6
  import { serve, upgradeWebSocket } from "@hono/node-server";
7
7
  import { serveStatic } from "@hono/node-server/serve-static";
8
- import { SpanStatusCode, context, trace } from "@opentelemetry/api";
9
- import { AsyncLocalStorageContextManager } from "@opentelemetry/context-async-hooks";
10
- import { BasicTracerProvider } from "@opentelemetry/sdk-trace-base";
8
+ import { SpanStatusCode, isSpanContextValid, trace } from "@opentelemetry/api";
11
9
  import { Hono } from "hono";
12
10
  import { WebSocketServer } from "ws";
13
11
  import { streamSSE } from "hono/streaming";
@@ -220,24 +218,29 @@ function setupRoutes({ app, promptProviders, traceProviders, promptRegistry, hot
220
218
  const { functionParams = [] } = await c.req.json().catch(() => ({}));
221
219
  const prompt = await provider.getPrompt(decodedId);
222
220
  if (!prompt) return c.json({ error: "Prompt not found" }, 404);
223
- const response = tracer.startActiveSpan(prompt.name, (span) => {
224
- const { traceId } = span.spanContext();
225
- provider.execute(decodedId, functionParams).then(() => {
226
- span.setStatus({ code: SpanStatusCode.OK });
227
- }, (err) => {
221
+ const response = await tracer.startActiveSpan(prompt.name, async (span) => {
222
+ const ctx = span.spanContext();
223
+ const native = !isSpanContextValid(ctx);
224
+ const traceId = native ? crypto.randomUUID() : ctx.traceId;
225
+ const rootSpanId = native ? `${traceId}:root` : ctx.spanId;
226
+ try {
227
+ await provider.execute(decodedId, functionParams, { traceId });
228
+ } catch (err) {
228
229
  console.error("prompt execution failed:", err);
229
230
  span.recordException(err);
230
231
  span.setStatus({
231
232
  code: SpanStatusCode.ERROR,
232
233
  message: err?.error ? JSON.stringify(err.error, null, 2) : err?.message ?? String(err)
233
234
  });
234
- }).finally(() => {
235
235
  span.end();
236
- });
236
+ throw err;
237
+ }
238
+ span.setStatus({ code: SpanStatusCode.OK });
239
+ span.end();
237
240
  return {
238
241
  traceId,
239
- tracerProviderId: defaultTraceProviderId,
240
- rootSpanId: span.spanContext().spanId
242
+ rootSpanId,
243
+ tracerProviderId: defaultTraceProviderId
241
244
  };
242
245
  });
243
246
  return c.json(response);
@@ -291,12 +294,12 @@ function setupRoutes({ app, promptProviders, traceProviders, promptRegistry, hot
291
294
  };
292
295
  await stream.writeSSE({ data: JSON.stringify(initial) });
293
296
  }
294
- const unsubscribe = provider.subscribeTrace(id, (event) => {
297
+ const unsubscribe = provider.subscribeTrace?.(id, (event) => {
295
298
  stream.writeSSE({ data: JSON.stringify(resolveEvent(event)) });
296
299
  });
297
300
  await new Promise((resolve) => {
298
301
  stream.onAbort(() => {
299
- unsubscribe();
302
+ unsubscribe?.();
300
303
  resolve();
301
304
  });
302
305
  });
@@ -783,14 +786,10 @@ async function startServer(options) {
783
786
  const traceProviderMap = new Map(traceProviders.map((p) => [p.id, p]));
784
787
  const promptRegistry = new PromptRegistry();
785
788
  await promptRegistry.rebuild(promptProviderMap);
786
- const tracerProvider = new BasicTracerProvider({ spanProcessors: traceProviders.filter((p) => !!p.getSpanProcessor).map((p) => p.getSpanProcessor()) });
787
- trace.setGlobalTracerProvider(tracerProvider);
788
- const contextManager = new AsyncLocalStorageContextManager();
789
- contextManager.enable();
790
- context.setGlobalContextManager(contextManager);
791
- const tracer = tracerProvider.getTracer("evalution");
792
- const defaultTraceProviderId = traceProviders.find((p) => p instanceof MemoryTraceProvider)?.id ?? traceProviders[0]?.id;
793
- if (!defaultTraceProviderId) throw new Error("At least one trace provider must be configured");
789
+ const tracer = trace.getTracer("evalution");
790
+ const defaultTraceProvider = traceProviders.find((p) => p instanceof MemoryTraceProvider) ?? traceProviders[0];
791
+ if (!defaultTraceProvider) throw new Error("At least one trace provider must be configured");
792
+ const defaultTraceProviderId = defaultTraceProvider.id;
794
793
  const app = new Hono();
795
794
  const hotReloadSubscribers = /* @__PURE__ */ new Set();
796
795
  const broadcast = (data) => {
@@ -925,7 +924,7 @@ function registerEvalutionResolver(parentURL) {
925
924
  function watchForConfigCreation(rootDir, onConfig) {
926
925
  const configPath = path.join(rootDir, CONFIG_FILE_RELATIVE_PATH);
927
926
  const configDir = path.dirname(configPath);
928
- const allowed = new Set([
927
+ const allowed = /* @__PURE__ */ new Set([
929
928
  rootDir,
930
929
  configDir,
931
930
  configPath
@@ -1071,11 +1070,19 @@ function applyDotenv(rootDir) {
1071
1070
  if (err?.code !== "ENOENT") console.warn(`Warning: failed to load .env from ${envPath}:`, err.message);
1072
1071
  }
1073
1072
  }
1074
- function startConfiguredServer(rootDir, config, hasConfig, port, terminalSessions) {
1073
+ async function startConfiguredServer(rootDir, config, hasConfig, port, terminalSessions) {
1075
1074
  if (config.useDotenv !== false) applyDotenv(rootDir);
1075
+ const promptProviders = config.promptProviders ?? [];
1076
+ let traceProviders = config.traceProviders;
1077
+ if (!traceProviders) {
1078
+ const collected = (await Promise.all(promptProviders.map((p) => p.setupTraceIngestion?.()))).filter((i) => !!i);
1079
+ const ingestors = [];
1080
+ for (const ing of collected) if (!ingestors.some((kept) => kept.isRedundant?.(ing))) ingestors.push(ing);
1081
+ traceProviders = [new MemoryTraceProvider({ ingestors })];
1082
+ }
1076
1083
  return startServer({
1077
- promptProviders: config.promptProviders ?? [],
1078
- traceProviders: config.traceProviders ?? [new MemoryTraceProvider()],
1084
+ promptProviders,
1085
+ traceProviders,
1079
1086
  port,
1080
1087
  rootPath: rootDir,
1081
1088
  hasConfig,
@@ -1094,16 +1101,18 @@ async function main() {
1094
1101
  let port;
1095
1102
  if (process.env.PORT) port = parseInt(process.env.PORT, 10);
1096
1103
  else port = await findAvailablePort(3e3);
1097
- const maybeOpen = (url) => {
1098
- if (!process.env.EVALUTION_NO_OPEN) openBrowser(url);
1104
+ const maybeOpen = async (url) => {
1105
+ if (process.env.EVALUTION_NO_OPEN) return;
1106
+ await new Promise((r) => setTimeout(r, 250));
1107
+ openBrowser(url);
1099
1108
  };
1100
1109
  const terminalSessions = new TerminalSessionRegistry();
1101
1110
  if (hasConfig) {
1102
- maybeOpen((await startConfiguredServer(rootDir, await loadConfig(rootDir), true, port, terminalSessions)).url);
1111
+ await maybeOpen((await startConfiguredServer(rootDir, await loadConfig(rootDir), true, port, terminalSessions)).url);
1103
1112
  return;
1104
1113
  }
1105
1114
  let server = await startConfiguredServer(rootDir, {}, false, port, terminalSessions);
1106
- maybeOpen(server.url);
1115
+ await maybeOpen(server.url);
1107
1116
  console.log(`👀 No config found; watching ${path.join(rootDir, ".evalution", "config.ts")} for creation...`);
1108
1117
  const stopWatching = watchForConfigCreation(rootDir, async () => {
1109
1118
  const config = await loadConfig(rootDir);