@databricks/appkit 0.73.0 → 0.74.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/CLAUDE.md +7 -0
- package/dist/appkit/package.js +1 -1
- package/dist/beta.d.ts +6 -6
- package/dist/beta.js +6 -6
- package/dist/cli/commands/agent/eval.js +85 -21
- package/dist/cli/commands/agent/eval.js.map +1 -1
- package/dist/cli/commands/registry/add.js +77 -6
- package/dist/cli/commands/registry/add.js.map +1 -1
- package/dist/evals/dataset.d.ts +14 -1
- package/dist/evals/dataset.d.ts.map +1 -1
- package/dist/evals/dataset.js +16 -1
- package/dist/evals/dataset.js.map +1 -1
- package/dist/evals/define-eval.d.ts +4 -2
- package/dist/evals/define-eval.d.ts.map +1 -1
- package/dist/evals/define-eval.js +5 -1
- package/dist/evals/define-eval.js.map +1 -1
- package/dist/evals/discover.d.ts +15 -1
- package/dist/evals/discover.d.ts.map +1 -1
- package/dist/evals/discover.js +40 -10
- package/dist/evals/discover.js.map +1 -1
- package/dist/evals/http-driver.d.ts.map +1 -1
- package/dist/evals/http-driver.js +31 -9
- package/dist/evals/http-driver.js.map +1 -1
- package/dist/evals/index.d.ts +5 -5
- package/dist/evals/index.js +5 -5
- package/dist/evals/report.d.ts +16 -1
- package/dist/evals/report.d.ts.map +1 -1
- package/dist/evals/report.js +64 -2
- package/dist/evals/report.js.map +1 -1
- package/dist/evals/run-eval.d.ts +5 -0
- package/dist/evals/run-eval.d.ts.map +1 -1
- package/dist/evals/run-eval.js +44 -3
- package/dist/evals/run-eval.js.map +1 -1
- package/dist/evals/run-evals.d.ts +32 -3
- package/dist/evals/run-evals.d.ts.map +1 -1
- package/dist/evals/run-evals.js +128 -26
- package/dist/evals/run-evals.js.map +1 -1
- package/dist/evals/types.d.ts +40 -2
- package/dist/evals/types.d.ts.map +1 -1
- package/dist/registry/manifest-loader.d.ts +1 -1
- package/docs/api/appkit/Function.defineEvalConfig.md +18 -0
- package/docs/api/appkit/Function.discoverEvalConfigs.md +18 -0
- package/docs/api/appkit/Function.formatResultsJUnit.md +18 -0
- package/docs/api/appkit/Function.formatResultsJson.md +18 -0
- package/docs/api/appkit/Function.runWithRetries.md +28 -0
- package/docs/api/appkit/Function.userTurns.md +20 -0
- package/docs/api/appkit/Interface.DiscoveredEvalConfig.md +25 -0
- package/docs/api/appkit/Interface.DriveResult.md +28 -0
- package/docs/api/appkit/Interface.EvalDefinition.md +22 -0
- package/docs/api/appkit/Interface.EvalDriver.md +10 -4
- package/docs/api/appkit/Interface.EvalResult.md +11 -0
- package/docs/api/appkit/Interface.EvalSummary.md +11 -0
- package/docs/api/appkit/Interface.RunEvalOptions.md +11 -0
- package/docs/api/appkit/Interface.RunEvalsOptions.md +23 -1
- package/docs/api/appkit/Interface.TestContext.md +30 -8
- package/docs/api/appkit.md +7 -0
- package/docs/plugins/agents.md +255 -4
- package/llms.txt +7 -0
- package/package.json +1 -1
- package/sbom.cdx.json +1 -1
package/CLAUDE.md
CHANGED
|
@@ -99,9 +99,11 @@ npx @databricks/appkit docs <query>
|
|
|
99
99
|
- [Function: createWorkspaceClient()](./docs/api/appkit/Function.createWorkspaceClient.md): Construct an AppKit workspace client.
|
|
100
100
|
- [Function: database()](./docs/api/appkit/Function.database.md): Create a typed database plugin registration for a finalized schema.
|
|
101
101
|
- [Function: defineEval()](./docs/api/appkit/Function.defineEval.md): Define an agent eval. Default-export the result from a
|
|
102
|
+
- [Function: defineEvalConfig()](./docs/api/appkit/Function.defineEvalConfig.md): Define per-directory eval config. Default-export from evals.config.ts.
|
|
102
103
|
- [Function: defineManifest()](./docs/api/appkit/Function.defineManifest.md): Validates a raw manifest (typically a manifest.json import) against the
|
|
103
104
|
- [Function: defineSchema()](./docs/api/appkit/Function.defineSchema.md): Compile one declared schema. The returned type keeps the table names the
|
|
104
105
|
- [Function: defineTool()](./docs/api/appkit/Function.defineTool.md): Defines a single tool entry for a plugin's internal registry.
|
|
106
|
+
- [Function: discoverEvalConfigs()](./docs/api/appkit/Function.discoverEvalConfigs.md): Discover the per-agent evals.config.ts (from defineEvalConfig) at
|
|
105
107
|
- [Function: discoverEvalFiles()](./docs/api/appkit/Function.discoverEvalFiles.md): Discover evals under /server/agents//evals/ — co-located
|
|
106
108
|
- [Function: enumColumn()](./docs/api/appkit/Function.enumColumn.md): Parameters
|
|
107
109
|
- [Function: equals()](./docs/api/appkit/Function.equals.md): Passes when the value equals expected exactly.
|
|
@@ -113,6 +115,8 @@ npx @databricks/appkit docs <query>
|
|
|
113
115
|
- [Function: formatEvalDetail()](./docs/api/appkit/Function.formatEvalDetail.md): Indented detail lines for a failing eval (error + failing assertions).
|
|
114
116
|
- [Function: formatEvalHeadline()](./docs/api/appkit/Function.formatEvalHeadline.md): The one-line header for a single eval result (no failure detail).
|
|
115
117
|
- [Function: formatEvalResults()](./docs/api/appkit/Function.formatEvalResults.md): Render all results as a human-readable console report (non-streaming).
|
|
118
|
+
- [Function: formatResultsJson()](./docs/api/appkit/Function.formatResultsJson.md): Render results as a machine-readable JSON report (2-space indented):
|
|
119
|
+
- [Function: formatResultsJUnit()](./docs/api/appkit/Function.formatResultsJUnit.md): Render results as JUnit XML for standard CI test reporters: a single
|
|
116
120
|
- [Function: formatSummaryLine()](./docs/api/appkit/Function.formatSummaryLine.md): The final PASS/FAIL summary line.
|
|
117
121
|
- [Function: fromSupervisorApi()](./docs/api/appkit/Function.fromSupervisorApi.md): Creates an AgentAdapter backed by the Databricks AI Gateway
|
|
118
122
|
- [Function: functionToolToDefinition()](./docs/api/appkit/Function.functionToolToDefinition.md): Parameters
|
|
@@ -148,11 +152,13 @@ npx @databricks/appkit docs <query>
|
|
|
148
152
|
- [Function: runAgent()](./docs/api/appkit/Function.runAgent.md): Standalone agent execution without createApp. Resolves the adapter, binds
|
|
149
153
|
- [Function: runEval()](./docs/api/appkit/Function.runEval.md): Run a single eval against a driver. Never throws for assertion or agent
|
|
150
154
|
- [Function: runEvalsInDir()](./docs/api/appkit/Function.runEvalsInDir.md): Discover, load, and run every eval under each agent's evals/ dir, driving
|
|
155
|
+
- [Function: runWithRetries()](./docs/api/appkit/Function.runWithRetries.md): Run attempt up to 1 + retries times, stopping as soon as it returns a
|
|
151
156
|
- [Function: summarize()](./docs/api/appkit/Function.summarize.md): Parameters
|
|
152
157
|
- [Function: text()](./docs/api/appkit/Function.text.md): Returns
|
|
153
158
|
- [Function: timestamp()](./docs/api/appkit/Function.timestamp.md): Parameters
|
|
154
159
|
- [Function: tool()](./docs/api/appkit/Function.tool.md): Factory for defining function tools with Zod schemas.
|
|
155
160
|
- [Function: toolsFromRegistry()](./docs/api/appkit/Function.toolsFromRegistry.md): Produces the AgentToolDefinition[] a ToolProvider exposes to the LLM,
|
|
161
|
+
- [Function: userTurns()](./docs/api/appkit/Function.userTurns.md): Extract every user-message content, in order, from an MLflow
|
|
156
162
|
- [Function: uuid()](./docs/api/appkit/Function.uuid.md): Returns
|
|
157
163
|
- [Function: varchar()](./docs/api/appkit/Function.varchar.md): Parameters
|
|
158
164
|
- [Interface: AgentAdapter](./docs/api/appkit/Interface.AgentAdapter.md): Properties
|
|
@@ -174,6 +180,7 @@ npx @databricks/appkit docs <query>
|
|
|
174
180
|
- [Interface: DatabricksAuth](./docs/api/appkit/Interface.DatabricksAuth.md): Resolved Databricks host + bearer token for the eval runner's REST calls.
|
|
175
181
|
- [Interface: DatasetRow](./docs/api/appkit/Interface.DatasetRow.md): One row of a managed evaluation dataset. inputs are the kwargs passed to the
|
|
176
182
|
- [Interface: DiscoveredEval](./docs/api/appkit/Interface.DiscoveredEval.md): An eval file found under server/agents//evals/.
|
|
183
|
+
- [Interface: DiscoveredEvalConfig](./docs/api/appkit/Interface.DiscoveredEvalConfig.md): A per-agent evals.config.ts found under server/agents//evals/.
|
|
177
184
|
- [Interface: DriveResult](./docs/api/appkit/Interface.DriveResult.md): What a driver returns for a single t.send.
|
|
178
185
|
- [Interface: EndpointConfig](./docs/api/appkit/Interface.EndpointConfig.md): Properties
|
|
179
186
|
- [Interface: EntityMutationHooks<TTable>](./docs/api/appkit/Interface.EntityMutationHooks.md): Mutation lifecycle for one entity. A before hook may return a replacement
|
package/dist/appkit/package.js
CHANGED
package/dist/beta.d.ts
CHANGED
|
@@ -17,17 +17,17 @@ import { defineSchema } from "./database/schema-builder/define-schema.js";
|
|
|
17
17
|
import { fk } from "./database/schema-builder/fk.js";
|
|
18
18
|
import { DatabricksAuth, ResolveDatabricksAuthOptions, resolveDatabricksAuth, resolveWorkspaceClient } from "./connectors/mlflow/auth.js";
|
|
19
19
|
import { MlflowClient, PostResult, normalizeHost } from "./connectors/mlflow/client.js";
|
|
20
|
-
import { DatasetRow, ReadEvalDatasetOptions, readEvalDataset } from "./evals/dataset.js";
|
|
20
|
+
import { DatasetRow, ReadEvalDatasetOptions, readEvalDataset, userTurns } from "./evals/dataset.js";
|
|
21
21
|
import { AssertionHandle, AssertionResult, CustomJudgeSpec, DriveResult, EvalDefinition, EvalDriver, EvalResult, MatchResult, Matcher, Severity, TestContext } from "./evals/types.js";
|
|
22
|
-
import { defineEval } from "./evals/define-eval.js";
|
|
23
|
-
import { DiscoveredEval, discoverEvalFiles } from "./evals/discover.js";
|
|
22
|
+
import { defineEval, defineEvalConfig } from "./evals/define-eval.js";
|
|
23
|
+
import { DiscoveredEval, DiscoveredEvalConfig, discoverEvalConfigs, discoverEvalFiles } from "./evals/discover.js";
|
|
24
24
|
import { HttpDriverOptions, createHttpDriver } from "./evals/http-driver.js";
|
|
25
25
|
import { JudgeConfig, JudgeScore, configureJudge, isJudgeConfigured } from "./evals/judge.js";
|
|
26
26
|
import { equals, includes, matches } from "./evals/matchers.js";
|
|
27
27
|
import { Assessment, ReportOutcome, buildAssessments, reportToMlflow } from "./evals/mlflow-report.js";
|
|
28
|
-
import { EvalSummary, evalGlyph, formatEvalDetail, formatEvalHeadline, formatEvalResults, formatSummaryLine, summarize } from "./evals/report.js";
|
|
28
|
+
import { EvalSummary, evalGlyph, formatEvalDetail, formatEvalHeadline, formatEvalResults, formatResultsJUnit, formatResultsJson, formatSummaryLine, summarize } from "./evals/report.js";
|
|
29
29
|
import { RunEvalOptions, runEval } from "./evals/run-eval.js";
|
|
30
|
-
import { EvalProgress, EvalRunSummary, RunEvalsOptions, runEvalsInDir } from "./evals/run-evals.js";
|
|
30
|
+
import { EvalProgress, EvalRunSummary, RunEvalsOptions, runEvalsInDir, runWithRetries } from "./evals/run-evals.js";
|
|
31
31
|
import "./evals/index.js";
|
|
32
32
|
import { agentIdFromMarkdownPath, loadAgentFromFile, loadAgentsFromDir } from "./core/agent/load-agents.js";
|
|
33
33
|
import { agents } from "./plugins/agents/agents.js";
|
|
@@ -40,4 +40,4 @@ import { DatabaseApiConfig, DatabaseApiWriteOperation, DatabaseApiWritesConfig,
|
|
|
40
40
|
import { database } from "./plugins/database/database.js";
|
|
41
41
|
import "./plugins/database/index.js";
|
|
42
42
|
import "./plugins/beta-exports.generated.js";
|
|
43
|
-
export { type AgentAdapter, type AgentDefinition, type AgentEvent, type AgentInput, type AgentRunContext, type AgentTool, type AgentToolDefinition, type AgentTools, type AgentToolsFn, type AgentsPluginConfig, AppKitMcpClient, AssertionHandle, AssertionResult, Assessment, type AutoInheritToolsConfig, type BaseSystemPromptOption, CustomJudgeSpec, type DatabaseApiConfig, type DatabaseApiWriteOperation, type DatabaseApiWritesConfig, type DatabaseExports, DatabricksAdapter, DatabricksAuth, DatasetRow, DiscoveredEval, DriveResult, type EntityHooks, type EntityMutationHooks, EvalDefinition, EvalDriver, EvalProgress, EvalResult, EvalRunSummary, EvalSummary, type FunctionTool, type GenerationParams, type HookApp, type HookContext, type HostedSupervisorTool, type HostedTool, HttpDriverOptions, type IAiSearchConfig, type IDatabaseConfig, type IndexConfig, JudgeConfig, JudgeScore, MatchResult, Matcher, type McpConnectAllResult, type Message, MlflowClient, type PluginToolkitProvider, type Plugins, PostResult, type PromptContext, ReadEvalDatasetOptions, type ReadSerializer, type ReadSerializerContext, type RegisteredAgent, ReportOutcome, type RerankerConfig, ResolveDatabricksAuthOptions, type ResolvedToolEntry, type RunAgentInput, type RunAgentResult, RunEvalOptions, RunEvalsOptions, SUPERVISOR_EXTENSION_KEY, type Schema, type SearchFilters, type SearchRequest, type SearchResponse, type SearchResult, Severity, SupervisorApiAdapter, type SupervisorApiAdapterOptions, type SupervisorExtension, type SupervisorTool, TestContext, type Thread, type ThreadStore, type ToolAnnotations, type ToolConfig, type ToolEntry, type ToolProvider, type ToolRegistry, type ToolkitEntry, type ToolkitOptions, type TransactionClient, type WorkspaceClientLike, agentIdFromMarkdownPath, agents, aiSearch, bigid, bigint, boolean, buildAssessments, configureJudge, createAgent, createHttpDriver, database, defineEval, defineSchema, defineTool, discoverEvalFiles, enumColumn, equals, evalGlyph, executeFromRegistry, fk, formatEvalDetail, formatEvalHeadline, formatEvalResults, formatSummaryLine, fromSupervisorApi, functionToolToDefinition, id, includes, integer, isFunctionTool, isHostedTool, isJudgeConfigured, isSupervisorTool, isToolkitEntry, jsonb, loadAgentFromFile, loadAgentsFromDir, matches, mcpServer, normalizeHost, parseTextToolCalls, readEvalDataset, reportToMlflow, resolveDatabricksAuth, resolveHostedTools, resolveWorkspaceClient, runAgent, runEval, runEvalsInDir, summarize, supervisorTools, text, timestamp, tool, toolsFromRegistry, uuid, varchar };
|
|
43
|
+
export { type AgentAdapter, type AgentDefinition, type AgentEvent, type AgentInput, type AgentRunContext, type AgentTool, type AgentToolDefinition, type AgentTools, type AgentToolsFn, type AgentsPluginConfig, AppKitMcpClient, AssertionHandle, AssertionResult, Assessment, type AutoInheritToolsConfig, type BaseSystemPromptOption, CustomJudgeSpec, type DatabaseApiConfig, type DatabaseApiWriteOperation, type DatabaseApiWritesConfig, type DatabaseExports, DatabricksAdapter, DatabricksAuth, DatasetRow, DiscoveredEval, DiscoveredEvalConfig, DriveResult, type EntityHooks, type EntityMutationHooks, EvalDefinition, EvalDriver, EvalProgress, EvalResult, EvalRunSummary, EvalSummary, type FunctionTool, type GenerationParams, type HookApp, type HookContext, type HostedSupervisorTool, type HostedTool, HttpDriverOptions, type IAiSearchConfig, type IDatabaseConfig, type IndexConfig, JudgeConfig, JudgeScore, MatchResult, Matcher, type McpConnectAllResult, type Message, MlflowClient, type PluginToolkitProvider, type Plugins, PostResult, type PromptContext, ReadEvalDatasetOptions, type ReadSerializer, type ReadSerializerContext, type RegisteredAgent, ReportOutcome, type RerankerConfig, ResolveDatabricksAuthOptions, type ResolvedToolEntry, type RunAgentInput, type RunAgentResult, RunEvalOptions, RunEvalsOptions, SUPERVISOR_EXTENSION_KEY, type Schema, type SearchFilters, type SearchRequest, type SearchResponse, type SearchResult, Severity, SupervisorApiAdapter, type SupervisorApiAdapterOptions, type SupervisorExtension, type SupervisorTool, TestContext, type Thread, type ThreadStore, type ToolAnnotations, type ToolConfig, type ToolEntry, type ToolProvider, type ToolRegistry, type ToolkitEntry, type ToolkitOptions, type TransactionClient, type WorkspaceClientLike, agentIdFromMarkdownPath, agents, aiSearch, bigid, bigint, boolean, buildAssessments, configureJudge, createAgent, createHttpDriver, database, defineEval, defineEvalConfig, defineSchema, defineTool, discoverEvalConfigs, discoverEvalFiles, enumColumn, equals, evalGlyph, executeFromRegistry, fk, formatEvalDetail, formatEvalHeadline, formatEvalResults, formatResultsJUnit, formatResultsJson, formatSummaryLine, fromSupervisorApi, functionToolToDefinition, id, includes, integer, isFunctionTool, isHostedTool, isJudgeConfigured, isSupervisorTool, isToolkitEntry, jsonb, loadAgentFromFile, loadAgentsFromDir, matches, mcpServer, normalizeHost, parseTextToolCalls, readEvalDataset, reportToMlflow, resolveDatabricksAuth, resolveHostedTools, resolveWorkspaceClient, runAgent, runEval, runEvalsInDir, runWithRetries, summarize, supervisorTools, text, timestamp, tool, toolsFromRegistry, userTurns, uuid, varchar };
|
package/dist/beta.js
CHANGED
|
@@ -15,16 +15,16 @@ import { isToolkitEntry } from "./core/agent/types.js";
|
|
|
15
15
|
import { runAgent } from "./core/agent/run-agent.js";
|
|
16
16
|
import "./core/agent/tools/index.js";
|
|
17
17
|
import "./database/schema-builder/index.js";
|
|
18
|
-
import { readEvalDataset } from "./evals/dataset.js";
|
|
19
|
-
import { defineEval } from "./evals/define-eval.js";
|
|
20
|
-
import { discoverEvalFiles } from "./evals/discover.js";
|
|
18
|
+
import { readEvalDataset, userTurns } from "./evals/dataset.js";
|
|
19
|
+
import { defineEval, defineEvalConfig } from "./evals/define-eval.js";
|
|
20
|
+
import { discoverEvalConfigs, discoverEvalFiles } from "./evals/discover.js";
|
|
21
21
|
import { createHttpDriver } from "./evals/http-driver.js";
|
|
22
22
|
import { configureJudge, isJudgeConfigured } from "./evals/judge.js";
|
|
23
23
|
import { equals, includes, matches } from "./evals/matchers.js";
|
|
24
24
|
import { buildAssessments, reportToMlflow } from "./evals/mlflow-report.js";
|
|
25
|
-
import { evalGlyph, formatEvalDetail, formatEvalHeadline, formatEvalResults, formatSummaryLine, summarize } from "./evals/report.js";
|
|
25
|
+
import { evalGlyph, formatEvalDetail, formatEvalHeadline, formatEvalResults, formatResultsJUnit, formatResultsJson, formatSummaryLine, summarize } from "./evals/report.js";
|
|
26
26
|
import { runEval } from "./evals/run-eval.js";
|
|
27
|
-
import { runEvalsInDir } from "./evals/run-evals.js";
|
|
27
|
+
import { runEvalsInDir, runWithRetries } from "./evals/run-evals.js";
|
|
28
28
|
import "./evals/index.js";
|
|
29
29
|
import { agentIdFromMarkdownPath, loadAgentFromFile, loadAgentsFromDir } from "./core/agent/load-agents.js";
|
|
30
30
|
import { agents } from "./plugins/agents/agents.js";
|
|
@@ -33,4 +33,4 @@ import { aiSearch } from "./plugins/ai-search/ai-search.js";
|
|
|
33
33
|
import { database } from "./plugins/database/database.js";
|
|
34
34
|
import "./plugins/beta-exports.generated.js";
|
|
35
35
|
|
|
36
|
-
export { AppKitMcpClient, DatabricksAdapter, MlflowClient, SUPERVISOR_EXTENSION_KEY, SupervisorApiAdapter, agentIdFromMarkdownPath, agents, aiSearch, bigid, bigint, boolean, buildAssessments, configureJudge, createAgent, createHttpDriver, database, defineEval, defineSchema, defineTool, discoverEvalFiles, enumColumn, equals, evalGlyph, executeFromRegistry, fk, formatEvalDetail, formatEvalHeadline, formatEvalResults, formatSummaryLine, fromSupervisorApi, functionToolToDefinition, id, includes, integer, isFunctionTool, isHostedTool, isJudgeConfigured, isSupervisorTool, isToolkitEntry, jsonb, loadAgentFromFile, loadAgentsFromDir, matches, mcpServer, normalizeHost, parseTextToolCalls, readEvalDataset, reportToMlflow, resolveDatabricksAuth, resolveHostedTools, resolveWorkspaceClient, runAgent, runEval, runEvalsInDir, summarize, supervisorTools, text, timestamp, tool, toolsFromRegistry, uuid, varchar };
|
|
36
|
+
export { AppKitMcpClient, DatabricksAdapter, MlflowClient, SUPERVISOR_EXTENSION_KEY, SupervisorApiAdapter, agentIdFromMarkdownPath, agents, aiSearch, bigid, bigint, boolean, buildAssessments, configureJudge, createAgent, createHttpDriver, database, defineEval, defineEvalConfig, defineSchema, defineTool, discoverEvalConfigs, discoverEvalFiles, enumColumn, equals, evalGlyph, executeFromRegistry, fk, formatEvalDetail, formatEvalHeadline, formatEvalResults, formatResultsJUnit, formatResultsJson, formatSummaryLine, fromSupervisorApi, functionToolToDefinition, id, includes, integer, isFunctionTool, isHostedTool, isJudgeConfigured, isSupervisorTool, isToolkitEntry, jsonb, loadAgentFromFile, loadAgentsFromDir, matches, mcpServer, normalizeHost, parseTextToolCalls, readEvalDataset, reportToMlflow, resolveDatabricksAuth, resolveHostedTools, resolveWorkspaceClient, runAgent, runEval, runEvalsInDir, runWithRetries, summarize, supervisorTools, text, timestamp, tool, toolsFromRegistry, userTurns, uuid, varchar };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { Command, Option } from "commander";
|
|
2
3
|
|
|
3
4
|
//#region src/cli/commands/agent/eval.ts
|
|
4
5
|
/**
|
|
@@ -24,6 +25,22 @@ function parseHeaders(values) {
|
|
|
24
25
|
return headers;
|
|
25
26
|
}
|
|
26
27
|
/**
|
|
28
|
+
* Parse `--min-pass-rate`: a finite number in `[0, 1]`, or `undefined` when
|
|
29
|
+
* unset. Throws on blank, out-of-range, or non-numeric input so a bad gate
|
|
30
|
+
* value fails fast instead of silently disabling or inverting the CI gate.
|
|
31
|
+
*/
|
|
32
|
+
function parsePassRate(raw) {
|
|
33
|
+
if (raw === void 0) return void 0;
|
|
34
|
+
const n = Number(raw);
|
|
35
|
+
if (raw.trim() === "" || !Number.isFinite(n) || n < 0 || n > 1) throw new Error(`Invalid --min-pass-rate "${raw}" — expected a number in [0, 1]`);
|
|
36
|
+
return n;
|
|
37
|
+
}
|
|
38
|
+
/** Parse a positive-integer CLI option; junk, zero, or negative → undefined. */
|
|
39
|
+
function positiveInt(raw) {
|
|
40
|
+
const n = raw ? Number.parseInt(raw, 10) : NaN;
|
|
41
|
+
return n > 0 ? n : void 0;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
27
44
|
* Native MLflow "Evaluation run" config — only when creds + an experiment are
|
|
28
45
|
* all present (traces live in the app; the run + scores are driven from here).
|
|
29
46
|
*/
|
|
@@ -47,17 +64,22 @@ function resolveJudge(opts, auth) {
|
|
|
47
64
|
model
|
|
48
65
|
} : void 0;
|
|
49
66
|
}
|
|
50
|
-
/**
|
|
51
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Progress reporter: stream each eval as it runs instead of going silent. In a
|
|
69
|
+
* machine reporter (json/junit) the live per-eval streaming is suppressed and
|
|
70
|
+
* banners go to stderr (via `info`), keeping stdout clean for the report.
|
|
71
|
+
*/
|
|
72
|
+
function makeProgressReporter(runner, url, machine, info) {
|
|
52
73
|
return (event) => {
|
|
53
74
|
switch (event.type) {
|
|
54
75
|
case "discovered":
|
|
55
|
-
|
|
76
|
+
info(`Running ${event.total} eval${event.total === 1 ? "" : "s"} against ${url}\n`);
|
|
56
77
|
break;
|
|
57
78
|
case "run-created":
|
|
58
|
-
|
|
79
|
+
info(`MLflow evaluation run: ${event.runId}\n`);
|
|
59
80
|
break;
|
|
60
81
|
case "result":
|
|
82
|
+
if (machine) break;
|
|
61
83
|
console.log(`[${event.index + 1}/${event.total}] ${runner.formatEvalHeadline(event.result)}`);
|
|
62
84
|
for (const line of runner.formatEvalDetail(event.result)) console.log(line);
|
|
63
85
|
break;
|
|
@@ -67,33 +89,51 @@ function makeProgressReporter(runner, url) {
|
|
|
67
89
|
function formatFailureLine(f) {
|
|
68
90
|
return ` ✗ trace ${f.traceId}: ${f.status ?? ""} ${f.error ?? ""}`.trim();
|
|
69
91
|
}
|
|
70
|
-
/**
|
|
71
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Print the MLflow assessment/finish outcome after a run that created one. The
|
|
94
|
+
* summary line goes through `info` (stderr under a machine reporter); per-trace
|
|
95
|
+
* failures and finish errors always go to stderr.
|
|
96
|
+
*/
|
|
97
|
+
function printMlflowOutcome(mlflow, info) {
|
|
72
98
|
const { report, finish } = mlflow;
|
|
73
|
-
|
|
99
|
+
info(`MLflow: ${report.written} assessment(s) written` + (report.skipped ? `, ${report.skipped} skipped` : "") + (report.failures.length ? `, ${report.failures.length} failed` : ""));
|
|
74
100
|
for (const f of report.failures) console.error(formatFailureLine(f));
|
|
75
101
|
if (finish.metricsError) console.error(` ⚠ metrics not logged: ${finish.metricsError}`);
|
|
76
102
|
if (!finish.finished) console.error(` ✗ run left RUNNING — failed to finish: ${finish.finishError ?? "unknown"}`);
|
|
77
103
|
}
|
|
78
104
|
async function runAgentEval(filter, opts) {
|
|
79
105
|
const runner = await loadRunner();
|
|
80
|
-
const
|
|
106
|
+
const credentials = {
|
|
81
107
|
profile: opts.profile ?? process.env.DATABRICKS_CONFIG_PROFILE,
|
|
82
108
|
host: opts.databricksHost ?? process.env.DATABRICKS_HOST,
|
|
83
109
|
token: opts.databricksToken ?? process.env.DATABRICKS_TOKEN
|
|
84
|
-
}
|
|
110
|
+
};
|
|
111
|
+
const auth = await runner.resolveDatabricksAuth(credentials) ?? {};
|
|
85
112
|
const warehouseId = opts.warehouseId ?? process.env.DATABRICKS_WAREHOUSE_ID;
|
|
86
|
-
const workspaceClient = runner.resolveWorkspaceClient(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
113
|
+
const workspaceClient = runner.resolveWorkspaceClient(credentials);
|
|
114
|
+
const timeoutMs = positiveInt(opts.timeout);
|
|
115
|
+
const retries = positiveInt(opts.retries);
|
|
116
|
+
let minPassRate;
|
|
117
|
+
try {
|
|
118
|
+
minPassRate = parsePassRate(opts.minPassRate);
|
|
119
|
+
} catch (err) {
|
|
120
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
121
|
+
process.exitCode = 1;
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
const reporter = opts.reporter ?? "text";
|
|
125
|
+
const machine = reporter !== "text";
|
|
126
|
+
const info = (msg) => {
|
|
127
|
+
if (machine) console.error(msg);
|
|
128
|
+
else console.log(msg);
|
|
129
|
+
};
|
|
91
130
|
let summary;
|
|
92
131
|
try {
|
|
93
132
|
summary = await runner.runEvalsInDir({
|
|
94
133
|
rootDir: opts.root,
|
|
95
134
|
baseUrl: opts.url,
|
|
96
135
|
filter,
|
|
136
|
+
tags: opts.tag,
|
|
97
137
|
strict: opts.strict,
|
|
98
138
|
headers: opts.header ? parseHeaders(opts.header) : void 0,
|
|
99
139
|
concurrency: opts.concurrency,
|
|
@@ -101,19 +141,43 @@ async function runAgentEval(filter, opts) {
|
|
|
101
141
|
judge: resolveJudge(opts, auth),
|
|
102
142
|
workspaceClient,
|
|
103
143
|
warehouseId,
|
|
104
|
-
|
|
144
|
+
timeoutMs,
|
|
145
|
+
retries,
|
|
146
|
+
onEvent: makeProgressReporter(runner, opts.url, machine, info)
|
|
105
147
|
});
|
|
106
148
|
} catch (err) {
|
|
107
149
|
console.error(`\nEval run failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
108
150
|
process.exitCode = 1;
|
|
109
151
|
return;
|
|
110
152
|
}
|
|
111
|
-
|
|
112
|
-
if (summary.mlflow) printMlflowOutcome(summary.mlflow);
|
|
113
|
-
else
|
|
114
|
-
if (
|
|
153
|
+
info(`\n${runner.formatSummaryLine(summary.results)}`);
|
|
154
|
+
if (summary.mlflow) printMlflowOutcome(summary.mlflow, info);
|
|
155
|
+
else info("\nMLflow evaluation run skipped — pass --experiment (or set MLFLOW_EXPERIMENT_ID) plus --profile/--databricks-host to create one.");
|
|
156
|
+
if (machine) {
|
|
157
|
+
const report = reporter === "json" ? runner.formatResultsJson(summary.results) : runner.formatResultsJUnit(summary.results);
|
|
158
|
+
if (opts.output) {
|
|
159
|
+
try {
|
|
160
|
+
fs.writeFileSync(opts.output, `${report}\n`);
|
|
161
|
+
} catch (err) {
|
|
162
|
+
console.error(`Failed to write ${reporter} report to ${opts.output}: ${err instanceof Error ? err.message : String(err)}`);
|
|
163
|
+
process.exitCode = 1;
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
info(`Wrote ${reporter} report to ${opts.output}`);
|
|
167
|
+
} else process.stdout.write(`${report}\n`);
|
|
168
|
+
}
|
|
169
|
+
const stats = runner.summarize(summary.results);
|
|
170
|
+
if (minPassRate !== void 0) {
|
|
171
|
+
const ok = stats.passRate >= minPassRate;
|
|
172
|
+
info(`Pass rate ${(stats.passRate * 100).toFixed(0)}% (threshold ${(minPassRate * 100).toFixed(0)}%) — ${ok ? "OK" : "below threshold"}`);
|
|
173
|
+
if (!ok) process.exitCode = 1;
|
|
174
|
+
} else if (!stats.allPassed) process.exitCode = 1;
|
|
115
175
|
}
|
|
116
|
-
const agentEvalCommand = new Command("eval").description("Run agent evals (server/agents/<id>/evals/*.eval.ts) against a running app").argument("[filter]", "Only run evals whose <agent>/<id> contains this substring (or an exact agent id)").option("--url <url>", "Base URL of the running app", "http://localhost:3000").option("--strict", "Fail on soft-assertion misses too", false).option("--concurrency <n>", "Max evals to run concurrently (default 4; keep at or below the app's max concurrent streams per user)", (v) => Number.parseInt(v, 10)).option("--root <dir>", "Project root containing server/agents/ (default: cwd)").option("--header <header...>", "Extra request header as 'Key: value' (repeatable)").option("--profile <name>", "Databricks CLI profile to authenticate with via OAuth (default: DATABRICKS_CONFIG_PROFILE)").option("--databricks-host <host>", "Databricks host for writing MLflow assessments (default: DATABRICKS_HOST)").option("--databricks-token <token>", "Databricks token for writing MLflow assessments (default: DATABRICKS_TOKEN)").option("--experiment <id>", "MLflow experiment id for the evaluation run (default: MLFLOW_EXPERIMENT_ID)").option("--warehouse-id <id>", "SQL warehouse id for reading managed eval datasets and writing assessments to UC-backed experiments (default: DATABRICKS_WAREHOUSE_ID, or MLFLOW_TRACING_SQL_WAREHOUSE_ID for assessments)").option("--judge-model <endpoint>", "Databricks serving endpoint to use as the LLM judge for t.judge.* (default: APPKIT_JUDGE_MODEL)").
|
|
176
|
+
const agentEvalCommand = new Command("eval").description("Run agent evals (server/agents/<id>/evals/*.eval.ts) against a running app").argument("[filter]", "Only run evals whose <agent>/<id> contains this substring (or an exact agent id)").option("--url <url>", "Base URL of the running app", "http://localhost:3000").option("--strict", "Fail on soft-assertion misses too", false).option("--concurrency <n>", "Max evals to run concurrently (default 4; keep at or below the app's max concurrent streams per user)", (v) => Number.parseInt(v, 10)).option("--root <dir>", "Project root containing server/agents/ (default: cwd)").option("--header <header...>", "Extra request header as 'Key: value' (repeatable)").option("--tag <tag...>", "Only run evals tagged with one of these tags (repeatable)").option("--profile <name>", "Databricks CLI profile to authenticate with via OAuth (default: DATABRICKS_CONFIG_PROFILE)").option("--databricks-host <host>", "Databricks host for writing MLflow assessments (default: DATABRICKS_HOST)").option("--databricks-token <token>", "Databricks token for writing MLflow assessments (default: DATABRICKS_TOKEN)").option("--experiment <id>", "MLflow experiment id for the evaluation run (default: MLFLOW_EXPERIMENT_ID)").option("--warehouse-id <id>", "SQL warehouse id for reading managed eval datasets and writing assessments to UC-backed experiments (default: DATABRICKS_WAREHOUSE_ID, or MLFLOW_TRACING_SQL_WAREHOUSE_ID for assessments)").option("--judge-model <endpoint>", "Databricks serving endpoint to use as the LLM judge for t.judge.* (default: APPKIT_JUDGE_MODEL)").option("--timeout <ms>", "Default per-eval timeout in ms (a per-eval timeoutMs overrides it)").option("--retries <n>", "Re-run an eval up to N times when it fails on an infra error (turn/timeout); assertion failures are not retried").option("--min-pass-rate <rate>", "Gate on aggregate pass rate (0..1) instead of requiring every eval to pass; exit 1 when below").addOption(new Option("--reporter <format>", "Report format: text (live console), json (dashboards), or junit (CI test reporters)").choices([
|
|
177
|
+
"text",
|
|
178
|
+
"json",
|
|
179
|
+
"junit"
|
|
180
|
+
]).default("text")).option("--output <file>", "Write the json/junit report to this file instead of stdout (ignored for text)").action(runAgentEval);
|
|
117
181
|
|
|
118
182
|
//#endregion
|
|
119
183
|
export { agentEvalCommand };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"eval.js","names":[],"sources":["../../../../src/cli/commands/agent/eval.ts"],"sourcesContent":["import { Command } from \"commander\";\n\ninterface EvalRunSummary {\n results: unknown[];\n mlflow?: {\n runId: string;\n report: {\n written: number;\n skipped: number;\n failures: Array<{ traceId: string; status?: number; error?: string }>;\n };\n finish: { finished: boolean; metricsError?: string; finishError?: string };\n };\n}\n\ntype EvalProgress =\n | { type: \"discovered\"; total: number }\n | { type: \"run-created\"; runId: string }\n | { type: \"start\"; id: string; index: number; total: number }\n | { type: \"result\"; result: unknown; index: number; total: number };\n\n/** Subset of `@databricks/appkit/beta`'s eval runner used by this command. */\ninterface EvalRunner {\n runEvalsInDir(opts: {\n rootDir?: string;\n baseUrl: string;\n filter?: string;\n strict?: boolean;\n headers?: Record<string, string>;\n concurrency?: number;\n mlflow?: {\n host: string;\n token: string;\n experimentId: string;\n sqlWarehouseId?: string;\n };\n judge?: { host: string; token: string; model: string };\n workspaceClient?: unknown;\n warehouseId?: string;\n onEvent?: (event: EvalProgress) => void;\n }): Promise<EvalRunSummary>;\n resolveDatabricksAuth(opts: {\n profile?: string;\n host?: string;\n token?: string;\n }): Promise<{ host: string; token: string } | undefined>;\n resolveWorkspaceClient(opts: {\n profile?: string;\n host?: string;\n token?: string;\n }): unknown;\n formatEvalHeadline(result: unknown): string;\n evalGlyph(result: unknown): string;\n formatEvalDetail(result: unknown): string[];\n formatSummaryLine(results: unknown[]): string;\n summarize(results: unknown[]): { allPassed: boolean };\n}\n\n/**\n * Loaded at runtime from the consuming project so this command (which ships in\n * `@databricks/shared`) doesn't take a build-time dependency on appkit. The\n * specifier is a variable so the type checker treats it as `any`.\n */\nasync function loadRunner(): Promise<EvalRunner> {\n const spec = \"@databricks/appkit/beta\";\n try {\n return (await import(spec)) as unknown as EvalRunner;\n } catch (err) {\n throw new Error(\n \"Could not load @databricks/appkit. Run `appkit agent eval` from a \" +\n \"project with @databricks/appkit installed. \" +\n `Cause: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n}\n\nfunction parseHeaders(values: string[]): Record<string, string> {\n const headers: Record<string, string> = {};\n for (const v of values) {\n const i = v.indexOf(\":\");\n if (i === -1) continue;\n headers[v.slice(0, i).trim()] = v.slice(i + 1).trim();\n }\n return headers;\n}\n\ninterface EvalOptions {\n url: string;\n strict?: boolean;\n root?: string;\n header?: string[];\n profile?: string;\n databricksHost?: string;\n databricksToken?: string;\n experiment?: string;\n judgeModel?: string;\n concurrency?: number;\n warehouseId?: string;\n}\n\n/** Resolved Databricks host + bearer (either field may be absent). */\ntype Auth = { host?: string; token?: string };\n\n/**\n * Native MLflow \"Evaluation run\" config — only when creds + an experiment are\n * all present (traces live in the app; the run + scores are driven from here).\n */\nfunction resolveMlflow(opts: EvalOptions, auth: Auth) {\n const experimentId = opts.experiment ?? process.env.MLFLOW_EXPERIMENT_ID;\n if (!(auth.host && auth.token && experimentId)) return undefined;\n // UC-backed experiments need a SQL warehouse to write assessments to their\n // V4 traces. Mirror mlflow's env var, and accept the common DATABRICKS one.\n const sqlWarehouseId =\n opts.warehouseId ??\n process.env.MLFLOW_TRACING_SQL_WAREHOUSE_ID ??\n process.env.DATABRICKS_WAREHOUSE_ID;\n return {\n host: auth.host,\n token: auth.token,\n experimentId,\n ...(sqlWarehouseId ? { sqlWarehouseId } : {}),\n };\n}\n\n/** LLM-as-judge config — reuses the Databricks creds + a judge serving endpoint. */\nfunction resolveJudge(opts: EvalOptions, auth: Auth) {\n const model = opts.judgeModel ?? process.env.APPKIT_JUDGE_MODEL;\n return model && auth.host && auth.token\n ? { host: auth.host, token: auth.token, model }\n : undefined;\n}\n\n/** Progress reporter: stream each eval as it runs instead of going silent. */\nfunction makeProgressReporter(\n runner: EvalRunner,\n url: string,\n): (event: EvalProgress) => void {\n return (event) => {\n switch (event.type) {\n case \"discovered\":\n console.log(\n `Running ${event.total} eval${event.total === 1 ? \"\" : \"s\"} against ${url}\\n`,\n );\n break;\n case \"run-created\":\n console.log(`MLflow evaluation run: ${event.runId}\\n`);\n break;\n case \"result\": {\n // One full line per completion — evals run concurrently, so a split\n // \"start … glyph\" prefix would interleave into garbage.\n console.log(\n `[${event.index + 1}/${event.total}] ${runner.formatEvalHeadline(event.result)}`,\n );\n for (const line of runner.formatEvalDetail(event.result)) {\n console.log(line);\n }\n break;\n }\n }\n };\n}\n\nfunction formatFailureLine(f: {\n traceId: string;\n status?: number;\n error?: string;\n}): string {\n return ` ✗ trace ${f.traceId}: ${f.status ?? \"\"} ${f.error ?? \"\"}`.trim();\n}\n\n/** Print the MLflow assessment/finish outcome after a run that created one. */\nfunction printMlflowOutcome(\n mlflow: NonNullable<EvalRunSummary[\"mlflow\"]>,\n): void {\n const { report, finish } = mlflow;\n console.log(\n `MLflow: ${report.written} assessment(s) written` +\n (report.skipped ? `, ${report.skipped} skipped` : \"\") +\n (report.failures.length ? `, ${report.failures.length} failed` : \"\"),\n );\n for (const f of report.failures) {\n console.error(formatFailureLine(f));\n }\n if (finish.metricsError) {\n console.error(` ⚠ metrics not logged: ${finish.metricsError}`);\n }\n if (!finish.finished) {\n console.error(\n ` ✗ run left RUNNING — failed to finish: ${finish.finishError ?? \"unknown\"}`,\n );\n }\n}\n\nasync function runAgentEval(\n filter: string | undefined,\n opts: EvalOptions,\n): Promise<void> {\n const runner = await loadRunner();\n\n // Resolve Databricks host + bearer the AppKit-native way: an explicit\n // host/token (or DATABRICKS_* env) wins; otherwise the SDK mints an OAuth\n // token from the CLI profile — so no hand-set PAT is required.\n const auth: Auth =\n (await runner.resolveDatabricksAuth({\n profile: opts.profile ?? process.env.DATABRICKS_CONFIG_PROFILE,\n host: opts.databricksHost ?? process.env.DATABRICKS_HOST,\n token: opts.databricksToken ?? process.env.DATABRICKS_TOKEN,\n })) ?? {};\n\n // Managed-dataset reads: a workspace client (same profile/host/token) + a SQL\n // warehouse. Only needed by evals that declare `dataset`.\n const warehouseId = opts.warehouseId ?? process.env.DATABRICKS_WAREHOUSE_ID;\n const workspaceClient = runner.resolveWorkspaceClient({\n profile: opts.profile ?? process.env.DATABRICKS_CONFIG_PROFILE,\n host: opts.databricksHost ?? process.env.DATABRICKS_HOST,\n token: opts.databricksToken ?? process.env.DATABRICKS_TOKEN,\n });\n\n let summary: EvalRunSummary;\n try {\n summary = await runner.runEvalsInDir({\n rootDir: opts.root,\n baseUrl: opts.url,\n filter,\n strict: opts.strict,\n headers: opts.header ? parseHeaders(opts.header) : undefined,\n concurrency: opts.concurrency,\n mlflow: resolveMlflow(opts, auth),\n judge: resolveJudge(opts, auth),\n workspaceClient,\n warehouseId,\n onEvent: makeProgressReporter(runner, opts.url),\n });\n } catch (err) {\n // Setup failures (e.g. a bad --experiment for the MLflow run) reject before\n // any eval runs; surface a clean message + non-zero exit rather than an\n // unhandled promise rejection with a raw stack.\n console.error(\n `\\nEval run failed: ${err instanceof Error ? err.message : String(err)}`,\n );\n process.exitCode = 1;\n return;\n }\n console.log(`\\n${runner.formatSummaryLine(summary.results)}`);\n\n if (summary.mlflow) {\n printMlflowOutcome(summary.mlflow);\n } else {\n console.log(\n \"\\nMLflow evaluation run skipped — pass --experiment (or set\" +\n \" MLFLOW_EXPERIMENT_ID) plus --profile/--databricks-host to create one.\",\n );\n }\n\n if (!runner.summarize(summary.results).allPassed) {\n process.exitCode = 1;\n }\n}\n\nexport const agentEvalCommand = new Command(\"eval\")\n .description(\n \"Run agent evals (server/agents/<id>/evals/*.eval.ts) against a running app\",\n )\n .argument(\n \"[filter]\",\n \"Only run evals whose <agent>/<id> contains this substring (or an exact agent id)\",\n )\n .option(\"--url <url>\", \"Base URL of the running app\", \"http://localhost:3000\")\n .option(\"--strict\", \"Fail on soft-assertion misses too\", false)\n .option(\n \"--concurrency <n>\",\n \"Max evals to run concurrently (default 4; keep at or below the app's max concurrent streams per user)\",\n (v) => Number.parseInt(v, 10),\n )\n .option(\n \"--root <dir>\",\n \"Project root containing server/agents/ (default: cwd)\",\n )\n .option(\n \"--header <header...>\",\n \"Extra request header as 'Key: value' (repeatable)\",\n )\n .option(\n \"--profile <name>\",\n \"Databricks CLI profile to authenticate with via OAuth (default: DATABRICKS_CONFIG_PROFILE)\",\n )\n .option(\n \"--databricks-host <host>\",\n \"Databricks host for writing MLflow assessments (default: DATABRICKS_HOST)\",\n )\n .option(\n \"--databricks-token <token>\",\n \"Databricks token for writing MLflow assessments (default: DATABRICKS_TOKEN)\",\n )\n .option(\n \"--experiment <id>\",\n \"MLflow experiment id for the evaluation run (default: MLFLOW_EXPERIMENT_ID)\",\n )\n .option(\n \"--warehouse-id <id>\",\n \"SQL warehouse id for reading managed eval datasets and writing assessments to UC-backed experiments (default: DATABRICKS_WAREHOUSE_ID, or MLFLOW_TRACING_SQL_WAREHOUSE_ID for assessments)\",\n )\n .option(\n \"--judge-model <endpoint>\",\n \"Databricks serving endpoint to use as the LLM judge for t.judge.* (default: APPKIT_JUDGE_MODEL)\",\n )\n .action(runAgentEval);\n"],"mappings":";;;;;;;;AA+DA,eAAe,aAAkC;CAC/C,MAAM,OAAO;AACb,KAAI;AACF,SAAQ,MAAM,OAAO;UACd,KAAK;AACZ,QAAM,IAAI,MACR,yHAEY,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI,GAC7D;;;AA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,eAAe,QAAQ,IAAI,UAAU,OAAO,IAAI,GACvE;AACD,UAAQ,WAAW;AACnB;;AAEF,SAAQ,IAAI,KAAK,OAAO,kBAAkB,QAAQ,QAAQ,GAAG;AAE7D,KAAI,QAAQ,OACV,oBAAmB,QAAQ,OAAO;KAElC,SAAQ,IACN,oIAED;AAGH,KAAI,CAAC,OAAO,UAAU,QAAQ,QAAQ,CAAC,UACrC,SAAQ,WAAW;;AAIvB,MAAa,mBAAmB,IAAI,QAAQ,OAAO,CAChD,YACC,6EACD,CACA,SACC,YACA,mFACD,CACA,OAAO,eAAe,+BAA+B,wBAAwB,CAC7E,OAAO,YAAY,qCAAqC,MAAM,CAC9D,OACC,qBACA,0GACC,MAAM,OAAO,SAAS,GAAG,GAAG,CAC9B,CACA,OACC,gBACA,wDACD,CACA,OACC,wBACA,oDACD,CACA,OACC,oBACA,6FACD,CACA,OACC,4BACA,4EACD,CACA,OACC,8BACA,8EACD,CACA,OACC,qBACA,8EACD,CACA,OACC,uBACA,6LACD,CACA,OACC,4BACA,kGACD,CACA,OAAO,aAAa"}
|
|
1
|
+
{"version":3,"file":"eval.js","names":[],"sources":["../../../../src/cli/commands/agent/eval.ts"],"sourcesContent":["import fs from \"node:fs\";\n\nimport { Command, Option } from \"commander\";\n\ninterface EvalRunSummary {\n results: unknown[];\n mlflow?: {\n runId: string;\n report: {\n written: number;\n skipped: number;\n failures: Array<{ traceId: string; status?: number; error?: string }>;\n };\n finish: { finished: boolean; metricsError?: string; finishError?: string };\n };\n}\n\ntype EvalProgress =\n | { type: \"discovered\"; total: number }\n | { type: \"run-created\"; runId: string }\n | { type: \"start\"; id: string; index: number; total: number }\n | { type: \"result\"; result: unknown; index: number; total: number };\n\n/** Subset of `@databricks/appkit/beta`'s eval runner used by this command. */\ninterface EvalRunner {\n runEvalsInDir(opts: {\n rootDir?: string;\n baseUrl: string;\n filter?: string;\n tags?: string[];\n strict?: boolean;\n headers?: Record<string, string>;\n concurrency?: number;\n mlflow?: {\n host: string;\n token: string;\n experimentId: string;\n sqlWarehouseId?: string;\n };\n judge?: { host: string; token: string; model: string };\n workspaceClient?: unknown;\n warehouseId?: string;\n timeoutMs?: number;\n retries?: number;\n onEvent?: (event: EvalProgress) => void;\n }): Promise<EvalRunSummary>;\n resolveDatabricksAuth(opts: {\n profile?: string;\n host?: string;\n token?: string;\n }): Promise<{ host: string; token: string } | undefined>;\n resolveWorkspaceClient(opts: {\n profile?: string;\n host?: string;\n token?: string;\n }): unknown;\n formatEvalHeadline(result: unknown): string;\n evalGlyph(result: unknown): string;\n formatEvalDetail(result: unknown): string[];\n formatSummaryLine(results: unknown[]): string;\n formatResultsJson(results: unknown[]): string;\n formatResultsJUnit(results: unknown[]): string;\n summarize(results: unknown[]): { allPassed: boolean; passRate: number };\n}\n\n/**\n * Loaded at runtime from the consuming project so this command (which ships in\n * `@databricks/shared`) doesn't take a build-time dependency on appkit. The\n * specifier is a variable so the type checker treats it as `any`.\n */\nasync function loadRunner(): Promise<EvalRunner> {\n const spec = \"@databricks/appkit/beta\";\n try {\n return (await import(spec)) as unknown as EvalRunner;\n } catch (err) {\n throw new Error(\n \"Could not load @databricks/appkit. Run `appkit agent eval` from a \" +\n \"project with @databricks/appkit installed. \" +\n `Cause: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n}\n\nfunction parseHeaders(values: string[]): Record<string, string> {\n const headers: Record<string, string> = {};\n for (const v of values) {\n const i = v.indexOf(\":\");\n if (i === -1) continue;\n headers[v.slice(0, i).trim()] = v.slice(i + 1).trim();\n }\n return headers;\n}\n\n/**\n * Parse `--min-pass-rate`: a finite number in `[0, 1]`, or `undefined` when\n * unset. Throws on blank, out-of-range, or non-numeric input so a bad gate\n * value fails fast instead of silently disabling or inverting the CI gate.\n */\nexport function parsePassRate(raw: string | undefined): number | undefined {\n if (raw === undefined) return undefined;\n const n = Number(raw);\n // Reject blank too: `Number(\"\")` is 0, which would silently disable the gate.\n if (raw.trim() === \"\" || !Number.isFinite(n) || n < 0 || n > 1) {\n throw new Error(\n `Invalid --min-pass-rate \"${raw}\" — expected a number in [0, 1]`,\n );\n }\n return n;\n}\n\n/** Parse a positive-integer CLI option; junk, zero, or negative → undefined. */\nfunction positiveInt(raw: string | undefined): number | undefined {\n const n = raw ? Number.parseInt(raw, 10) : Number.NaN;\n return n > 0 ? n : undefined;\n}\n\ninterface EvalOptions {\n url: string;\n strict?: boolean;\n root?: string;\n header?: string[];\n tag?: string[];\n profile?: string;\n databricksHost?: string;\n databricksToken?: string;\n experiment?: string;\n judgeModel?: string;\n concurrency?: number;\n warehouseId?: string;\n timeout?: string;\n retries?: string;\n minPassRate?: string;\n reporter?: \"text\" | \"json\" | \"junit\";\n output?: string;\n}\n\n/** Resolved Databricks host + bearer (either field may be absent). */\ntype Auth = { host?: string; token?: string };\n\n/**\n * Native MLflow \"Evaluation run\" config — only when creds + an experiment are\n * all present (traces live in the app; the run + scores are driven from here).\n */\nfunction resolveMlflow(opts: EvalOptions, auth: Auth) {\n const experimentId = opts.experiment ?? process.env.MLFLOW_EXPERIMENT_ID;\n if (!(auth.host && auth.token && experimentId)) return undefined;\n // UC-backed experiments need a SQL warehouse to write assessments to their\n // V4 traces. Mirror mlflow's env var, and accept the common DATABRICKS one.\n const sqlWarehouseId =\n opts.warehouseId ??\n process.env.MLFLOW_TRACING_SQL_WAREHOUSE_ID ??\n process.env.DATABRICKS_WAREHOUSE_ID;\n return {\n host: auth.host,\n token: auth.token,\n experimentId,\n ...(sqlWarehouseId ? { sqlWarehouseId } : {}),\n };\n}\n\n/** LLM-as-judge config — reuses the Databricks creds + a judge serving endpoint. */\nfunction resolveJudge(opts: EvalOptions, auth: Auth) {\n const model = opts.judgeModel ?? process.env.APPKIT_JUDGE_MODEL;\n return model && auth.host && auth.token\n ? { host: auth.host, token: auth.token, model }\n : undefined;\n}\n\n/**\n * Progress reporter: stream each eval as it runs instead of going silent. In a\n * machine reporter (json/junit) the live per-eval streaming is suppressed and\n * banners go to stderr (via `info`), keeping stdout clean for the report.\n */\nfunction makeProgressReporter(\n runner: EvalRunner,\n url: string,\n machine: boolean,\n info: (msg: string) => void,\n): (event: EvalProgress) => void {\n return (event) => {\n switch (event.type) {\n case \"discovered\":\n info(\n `Running ${event.total} eval${event.total === 1 ? \"\" : \"s\"} against ${url}\\n`,\n );\n break;\n case \"run-created\":\n info(`MLflow evaluation run: ${event.runId}\\n`);\n break;\n case \"result\": {\n if (machine) break;\n // One full line per completion — evals run concurrently, so a split\n // \"start … glyph\" prefix would interleave into garbage.\n console.log(\n `[${event.index + 1}/${event.total}] ${runner.formatEvalHeadline(event.result)}`,\n );\n for (const line of runner.formatEvalDetail(event.result)) {\n console.log(line);\n }\n break;\n }\n }\n };\n}\n\nfunction formatFailureLine(f: {\n traceId: string;\n status?: number;\n error?: string;\n}): string {\n return ` ✗ trace ${f.traceId}: ${f.status ?? \"\"} ${f.error ?? \"\"}`.trim();\n}\n\n/**\n * Print the MLflow assessment/finish outcome after a run that created one. The\n * summary line goes through `info` (stderr under a machine reporter); per-trace\n * failures and finish errors always go to stderr.\n */\nfunction printMlflowOutcome(\n mlflow: NonNullable<EvalRunSummary[\"mlflow\"]>,\n info: (msg: string) => void,\n): void {\n const { report, finish } = mlflow;\n info(\n `MLflow: ${report.written} assessment(s) written` +\n (report.skipped ? `, ${report.skipped} skipped` : \"\") +\n (report.failures.length ? `, ${report.failures.length} failed` : \"\"),\n );\n for (const f of report.failures) {\n console.error(formatFailureLine(f));\n }\n if (finish.metricsError) {\n console.error(` ⚠ metrics not logged: ${finish.metricsError}`);\n }\n if (!finish.finished) {\n console.error(\n ` ✗ run left RUNNING — failed to finish: ${finish.finishError ?? \"unknown\"}`,\n );\n }\n}\n\nasync function runAgentEval(\n filter: string | undefined,\n opts: EvalOptions,\n): Promise<void> {\n const runner = await loadRunner();\n\n // Databricks credentials shared by auth resolution and the workspace client:\n // an explicit flag/DATABRICKS_* env wins, else the SDK resolves from the CLI\n // profile.\n const credentials = {\n profile: opts.profile ?? process.env.DATABRICKS_CONFIG_PROFILE,\n host: opts.databricksHost ?? process.env.DATABRICKS_HOST,\n token: opts.databricksToken ?? process.env.DATABRICKS_TOKEN,\n };\n\n // Resolve Databricks host + bearer the AppKit-native way: an explicit\n // host/token wins; otherwise the SDK mints an OAuth token from the CLI\n // profile — so no hand-set PAT is required.\n const auth: Auth = (await runner.resolveDatabricksAuth(credentials)) ?? {};\n\n // Managed-dataset reads: a workspace client (same profile/host/token) + a SQL\n // warehouse. Only needed by evals that declare `dataset`.\n const warehouseId = opts.warehouseId ?? process.env.DATABRICKS_WAREHOUSE_ID;\n const workspaceClient = runner.resolveWorkspaceClient(credentials);\n\n // Runner-level default per-eval timeout (ms). A per-eval `timeoutMs` wins.\n const timeoutMs = positiveInt(opts.timeout);\n\n // Extra attempts for evals that fail on an infra error (turn/timeout). Junk\n // or negative input falls back to no retries.\n const retries = positiveInt(opts.retries);\n\n // Validate up front so a bad gate value fails before the run, not after.\n let minPassRate: number | undefined;\n try {\n minPassRate = parsePassRate(opts.minPassRate);\n } catch (err) {\n console.error(err instanceof Error ? err.message : String(err));\n process.exitCode = 1;\n return;\n }\n\n // In a machine reporter (json/junit), stdout is reserved for the report (it\n // may be piped), so human-facing lines go to stderr and the per-eval live\n // streaming is suppressed. Text mode keeps its current stdout behavior.\n const reporter = opts.reporter ?? \"text\";\n const machine = reporter !== \"text\";\n const info = (msg: string): void => {\n if (machine) console.error(msg);\n else console.log(msg);\n };\n\n let summary: EvalRunSummary;\n try {\n summary = await runner.runEvalsInDir({\n rootDir: opts.root,\n baseUrl: opts.url,\n filter,\n tags: opts.tag,\n strict: opts.strict,\n headers: opts.header ? parseHeaders(opts.header) : undefined,\n concurrency: opts.concurrency,\n mlflow: resolveMlflow(opts, auth),\n judge: resolveJudge(opts, auth),\n workspaceClient,\n warehouseId,\n timeoutMs,\n retries,\n onEvent: makeProgressReporter(runner, opts.url, machine, info),\n });\n } catch (err) {\n // Setup failures (e.g. a bad --experiment for the MLflow run) reject before\n // any eval runs; surface a clean message + non-zero exit rather than an\n // unhandled promise rejection with a raw stack.\n console.error(\n `\\nEval run failed: ${err instanceof Error ? err.message : String(err)}`,\n );\n process.exitCode = 1;\n return;\n }\n\n // The final human summary always shows (stderr for machine reporters so it\n // never pollutes the report on stdout/file).\n info(`\\n${runner.formatSummaryLine(summary.results)}`);\n\n if (summary.mlflow) {\n printMlflowOutcome(summary.mlflow, info);\n } else {\n info(\n \"\\nMLflow evaluation run skipped — pass --experiment (or set\" +\n \" MLFLOW_EXPERIMENT_ID) plus --profile/--databricks-host to create one.\",\n );\n }\n\n // Machine-readable report: build the string with a pure formatter, then emit\n // it to --output <file> or stdout (kept clean of the human noise above).\n if (machine) {\n const report =\n reporter === \"json\"\n ? runner.formatResultsJson(summary.results)\n : runner.formatResultsJUnit(summary.results);\n if (opts.output) {\n try {\n fs.writeFileSync(opts.output, `${report}\\n`);\n } catch (err) {\n console.error(\n `Failed to write ${reporter} report to ${opts.output}: ${\n err instanceof Error ? err.message : String(err)\n }`,\n );\n process.exitCode = 1;\n return;\n }\n info(`Wrote ${reporter} report to ${opts.output}`);\n } else {\n process.stdout.write(`${report}\\n`);\n }\n }\n\n const stats = runner.summarize(summary.results);\n if (minPassRate !== undefined) {\n // Threshold mode: gate on the aggregate pass rate rather than requiring\n // every eval to pass.\n const ok = stats.passRate >= minPassRate;\n info(\n `Pass rate ${(stats.passRate * 100).toFixed(0)}% (threshold ${(\n minPassRate * 100\n ).toFixed(0)}%) — ${ok ? \"OK\" : \"below threshold\"}`,\n );\n if (!ok) process.exitCode = 1;\n } else if (!stats.allPassed) {\n process.exitCode = 1;\n }\n}\n\nexport const agentEvalCommand = new Command(\"eval\")\n .description(\n \"Run agent evals (server/agents/<id>/evals/*.eval.ts) against a running app\",\n )\n .argument(\n \"[filter]\",\n \"Only run evals whose <agent>/<id> contains this substring (or an exact agent id)\",\n )\n .option(\"--url <url>\", \"Base URL of the running app\", \"http://localhost:3000\")\n .option(\"--strict\", \"Fail on soft-assertion misses too\", false)\n .option(\n \"--concurrency <n>\",\n \"Max evals to run concurrently (default 4; keep at or below the app's max concurrent streams per user)\",\n (v) => Number.parseInt(v, 10),\n )\n .option(\n \"--root <dir>\",\n \"Project root containing server/agents/ (default: cwd)\",\n )\n .option(\n \"--header <header...>\",\n \"Extra request header as 'Key: value' (repeatable)\",\n )\n .option(\n \"--tag <tag...>\",\n \"Only run evals tagged with one of these tags (repeatable)\",\n )\n .option(\n \"--profile <name>\",\n \"Databricks CLI profile to authenticate with via OAuth (default: DATABRICKS_CONFIG_PROFILE)\",\n )\n .option(\n \"--databricks-host <host>\",\n \"Databricks host for writing MLflow assessments (default: DATABRICKS_HOST)\",\n )\n .option(\n \"--databricks-token <token>\",\n \"Databricks token for writing MLflow assessments (default: DATABRICKS_TOKEN)\",\n )\n .option(\n \"--experiment <id>\",\n \"MLflow experiment id for the evaluation run (default: MLFLOW_EXPERIMENT_ID)\",\n )\n .option(\n \"--warehouse-id <id>\",\n \"SQL warehouse id for reading managed eval datasets and writing assessments to UC-backed experiments (default: DATABRICKS_WAREHOUSE_ID, or MLFLOW_TRACING_SQL_WAREHOUSE_ID for assessments)\",\n )\n .option(\n \"--judge-model <endpoint>\",\n \"Databricks serving endpoint to use as the LLM judge for t.judge.* (default: APPKIT_JUDGE_MODEL)\",\n )\n .option(\n \"--timeout <ms>\",\n \"Default per-eval timeout in ms (a per-eval timeoutMs overrides it)\",\n )\n .option(\n \"--retries <n>\",\n \"Re-run an eval up to N times when it fails on an infra error (turn/timeout); assertion failures are not retried\",\n )\n .option(\n \"--min-pass-rate <rate>\",\n \"Gate on aggregate pass rate (0..1) instead of requiring every eval to pass; exit 1 when below\",\n )\n .addOption(\n new Option(\n \"--reporter <format>\",\n \"Report format: text (live console), json (dashboards), or junit (CI test reporters)\",\n )\n .choices([\"text\", \"json\", \"junit\"])\n .default(\"text\"),\n )\n .option(\n \"--output <file>\",\n \"Write the json/junit report to this file instead of stdout (ignored for text)\",\n )\n .action(runAgentEval);\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
130
130
|
};
|
|
131
131
|
}
|
|
132
|
-
|
|
132
|
+
/** Splits an npm spec into `name` and optional version `range`, handling the
|
|
133
|
+
* leading `@` of scoped names (`@databricks/appkit-ui@^0.41.0` → name
|
|
134
|
+
* `@databricks/appkit-ui`, range `^0.41.0`; `lodash` → no range). */
|
|
135
|
+
function parseDepSpec(spec) {
|
|
136
|
+
const at = spec.lastIndexOf("@");
|
|
137
|
+
if (at <= 0) return { name: spec };
|
|
138
|
+
return {
|
|
139
|
+
name: spec.slice(0, at),
|
|
140
|
+
range: spec.slice(at + 1)
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Registry `dependencies` are floors ("needs at least this version"), not pins.
|
|
145
|
+
* Against the versions already in the target `package.json`, returns which specs
|
|
146
|
+
* to install: missing packages (as declared) and genuine upgrades (installed
|
|
147
|
+
* floor below the requested floor). A package already at a same-or-newer version
|
|
148
|
+
* is skipped so the package manager never downgrades it; ranges that can't be
|
|
149
|
+
* compared (workspace:*, catalog:, git) are skipped for the same reason.
|
|
150
|
+
*
|
|
151
|
+
* `semver` is injected so the caller can lazy-load it (see `installDependencies`).
|
|
152
|
+
*/
|
|
153
|
+
function reconcileDeps(specs, installed, { gte, minVersion }) {
|
|
154
|
+
const floor = (range) => {
|
|
155
|
+
try {
|
|
156
|
+
return minVersion(range)?.version ?? null;
|
|
157
|
+
} catch {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
const install = [];
|
|
162
|
+
const skipped = [];
|
|
163
|
+
for (const spec of specs) {
|
|
164
|
+
const { name, range } = parseDepSpec(spec);
|
|
165
|
+
const have = installed[name];
|
|
166
|
+
if (!have) {
|
|
167
|
+
install.push(spec);
|
|
168
|
+
continue;
|
|
169
|
+
}
|
|
170
|
+
if (!range) {
|
|
171
|
+
skipped.push(spec);
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
const reqFloor = floor(range);
|
|
175
|
+
const haveFloor = floor(have);
|
|
176
|
+
if (!reqFloor || !haveFloor) skipped.push(spec);
|
|
177
|
+
else if (gte(haveFloor, reqFloor)) skipped.push(spec);
|
|
178
|
+
else install.push(spec);
|
|
179
|
+
}
|
|
180
|
+
return {
|
|
181
|
+
install,
|
|
182
|
+
skipped
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/** Merged dependencies + devDependencies (name → declared range) of a
|
|
186
|
+
* package.json, tolerating a missing/unreadable file (returns {}). */
|
|
187
|
+
function readInstalledRanges(pkgPath) {
|
|
188
|
+
try {
|
|
189
|
+
const pkg = JSON.parse(fs.readFileSync(pkgPath, "utf-8"));
|
|
190
|
+
return {
|
|
191
|
+
...pkg.dependencies,
|
|
192
|
+
...pkg.devDependencies
|
|
193
|
+
};
|
|
194
|
+
} catch {
|
|
195
|
+
return {};
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
async function installDependencies(deps, cwd) {
|
|
133
199
|
if (deps.length === 0) return;
|
|
134
200
|
const { safe, rejected } = partitionDeps(deps);
|
|
135
201
|
if (rejected.length > 0) console.warn(pc.yellow(`Skipping suspicious dependenc${rejected.length === 1 ? "y" : "ies"} from the registry (not a plain name@version): ${rejected.join(", ")}. Install manually if you trust them.`));
|
|
136
202
|
if (safe.length === 0) return;
|
|
137
|
-
|
|
203
|
+
const pkgPath = path.join(cwd, "package.json");
|
|
204
|
+
if (!fs.existsSync(pkgPath)) {
|
|
138
205
|
console.warn(pc.yellow(`No package.json found — install these manually: ${safe.join(" ")}`));
|
|
139
206
|
return;
|
|
140
207
|
}
|
|
208
|
+
const semver = await import("semver");
|
|
209
|
+
const { install, skipped } = reconcileDeps(safe, readInstalledRanges(pkgPath), semver);
|
|
210
|
+
if (skipped.length > 0) console.log(pc.dim(`Keeping already-installed (registry asked for an older/equal range): ${skipped.join(", ")}`));
|
|
211
|
+
if (install.length === 0) return;
|
|
141
212
|
const pm = detectPackageManager(cwd);
|
|
142
213
|
const subcommand = pm === "npm" ? "install" : "add";
|
|
143
|
-
console.log(`\nInstalling dependencies with ${pm}: ${
|
|
214
|
+
console.log(`\nInstalling dependencies with ${pm}: ${install.join(" ")}`);
|
|
144
215
|
const result = spawnSync(pm, [
|
|
145
216
|
subcommand,
|
|
146
217
|
"--",
|
|
147
|
-
...
|
|
218
|
+
...install
|
|
148
219
|
], {
|
|
149
220
|
stdio: "inherit",
|
|
150
221
|
cwd
|
|
151
222
|
});
|
|
152
|
-
if (result.status !== 0) console.warn(pc.yellow(`Dependency install exited with code ${result.status ?? "unknown"} — install manually if needed: ${
|
|
223
|
+
if (result.status !== 0) console.warn(pc.yellow(`Dependency install exited with code ${result.status ?? "unknown"} — install manually if needed: ${install.join(" ")}`));
|
|
153
224
|
}
|
|
154
225
|
/** Runs `appkit plugin sync --write` via this same CLI binary. */
|
|
155
226
|
function runPluginSync(cwd) {
|
|
@@ -281,7 +352,7 @@ async function runAdd(refs, opts) {
|
|
|
281
352
|
wroteUi = true;
|
|
282
353
|
}
|
|
283
354
|
}
|
|
284
|
-
installDependencies([...deps], findNearestPackageJson(cwd));
|
|
355
|
+
await installDependencies([...deps], findNearestPackageJson(cwd));
|
|
285
356
|
if (hasPlugin) {
|
|
286
357
|
console.log(pc.dim("\nRegistering plugins (appkit plugin sync)..."));
|
|
287
358
|
runPluginSync(cwd);
|