vieval 0.0.7 → 0.0.8

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.
@@ -1,4 +1,4 @@
1
- import { D as TaskRunContext, f as MatrixDefinition, t as ConfigHookPlugin, w as TaskExecutionPolicy, z as ModelDefinition } from "../../index-5R1_k2nv.mjs";
1
+ import { D as TaskRunContext, R as ModelDefinition, f as MatrixDefinition, t as ConfigHookPlugin, w as TaskExecutionPolicy } from "../../index-BkjyCInx.mjs";
2
2
 
3
3
  //#region src/plugins/chat-models/runtime-config.d.ts
4
4
  /**
@@ -80,7 +80,7 @@ type ChatModelRuntimeConfig = OpenAIChatModelRuntimeConfig | OllamaChatModelRunt
80
80
  * Normalizes one configured chat model into runtime executor config.
81
81
  *
82
82
  * Use when:
83
- * - eval code needs typed provider constructor options from `context.model()`
83
+ * - eval code needs typed provider constructor options from a resolved model
84
84
  * - model parameters should be validated once with clear error messages
85
85
  *
86
86
  * Expects:
@@ -95,7 +95,7 @@ declare function toChatModelRuntimeConfig(model: ModelDefinition): ChatModelRunt
95
95
  * Resolves OpenAI runtime config from one resolved run-context model.
96
96
  *
97
97
  * Use when:
98
- * - task execution already has `context.model()` output
98
+ * - task execution already has a model resolved through chat-model helpers
99
99
  * - eval code wants typed OpenAI provider options with a concise helper name
100
100
  *
101
101
  * Expects:
@@ -109,7 +109,7 @@ declare function openaiFromRunContext(model: ModelDefinition): OpenAIChatModelRu
109
109
  * Resolves Ollama runtime config from one resolved run-context model.
110
110
  *
111
111
  * Use when:
112
- * - task execution already has `context.model()` output
112
+ * - task execution already has a model resolved through chat-model helpers
113
113
  * - eval code wants typed Ollama provider options with a concise helper name
114
114
  *
115
115
  * Expects:
@@ -123,7 +123,7 @@ declare function ollamaFromRunContext(model: ModelDefinition): OllamaChatModelRu
123
123
  * Resolves OpenRouter runtime config from one resolved run-context model.
124
124
  *
125
125
  * Use when:
126
- * - task execution already has `context.model()` output
126
+ * - task execution already has a model resolved through chat-model helpers
127
127
  * - eval code wants typed OpenRouter provider options with a concise helper name
128
128
  *
129
129
  * Expects:
@@ -540,6 +540,63 @@ interface ChatModelsPluginOptions {
540
540
  */
541
541
  models: readonly ChatModelDefinition[];
542
542
  }
543
+ /**
544
+ * Matrix scope that can carry a chat model selector.
545
+ */
546
+ type MatrixModelScope = 'eval' | 'run';
547
+ /**
548
+ * Options for resolving a chat model from a matrix axis.
549
+ */
550
+ interface ModelFromMatrixOptions {
551
+ /**
552
+ * Matrix axis whose selected value is a model id, model name, or alias.
553
+ */
554
+ axis: string;
555
+ }
556
+ type MatrixModelContext = Pick<TaskRunContext, 'models' | 'task'>;
557
+ /**
558
+ * Resolves a configured chat model from one scoped matrix axis.
559
+ *
560
+ * Use when:
561
+ * - a matrix axis selects the agent, judge, or another chat model role
562
+ * - eval code should keep model lookup semantics inside the chat-models plugin
563
+ *
564
+ * Expects:
565
+ * - `scope` to identify `context.task.matrix.run` or `context.task.matrix.eval`
566
+ * - `options.axis` to exist and contain a model id, model name, or alias
567
+ *
568
+ * Returns:
569
+ * - the configured model matching the selected matrix value
570
+ */
571
+ declare function modelFromMatrix(context: MatrixModelContext, scope: MatrixModelScope, options: ModelFromMatrixOptions): ModelDefinition;
572
+ /**
573
+ * Resolves a configured chat model from one run-matrix axis.
574
+ *
575
+ * Use when:
576
+ * - run matrix selects the model used by the system under evaluation
577
+ * - callers want the scoped helper instead of passing `scope: 'run'`
578
+ *
579
+ * Expects:
580
+ * - `options.axis` to exist in `context.task.matrix.run`
581
+ *
582
+ * Returns:
583
+ * - the configured model matching the selected run-matrix value
584
+ */
585
+ declare function modelFromRun(context: MatrixModelContext, options: ModelFromMatrixOptions): ModelDefinition;
586
+ /**
587
+ * Resolves a configured chat model from one eval-matrix axis.
588
+ *
589
+ * Use when:
590
+ * - eval matrix selects a judge, rubric, or evaluator model
591
+ * - callers want the scoped helper instead of passing `scope: 'eval'`
592
+ *
593
+ * Expects:
594
+ * - `options.axis` to exist in `context.task.matrix.eval`
595
+ *
596
+ * Returns:
597
+ * - the configured model matching the selected eval-matrix value
598
+ */
599
+ declare function modelFromEval(context: MatrixModelContext, options: ModelFromMatrixOptions): ModelDefinition;
543
600
  /**
544
601
  * Creates a run-matrix `model` axis from configured chat model names.
545
602
  *
@@ -571,5 +628,5 @@ declare function ChatProviders(options: ChatProvidersPluginOptions): Plugin;
571
628
  */
572
629
  declare function ChatModels(options: ChatModelsPluginOptions): Plugin;
573
630
  //#endregion
574
- export { ChatModelDefinition, ChatModelExecutorInput, ChatModelExecutorLike, ChatModelFromBaseOptions, ChatModelFromOptions, ChatModelHeaders, ChatModelInferenceExecutor, ChatModelResolverContext, ChatModelResolverValue, ChatModelRuntimeConfig, ChatModelTelemetryProvider, ChatModelToolCall, ChatModels, ChatModelsPluginOptions, ChatProviderDefinition, ChatProviderFromOptions, ChatProviders, ChatProvidersPluginOptions, EmitChatModelErrorTelemetryOptions, EmitChatModelRequestTelemetryOptions, EmitChatModelResponseTelemetryOptions, GenericChatModelInferenceExecutor, OllamaChatModelInferenceExecutor, OllamaChatModelRuntimeConfig, OpenAIChatModelInferenceExecutor, OpenAIChatModelRuntimeConfig, OpenRouterChatModelInferenceExecutor, OpenRouterChatModelRuntimeConfig, OptionalProviderEnvMap, Plugin, PluginConfig, RequiredProviderEnvMap, chatModelFrom, chatModelMatrix, chatProviderFrom, emitChatModelErrorTelemetry, emitChatModelRequestTelemetry, emitChatModelResponseTelemetry, extractChatModelToolCalls, extractMeteringDimensions, ollamaFromRunContext, openaiFromRunContext, openrouterFromRunContext, toChatModelRuntimeConfig };
631
+ export { ChatModelDefinition, ChatModelExecutorInput, ChatModelExecutorLike, ChatModelFromBaseOptions, ChatModelFromOptions, ChatModelHeaders, ChatModelInferenceExecutor, ChatModelResolverContext, ChatModelResolverValue, ChatModelRuntimeConfig, ChatModelTelemetryProvider, ChatModelToolCall, ChatModels, ChatModelsPluginOptions, ChatProviderDefinition, ChatProviderFromOptions, ChatProviders, ChatProvidersPluginOptions, EmitChatModelErrorTelemetryOptions, EmitChatModelRequestTelemetryOptions, EmitChatModelResponseTelemetryOptions, GenericChatModelInferenceExecutor, MatrixModelScope, ModelFromMatrixOptions, OllamaChatModelInferenceExecutor, OllamaChatModelRuntimeConfig, OpenAIChatModelInferenceExecutor, OpenAIChatModelRuntimeConfig, OpenRouterChatModelInferenceExecutor, OpenRouterChatModelRuntimeConfig, OptionalProviderEnvMap, Plugin, PluginConfig, RequiredProviderEnvMap, chatModelFrom, chatModelMatrix, chatProviderFrom, emitChatModelErrorTelemetry, emitChatModelRequestTelemetry, emitChatModelResponseTelemetry, extractChatModelToolCalls, extractMeteringDimensions, modelFromEval, modelFromMatrix, modelFromRun, ollamaFromRunContext, openaiFromRunContext, openrouterFromRunContext, toChatModelRuntimeConfig };
575
632
  //# sourceMappingURL=index.d.mts.map
@@ -1,4 +1,5 @@
1
- import { n as requiredEnvFrom, t as envFrom } from "../../env--94B0UtW.mjs";
1
+ import { n as requiredEnvFrom, t as envFrom } from "../../env-BFSjny07.mjs";
2
+ import { t as resolveModelByName } from "../../models-pBSRUZhY.mjs";
2
3
  import process from "node:process";
3
4
  import { errorMessageFrom } from "@moeru/std";
4
5
  //#region src/plugins/chat-models/runtime-config.ts
@@ -41,7 +42,7 @@ function parseHeadersParameter(parameters, modelId) {
41
42
  * Normalizes one configured chat model into runtime executor config.
42
43
  *
43
44
  * Use when:
44
- * - eval code needs typed provider constructor options from `context.model()`
45
+ * - eval code needs typed provider constructor options from a resolved model
45
46
  * - model parameters should be validated once with clear error messages
46
47
  *
47
48
  * Expects:
@@ -79,7 +80,7 @@ function toChatModelRuntimeConfig(model) {
79
80
  * Resolves OpenAI runtime config from one resolved run-context model.
80
81
  *
81
82
  * Use when:
82
- * - task execution already has `context.model()` output
83
+ * - task execution already has a model resolved through chat-model helpers
83
84
  * - eval code wants typed OpenAI provider options with a concise helper name
84
85
  *
85
86
  * Expects:
@@ -97,7 +98,7 @@ function openaiFromRunContext(model) {
97
98
  * Resolves Ollama runtime config from one resolved run-context model.
98
99
  *
99
100
  * Use when:
100
- * - task execution already has `context.model()` output
101
+ * - task execution already has a model resolved through chat-model helpers
101
102
  * - eval code wants typed Ollama provider options with a concise helper name
102
103
  *
103
104
  * Expects:
@@ -115,7 +116,7 @@ function ollamaFromRunContext(model) {
115
116
  * Resolves OpenRouter runtime config from one resolved run-context model.
116
117
  *
117
118
  * Use when:
118
- * - task execution already has `context.model()` output
119
+ * - task execution already has a model resolved through chat-model helpers
119
120
  * - eval code wants typed OpenRouter provider options with a concise helper name
120
121
  *
121
122
  * Expects:
@@ -479,6 +480,59 @@ function chatProviderFrom(options) {
479
480
  };
480
481
  }
481
482
  /**
483
+ * Resolves a configured chat model from one scoped matrix axis.
484
+ *
485
+ * Use when:
486
+ * - a matrix axis selects the agent, judge, or another chat model role
487
+ * - eval code should keep model lookup semantics inside the chat-models plugin
488
+ *
489
+ * Expects:
490
+ * - `scope` to identify `context.task.matrix.run` or `context.task.matrix.eval`
491
+ * - `options.axis` to exist and contain a model id, model name, or alias
492
+ *
493
+ * Returns:
494
+ * - the configured model matching the selected matrix value
495
+ */
496
+ function modelFromMatrix(context, scope, options) {
497
+ const selectedModelName = context.task.matrix[scope][options.axis];
498
+ if (selectedModelName == null) throw new Error(`Missing ${scope} matrix axis "${options.axis}".`);
499
+ const model = resolveModelByName(context.models, selectedModelName);
500
+ if (model == null) throw new Error(`Unknown configured chat model "${selectedModelName}" from ${scope} matrix axis "${options.axis}".`);
501
+ return model;
502
+ }
503
+ /**
504
+ * Resolves a configured chat model from one run-matrix axis.
505
+ *
506
+ * Use when:
507
+ * - run matrix selects the model used by the system under evaluation
508
+ * - callers want the scoped helper instead of passing `scope: 'run'`
509
+ *
510
+ * Expects:
511
+ * - `options.axis` to exist in `context.task.matrix.run`
512
+ *
513
+ * Returns:
514
+ * - the configured model matching the selected run-matrix value
515
+ */
516
+ function modelFromRun(context, options) {
517
+ return modelFromMatrix(context, "run", options);
518
+ }
519
+ /**
520
+ * Resolves a configured chat model from one eval-matrix axis.
521
+ *
522
+ * Use when:
523
+ * - eval matrix selects a judge, rubric, or evaluator model
524
+ * - callers want the scoped helper instead of passing `scope: 'eval'`
525
+ *
526
+ * Expects:
527
+ * - `options.axis` to exist in `context.task.matrix.eval`
528
+ *
529
+ * Returns:
530
+ * - the configured model matching the selected eval-matrix value
531
+ */
532
+ function modelFromEval(context, options) {
533
+ return modelFromMatrix(context, "eval", options);
534
+ }
535
+ /**
482
536
  * Creates a run-matrix `model` axis from configured chat model names.
483
537
  *
484
538
  * Use when:
@@ -534,6 +588,6 @@ function ChatModels(options) {
534
588
  };
535
589
  }
536
590
  //#endregion
537
- export { ChatModels, ChatProviders, chatModelFrom, chatModelMatrix, chatProviderFrom, emitChatModelErrorTelemetry, emitChatModelRequestTelemetry, emitChatModelResponseTelemetry, extractChatModelToolCalls, extractMeteringDimensions, ollamaFromRunContext, openaiFromRunContext, openrouterFromRunContext, toChatModelRuntimeConfig };
591
+ export { ChatModels, ChatProviders, chatModelFrom, chatModelMatrix, chatProviderFrom, emitChatModelErrorTelemetry, emitChatModelRequestTelemetry, emitChatModelResponseTelemetry, extractChatModelToolCalls, extractMeteringDimensions, modelFromEval, modelFromMatrix, modelFromRun, ollamaFromRunContext, openaiFromRunContext, openrouterFromRunContext, toChatModelRuntimeConfig };
538
592
 
539
593
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugins/chat-models/runtime-config.ts","../../../src/plugins/chat-models/telemetry.ts","../../../src/plugins/chat-models/index.ts"],"sourcesContent":["import type { ModelDefinition } from '../../config/models'\nimport type { ChatModelHeaders } from './index'\n\nimport { envFrom, requiredEnvFrom } from '../../core/inference-executors/env'\n\n/**\n * Runtime config consumed by OpenAI-compatible provider constructors.\n */\nexport interface OpenAIChatModelRuntimeConfig {\n /**\n * Resolved inference executor kind.\n */\n inferenceExecutor: 'openai'\n /**\n * Concrete model name.\n */\n model: string\n /**\n * Required API key.\n */\n apiKey: string\n /**\n * Optional base URL override.\n */\n baseURL?: string\n /**\n * Optional request headers.\n */\n headers?: ChatModelHeaders\n}\n\n/**\n * Runtime config consumed by Ollama provider constructors.\n */\nexport interface OllamaChatModelRuntimeConfig {\n /**\n * Resolved inference executor kind.\n */\n inferenceExecutor: 'ollama'\n /**\n * Concrete model name.\n */\n model: string\n /**\n * Optional base URL override.\n */\n baseURL?: string\n /**\n * Optional request headers.\n */\n headers?: ChatModelHeaders\n}\n\n/**\n * Runtime config consumed by OpenRouter provider constructors.\n */\nexport interface OpenRouterChatModelRuntimeConfig {\n /**\n * Resolved inference executor kind.\n */\n inferenceExecutor: 'openrouter'\n /**\n * Concrete model name.\n */\n model: string\n /**\n * Required API key.\n */\n apiKey: string\n /**\n * Optional base URL override.\n */\n baseURL?: string\n /**\n * Optional request headers.\n */\n headers?: ChatModelHeaders\n}\n\n/**\n * Union of normalized runtime configs for supported chat-model executors.\n */\nexport type ChatModelRuntimeConfig\n = OpenAIChatModelRuntimeConfig\n | OllamaChatModelRuntimeConfig\n | OpenRouterChatModelRuntimeConfig\n\nfunction getParameters(model: ModelDefinition): Record<string, unknown> {\n return model.parameters ?? {}\n}\n\nfunction parseOptionalStringParameter(\n parameters: Record<string, unknown>,\n key: string,\n modelId: string,\n): string | undefined {\n const value = parameters[key]\n const normalized = value == null ? undefined : String(value)\n\n return envFrom(normalized, {\n name: `${modelId}.parameters.${key}`,\n type: 'string',\n })\n}\n\nfunction parseRequiredStringParameter(\n parameters: Record<string, unknown>,\n key: string,\n modelId: string,\n): string {\n const value = parameters[key]\n const normalized = value == null ? undefined : String(value)\n\n return requiredEnvFrom(normalized, {\n name: `${modelId}.parameters.${key}`,\n type: 'string',\n })\n}\n\nfunction parseHeadersParameter(\n parameters: Record<string, unknown>,\n modelId: string,\n): ChatModelHeaders | undefined {\n const headers = parameters.headers\n if (headers == null) {\n return undefined\n }\n\n if (typeof headers !== 'object' || Array.isArray(headers)) {\n throw new TypeError(`Invalid ${modelId}.parameters.headers: expected an object.`)\n }\n\n const normalized: Record<string, string | string[]> = {}\n for (const [key, value] of Object.entries(headers as Record<string, unknown>)) {\n if (typeof value === 'string') {\n normalized[key] = value\n continue\n }\n\n if (Array.isArray(value) && value.every(item => typeof item === 'string')) {\n normalized[key] = value\n continue\n }\n\n throw new Error(`Invalid ${modelId}.parameters.headers.${key}: expected string or string[].`)\n }\n\n return normalized\n}\n\n/**\n * Normalizes one configured chat model into runtime executor config.\n *\n * Use when:\n * - eval code needs typed provider constructor options from `context.model()`\n * - model parameters should be validated once with clear error messages\n *\n * Expects:\n * - `model.inferenceExecutorId` to be one of the supported executor ids\n * - required OpenAI fields (apiKey) to exist in `model.parameters`\n *\n * Returns:\n * - validated runtime config union for OpenAI or Ollama\n */\nexport function toChatModelRuntimeConfig(model: ModelDefinition): ChatModelRuntimeConfig {\n const parameters = getParameters(model)\n\n if (model.inferenceExecutorId === 'openai') {\n return {\n apiKey: parseRequiredStringParameter(parameters, 'apiKey', model.id),\n baseURL: parseOptionalStringParameter(parameters, 'baseURL', model.id),\n headers: parseHeadersParameter(parameters, model.id),\n inferenceExecutor: 'openai',\n model: model.model,\n }\n }\n\n if (model.inferenceExecutorId === 'ollama') {\n return {\n baseURL: parseOptionalStringParameter(parameters, 'baseURL', model.id),\n headers: parseHeadersParameter(parameters, model.id),\n inferenceExecutor: 'ollama',\n model: model.model,\n }\n }\n\n if (model.inferenceExecutorId === 'openrouter') {\n return {\n apiKey: parseRequiredStringParameter(parameters, 'apiKey', model.id),\n baseURL: parseOptionalStringParameter(parameters, 'baseURL', model.id),\n headers: parseHeadersParameter(parameters, model.id),\n inferenceExecutor: 'openrouter',\n model: model.model,\n }\n }\n\n throw new Error(`Unsupported chat inference executor \"${model.inferenceExecutorId}\" for model \"${model.id}\".`)\n}\n\n/**\n * Resolves OpenAI runtime config from one resolved run-context model.\n *\n * Use when:\n * - task execution already has `context.model()` output\n * - eval code wants typed OpenAI provider options with a concise helper name\n *\n * Expects:\n * - `model` to resolve to an OpenAI-backed chat model\n *\n * Returns:\n * - validated OpenAI runtime config\n */\nexport function openaiFromRunContext(model: ModelDefinition): OpenAIChatModelRuntimeConfig {\n const runtimeConfig = toChatModelRuntimeConfig(model)\n if (runtimeConfig.inferenceExecutor !== 'openai') {\n throw new Error(`Expected openai model, got \"${runtimeConfig.inferenceExecutor}\" for \"${model.id}\".`)\n }\n\n return runtimeConfig\n}\n\n/**\n * Resolves Ollama runtime config from one resolved run-context model.\n *\n * Use when:\n * - task execution already has `context.model()` output\n * - eval code wants typed Ollama provider options with a concise helper name\n *\n * Expects:\n * - `model` to resolve to an Ollama-backed chat model\n *\n * Returns:\n * - validated Ollama runtime config\n */\nexport function ollamaFromRunContext(model: ModelDefinition): OllamaChatModelRuntimeConfig {\n const runtimeConfig = toChatModelRuntimeConfig(model)\n if (runtimeConfig.inferenceExecutor !== 'ollama') {\n throw new Error(`Expected ollama model, got \"${runtimeConfig.inferenceExecutor}\" for \"${model.id}\".`)\n }\n\n return runtimeConfig\n}\n\n/**\n * Resolves OpenRouter runtime config from one resolved run-context model.\n *\n * Use when:\n * - task execution already has `context.model()` output\n * - eval code wants typed OpenRouter provider options with a concise helper name\n *\n * Expects:\n * - `model` to resolve to an OpenRouter-backed chat model\n *\n * Returns:\n * - validated OpenRouter runtime config\n */\nexport function openrouterFromRunContext(model: ModelDefinition): OpenRouterChatModelRuntimeConfig {\n const runtimeConfig = toChatModelRuntimeConfig(model)\n if (runtimeConfig.inferenceExecutor !== 'openrouter') {\n throw new Error(`Expected openrouter model, got \"${runtimeConfig.inferenceExecutor}\" for \"${model.id}\".`)\n }\n\n return runtimeConfig\n}\n","import type { TaskRunContext } from '../../config/types'\n\nimport { errorMessageFrom } from '@moeru/std'\n\n/**\n * Represents one normalized chat-model tool call.\n *\n * Use when:\n * - report events need tool-call level payloads that remain provider-neutral\n *\n * Expects:\n * - `name` to be stable enough for aggregation and assertion checks\n * - `args` to be JSON-serializable\n */\nexport interface ChatModelToolCall {\n /**\n * Optional provider-assigned tool-call identifier.\n */\n id?: string\n /**\n * Tool name.\n */\n name: string\n /**\n * Parsed tool arguments object/value.\n */\n args: unknown\n}\n\n/**\n * Provider identity attached to chat-model telemetry events.\n */\nexport interface ChatModelTelemetryProvider {\n /**\n * Provider id, for example `openai`.\n */\n id: string\n /**\n * Optional concrete model id/name.\n */\n model?: string\n}\n\n/**\n * Input options for response telemetry emission.\n */\nexport interface EmitChatModelResponseTelemetryOptions {\n /**\n * Optional case id for case-scoped telemetry events.\n */\n caseId?: string\n /**\n * Optional response latency in milliseconds.\n */\n latencyMs?: number\n /**\n * Optional provider identity payload.\n */\n provider?: ChatModelTelemetryProvider\n /**\n * Raw chat-model response object from the inference library/provider.\n */\n response: unknown\n}\n\n/**\n * Input options for request telemetry emission.\n */\nexport interface EmitChatModelRequestTelemetryOptions {\n /**\n * Optional case id for case-scoped telemetry events.\n */\n caseId?: string\n /**\n * Optional request payload metadata.\n */\n data?: unknown\n /**\n * Optional provider identity payload.\n */\n provider?: ChatModelTelemetryProvider\n}\n\n/**\n * Input options for error telemetry emission.\n */\nexport interface EmitChatModelErrorTelemetryOptions {\n /**\n * Optional case id for case-scoped telemetry events.\n */\n caseId?: string\n /**\n * Error payload emitted by the inference client/runtime.\n */\n error: unknown\n /**\n * Optional provider identity payload.\n */\n provider?: ChatModelTelemetryProvider\n}\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n if (value == null || typeof value !== 'object') {\n return undefined\n }\n\n return value as Record<string, unknown>\n}\n\nfunction parseMaybeJson(value: unknown): unknown {\n if (typeof value !== 'string') {\n return value\n }\n\n try {\n return JSON.parse(value)\n }\n catch {\n return value\n }\n}\n\n/**\n * Extracts normalized tool calls from one chat-model response shape.\n *\n * Use when:\n * - downstream scoring, reporting, or analysis should inspect tool call usage\n * - provider payload differences should stay hidden behind one stable shape\n *\n * Returns:\n * - normalized list of `{ id?, name, args }` tool calls\n */\nexport function extractChatModelToolCalls(response: unknown): ChatModelToolCall[] {\n const responseRecord = asRecord(response)\n if (responseRecord == null) {\n return []\n }\n\n const rawToolCalls = responseRecord.toolCalls ?? responseRecord.tool_calls\n if (!Array.isArray(rawToolCalls)) {\n return []\n }\n\n const toolCalls: ChatModelToolCall[] = []\n\n for (const rawToolCall of rawToolCalls) {\n const toolCallRecord = asRecord(rawToolCall)\n if (toolCallRecord == null) {\n continue\n }\n\n const functionPayload = asRecord(toolCallRecord.function)\n const name = typeof toolCallRecord.name === 'string'\n ? toolCallRecord.name\n : typeof functionPayload?.name === 'string'\n ? functionPayload.name\n : undefined\n\n if (name == null || name.length === 0) {\n continue\n }\n\n const rawArgs = toolCallRecord.args\n ?? toolCallRecord.arguments\n ?? functionPayload?.args\n ?? functionPayload?.arguments\n\n toolCalls.push({\n args: parseMaybeJson(rawArgs),\n id: typeof toolCallRecord.id === 'string' ? toolCallRecord.id : undefined,\n name,\n })\n }\n\n return toolCalls\n}\n\n/**\n * Extracts numeric metering dimensions from one chat-model response usage block.\n *\n * Use when:\n * - report events should capture usage dimensions in a modality-neutral map\n *\n * Returns:\n * - numeric dimensions keyed by provider usage field names\n */\nexport function extractMeteringDimensions(response: unknown): Record<string, number> {\n const responseRecord = asRecord(response)\n const usage = asRecord(responseRecord?.usage)\n if (usage == null) {\n return {}\n }\n\n const dimensions: Record<string, number> = {}\n\n for (const [key, value] of Object.entries(usage)) {\n if (typeof value !== 'number' || Number.isNaN(value)) {\n continue\n }\n\n dimensions[key] = value\n }\n\n return dimensions\n}\n\n/**\n * Emits chat-model response telemetry as reportable task events.\n *\n * Use when:\n * - task code receives one chat-model response and wants standardized report events\n * - `ToolCall*` and metering metrics should be persisted in `events.jsonl`\n *\n * Expects:\n * - `context.reporterHooks?.onEvent` to be available in CLI execution paths\n *\n * Returns:\n * - no return value; this is a best-effort reporting helper\n */\nexport function emitChatModelResponseTelemetry(\n context: TaskRunContext,\n options: EmitChatModelResponseTelemetryOptions,\n): void {\n const toolCalls = extractChatModelToolCalls(options.response)\n const meteringDimensions = extractMeteringDimensions(options.response)\n\n if (toolCalls.length > 0) {\n meteringDimensions.tool_call_count = toolCalls.length\n }\n\n const data = {\n metering: {\n dimensions: meteringDimensions,\n latency_ms: options.latencyMs,\n },\n metrics: {\n 'vieval.chat.tool_call_count': toolCalls.length,\n },\n modality: 'chat',\n provider: options.provider,\n toolCalls,\n }\n\n context.reporterHooks?.onEvent?.({\n caseId: options.caseId,\n data,\n event: 'InferenceResponse',\n })\n\n for (const toolCall of toolCalls) {\n context.reporterHooks?.onEvent?.({\n caseId: options.caseId,\n data: {\n modality: 'chat',\n provider: options.provider,\n toolCall,\n },\n event: 'ToolCallStarted',\n })\n context.reporterHooks?.onEvent?.({\n caseId: options.caseId,\n data: {\n modality: 'chat',\n provider: options.provider,\n toolCall,\n },\n event: 'ToolCallEnded',\n })\n }\n}\n\n/**\n * Emits chat-model request telemetry as a reportable task event.\n *\n * Use when:\n * - task code submits one model request and wants request-side traceability\n *\n * Expects:\n * - `context.reporterHooks?.onEvent` to be available in CLI execution paths\n */\nexport function emitChatModelRequestTelemetry(\n context: TaskRunContext,\n options: EmitChatModelRequestTelemetryOptions,\n): void {\n context.reporterHooks?.onEvent?.({\n caseId: options.caseId,\n data: {\n data: options.data,\n modality: 'chat',\n provider: options.provider,\n },\n event: 'InferenceRequest',\n })\n}\n\n/**\n * Emits chat-model failure telemetry as a reportable task event.\n *\n * Use when:\n * - one inference call fails and report artifacts should include normalized error context\n *\n * Expects:\n * - `context.reporterHooks?.onEvent` to be available in CLI execution paths\n */\nexport function emitChatModelErrorTelemetry(\n context: TaskRunContext,\n options: EmitChatModelErrorTelemetryOptions,\n): void {\n context.reporterHooks?.onEvent?.({\n caseId: options.caseId,\n data: {\n error: errorMessageFrom(options.error) ?? 'Unknown inference error.',\n modality: 'chat',\n provider: options.provider,\n },\n event: 'InferenceError',\n })\n}\n","import type { MatrixDefinition, TaskExecutionPolicy } from '../../config'\nimport type { ModelDefinition } from '../../config/models'\nimport type { ConfigHookPlugin } from '../../config/plugin'\nimport type { EnvFromOptions, RequiredEnvFromOptions } from '../../core/inference-executors/env'\n\nimport process from 'node:process'\n\nimport { envFrom, requiredEnvFrom } from '../../core/inference-executors/env'\n\n/**\n * Minimal inference-executor shape expected by chat model runtime callers.\n */\nexport interface ChatModelExecutorLike {\n chat: (model: string) => Record<string, unknown>\n}\n\n/**\n * Inference-executor input accepted by `chatModelFrom`.\n */\nexport type ChatModelExecutorInput = string | ChatModelExecutorLike\n\n/**\n * Chat-model header payload accepted by executor parameters.\n */\nexport type ChatModelHeaders = Record<string, string | string[]>\n\n/**\n * Runtime env context passed to model callback resolvers.\n */\nexport interface ChatModelResolverContext {\n env: Record<string, string>\n}\n\n/**\n * Value-or-callback resolver used by model runtime fields.\n */\nexport type ChatModelResolverValue<TValue> = TValue | ((config: ChatModelResolverContext) => Promise<TValue> | TValue)\n\n/**\n * OpenAI-specific inference executor config shape.\n */\nexport interface OpenAIChatModelInferenceExecutor {\n inferenceExecutor: 'openai'\n apiKey?: ChatModelResolverValue<string>\n baseURL?: ChatModelResolverValue<string>\n headers?: ChatModelResolverValue<ChatModelHeaders>\n}\n\n/**\n * Ollama-specific inference executor config shape.\n */\nexport interface OllamaChatModelInferenceExecutor {\n inferenceExecutor: 'ollama'\n baseURL?: ChatModelResolverValue<string>\n headers?: ChatModelResolverValue<ChatModelHeaders>\n}\n\n/**\n * OpenRouter-specific inference executor config shape.\n */\nexport interface OpenRouterChatModelInferenceExecutor {\n inferenceExecutor: 'openrouter'\n apiKey?: ChatModelResolverValue<string>\n baseURL?: ChatModelResolverValue<string>\n headers?: ChatModelResolverValue<ChatModelHeaders>\n}\n\n/**\n * Generic inference executor config shape.\n */\nexport interface GenericChatModelInferenceExecutor {\n inferenceExecutor?: ChatModelExecutorInput\n}\n\n/**\n * Union of supported inference executor config shapes for `chatModelFrom`.\n */\nexport type ChatModelInferenceExecutor\n = OpenAIChatModelInferenceExecutor\n | OllamaChatModelInferenceExecutor\n | OpenRouterChatModelInferenceExecutor\n | GenericChatModelInferenceExecutor\n\n/**\n * Common builder input fields for `chatModelFrom`.\n */\nexport interface ChatModelFromBaseOptions {\n /**\n * Provider id registered through `ChatProviders`.\n *\n * Use when:\n * - model runtime transport and credentials should be delegated to a named provider preset\n *\n * Expects:\n * - one `ChatProviders` plugin entry to expose the same id\n */\n provider?: string\n /**\n * Inference-executor id or inference-executor instance.\n */\n inferenceExecutor?: ChatModelExecutorInput\n /**\n * Optional explicit inference-executor id for inference-executor instances.\n *\n * @default 'custom'\n */\n inferenceExecutorId?: string\n /**\n * Concrete model name.\n */\n model: string\n /**\n * Optional stable model id.\n *\n * @default `${inferenceExecutorId}:${model}`\n */\n id?: string\n /**\n * Alias names used by `resolveModelByName`.\n */\n aliases?: string[]\n /**\n * Optional execution policy hints attached to this model.\n */\n executionPolicy?: TaskExecutionPolicy\n /**\n * Additional retries allowed within the current attempt.\n *\n * @default 0\n */\n autoRetry?: number\n /**\n * Delay in milliseconds before a retry starts.\n *\n * @default retryIndex => 500 * 2 ** (retryIndex - 1)\n */\n autoRetryDelay?: TaskExecutionPolicy['autoRetryDelay']\n /**\n * Additional full task attempts allowed after the current attempt settles.\n *\n * @default 0\n */\n autoAttempt?: number\n /**\n * Timeout in milliseconds for model-backed work.\n */\n timeout?: number\n /**\n * Optional model-level call parameters.\n */\n parameters?: Record<string, unknown>\n}\n\n/**\n * Builder input for `chatModelFrom`.\n */\nexport type ChatModelFromOptions = ChatModelInferenceExecutor & ChatModelFromBaseOptions\n\n/**\n * Chat-model specific specialization of the canonical `ModelDefinition`.\n */\nexport type ChatModelDefinition = Omit<ModelDefinition, 'inferenceExecutor'> & {\n inferenceExecutor: ChatModelExecutorInput\n provider?: string\n runtimeResolvers?: {\n apiKey?: ChatModelResolverValue<string>\n baseURL?: ChatModelResolverValue<string>\n headers?: ChatModelResolverValue<ChatModelHeaders>\n }\n}\n\nfunction normalizeExecutionPolicy(\n policy: TaskExecutionPolicy | undefined,\n): TaskExecutionPolicy | undefined {\n if (policy == null) {\n return undefined\n }\n\n const normalized = {\n autoAttempt: policy.autoAttempt,\n autoRetry: policy.autoRetry,\n autoRetryDelay: policy.autoRetryDelay,\n timeout: policy.timeout,\n }\n\n return Object.values(normalized).some(value => value != null)\n ? normalized\n : undefined\n}\n\nfunction hasJudgeAlias(model: Pick<ChatModelFromBaseOptions, 'aliases' | 'id' | 'model'>): boolean {\n return [\n ...(model.aliases ?? []),\n ...(model.id == null ? [] : [model.id]),\n model.model,\n ].some(value => value.toLowerCase().includes('judge'))\n}\n\nfunction resolveModelExecutionPolicy(options: ChatModelFromOptions): TaskExecutionPolicy | undefined {\n const explicitPolicy = normalizeExecutionPolicy({\n autoAttempt: options.autoAttempt ?? options.executionPolicy?.autoAttempt,\n autoRetry: options.autoRetry ?? options.executionPolicy?.autoRetry,\n autoRetryDelay: options.autoRetryDelay ?? options.executionPolicy?.autoRetryDelay,\n timeout: options.timeout ?? options.executionPolicy?.timeout,\n })\n\n if (explicitPolicy != null && Object.keys(explicitPolicy).length > 0) {\n return explicitPolicy\n }\n\n if (hasJudgeAlias(options)) {\n return {\n autoRetry: 3,\n }\n }\n\n return undefined\n}\n\n/**\n * Env-key map for optional provider parameters.\n *\n * Use when:\n * - provider parameter values should be read from env keys\n * - missing keys should resolve to `undefined`\n */\nexport type OptionalProviderEnvMap = Record<string, string>\n\n/**\n * Env-key map for required provider parameters.\n *\n * Use when:\n * - provider parameter values must exist before model execution\n * - missing keys should throw with key-aware error messages\n */\nexport type RequiredProviderEnvMap = Record<string, string>\n\n/**\n * One provider definition consumed by chat model presets.\n */\nexport interface ChatProviderDefinition {\n /**\n * Stable provider id referenced by `chatModelFrom({ provider })`.\n */\n id: string\n /**\n * Inference-executor id or instance used by this provider preset.\n */\n inferenceExecutor: ChatModelExecutorInput\n /**\n * Optional explicit inference-executor id for inference-executor instances.\n *\n * @default 'custom'\n */\n inferenceExecutorId?: string\n /**\n * Optional literal provider-level parameters.\n */\n parameters?: Record<string, unknown>\n /**\n * Optional provider parameters resolved via `envFrom`.\n *\n * Expects:\n * - map key is the provider parameter name\n * - map value is the env key name\n */\n optionalEnv?: OptionalProviderEnvMap\n /**\n * Required provider parameters resolved via `requiredEnvFrom`.\n *\n * Expects:\n * - map key is the provider parameter name\n * - map value is the env key name\n */\n requiredEnv?: RequiredProviderEnvMap\n}\n\n/**\n * Builder input for `chatProviderFrom`.\n */\nexport interface ChatProviderFromOptions extends ChatProviderDefinition {\n}\n\n/**\n * Options for the built-in `ChatProviders` plugin.\n */\nexport interface ChatProvidersPluginOptions {\n /**\n * Provider definitions to append to config.\n */\n providers: readonly ChatProviderDefinition[]\n /**\n * Optional explicit env source used for env-backed provider parameters.\n *\n * @default process.env\n */\n env?: NodeJS.ProcessEnv\n}\n\n/**\n * Partial config shape needed by the chat models plugin.\n */\nexport interface PluginConfig {\n env?: NodeJS.ProcessEnv\n chatProviders?: ChatProviderDefinition[]\n models?: ModelDefinition[]\n}\n\n/**\n * Plugin type bound to the minimal config shape used by model plugins.\n */\nexport type Plugin = ConfigHookPlugin<PluginConfig>\n\nfunction normalizeInferenceExecutorId(\n inferenceExecutor: ChatModelExecutorInput,\n inferenceExecutorId: string | undefined,\n): string {\n if (typeof inferenceExecutor === 'string') {\n return inferenceExecutor\n }\n\n return inferenceExecutorId ?? 'custom'\n}\n\nfunction createDefaultModelId(inferenceExecutorId: string, model: string): string {\n return `${inferenceExecutorId}:${model}`\n}\n\nfunction normalizeEnvRecord(env: NodeJS.ProcessEnv): Record<string, string> {\n const normalized: Record<string, string> = {}\n for (const [key, value] of Object.entries(env)) {\n if (typeof value === 'string') {\n normalized[key] = value\n }\n }\n\n return normalized\n}\n\nasync function resolveChatModelResolverValue<TValue>(\n value: ChatModelResolverValue<TValue>,\n context: ChatModelResolverContext,\n): Promise<TValue> {\n if (typeof value === 'function') {\n const resolver = value as (config: ChatModelResolverContext) => Promise<TValue> | TValue\n return await resolver(context)\n }\n\n return value\n}\n\nfunction resolveRequiredStringValue(value: string | undefined, name: string): string {\n return requiredEnvFrom(value, {\n name,\n type: 'string',\n })\n}\n\nfunction resolveOptionalStringValue(value: string | undefined, name: string): string | undefined {\n return envFrom(value, {\n name,\n type: 'string',\n })\n}\n\nfunction resolveOptionalEnvValue(\n env: NodeJS.ProcessEnv,\n envKey: string,\n): string | undefined {\n const options: EnvFromOptions = {\n name: envKey,\n type: 'string',\n }\n\n return envFrom(env[envKey], options)\n}\n\nfunction resolveRequiredEnvValue(\n env: NodeJS.ProcessEnv,\n envKey: string,\n): string {\n const options: RequiredEnvFromOptions = {\n name: envKey,\n type: 'string',\n }\n\n return requiredEnvFrom(env[envKey], options)\n}\n\nfunction resolveProviderParameters(\n provider: ChatProviderDefinition,\n env: NodeJS.ProcessEnv,\n): Record<string, unknown> | undefined {\n const parameters: Record<string, unknown> = {\n ...provider.parameters,\n }\n\n for (const [parameterName, envKey] of Object.entries(provider.optionalEnv ?? {})) {\n const resolved = resolveOptionalEnvValue(env, envKey)\n if (resolved != null) {\n parameters[parameterName] = resolved\n }\n }\n\n for (const [parameterName, envKey] of Object.entries(provider.requiredEnv ?? {})) {\n parameters[parameterName] = resolveRequiredEnvValue(env, envKey)\n }\n\n return Object.keys(parameters).length > 0 ? parameters : undefined\n}\n\nfunction normalizeChatProviderDefinition(\n provider: ChatProviderDefinition,\n env: NodeJS.ProcessEnv,\n): ChatProviderDefinition {\n return {\n id: provider.id,\n inferenceExecutor: provider.inferenceExecutor,\n inferenceExecutorId: normalizeInferenceExecutorId(provider.inferenceExecutor, provider.inferenceExecutorId),\n optionalEnv: provider.optionalEnv,\n parameters: resolveProviderParameters(provider, env),\n requiredEnv: provider.requiredEnv,\n }\n}\n\nfunction createProviderMap(config: PluginConfig): Map<string, ChatProviderDefinition> {\n const providerMap = new Map<string, ChatProviderDefinition>()\n for (const provider of config.chatProviders ?? []) {\n providerMap.set(provider.id, provider)\n }\n\n return providerMap\n}\n\nfunction resolveModelProvider(\n model: ChatModelDefinition,\n providerMap: ReadonlyMap<string, ChatProviderDefinition>,\n): ChatModelDefinition {\n if (model.provider == null) {\n return model\n }\n\n const provider = providerMap.get(model.provider)\n if (provider == null) {\n throw new Error(`Unknown chat provider \"${model.provider}\" referenced by model \"${model.id}\".`)\n }\n\n return {\n ...model,\n inferenceExecutor: provider.inferenceExecutor,\n inferenceExecutorId: provider.inferenceExecutorId ?? normalizeInferenceExecutorId(provider.inferenceExecutor, provider.inferenceExecutorId),\n parameters: {\n ...provider.parameters,\n ...model.parameters,\n },\n }\n}\n\nasync function resolveModelRuntimeResolvers(\n model: ChatModelDefinition,\n context: ChatModelResolverContext,\n): Promise<Record<string, unknown> | undefined> {\n if (model.runtimeResolvers == null) {\n return undefined\n }\n\n const resolvedParameters: Record<string, unknown> = {}\n\n if (model.runtimeResolvers.apiKey != null) {\n const resolvedApiKey = await resolveChatModelResolverValue(model.runtimeResolvers.apiKey, context)\n resolvedParameters.apiKey = resolveRequiredStringValue(resolvedApiKey, `${model.id}.apiKey`)\n }\n\n if (model.runtimeResolvers.baseURL != null) {\n const resolvedBaseURL = await resolveChatModelResolverValue(model.runtimeResolvers.baseURL, context)\n const normalizedBaseURL = resolveOptionalStringValue(resolvedBaseURL, `${model.id}.baseURL`)\n if (normalizedBaseURL != null) {\n resolvedParameters.baseURL = normalizedBaseURL\n }\n }\n\n if (model.runtimeResolvers.headers != null) {\n const resolvedHeaders = await resolveChatModelResolverValue(model.runtimeResolvers.headers, context)\n resolvedParameters.headers = resolvedHeaders\n }\n\n return Object.keys(resolvedParameters).length > 0 ? resolvedParameters : undefined\n}\n\nasync function resolveChatModelDefinition(\n model: ChatModelDefinition,\n config: PluginConfig,\n): Promise<ChatModelDefinition> {\n const providerResolvedModel = resolveModelProvider(model, createProviderMap(config))\n const resolvedRuntimeParameters = await resolveModelRuntimeResolvers(providerResolvedModel, {\n env: normalizeEnvRecord(config.env ?? process.env),\n })\n\n if (resolvedRuntimeParameters == null) {\n return providerResolvedModel\n }\n\n return {\n ...providerResolvedModel,\n parameters: {\n ...providerResolvedModel.parameters,\n ...resolvedRuntimeParameters,\n },\n }\n}\n\nfunction isOpenAIChatModelInferenceExecutor(\n options: ChatModelFromOptions,\n): options is ChatModelFromBaseOptions & OpenAIChatModelInferenceExecutor {\n return options.inferenceExecutor === 'openai'\n}\n\nfunction isOllamaChatModelInferenceExecutor(\n options: ChatModelFromOptions,\n): options is ChatModelFromBaseOptions & OllamaChatModelInferenceExecutor {\n return options.inferenceExecutor === 'ollama'\n}\n\nfunction isOpenRouterChatModelInferenceExecutor(\n options: ChatModelFromOptions,\n): options is ChatModelFromBaseOptions & OpenRouterChatModelInferenceExecutor {\n return options.inferenceExecutor === 'openrouter'\n}\n\n/**\n * Builds one normalized chat model definition.\n *\n * Use when:\n * - registering chat models through config plugins\n * - a single model needs aliases for matrix selection or judge lookup\n */\nexport function chatModelFrom(options: ChatModelFromOptions): ChatModelDefinition {\n const fallbackInferenceExecutor = options.inferenceExecutor ?? options.provider ?? 'custom'\n const inferenceExecutorId = normalizeInferenceExecutorId(fallbackInferenceExecutor, options.inferenceExecutorId)\n const runtimeResolvers = isOpenAIChatModelInferenceExecutor(options)\n ? {\n apiKey: options.apiKey,\n baseURL: options.baseURL,\n headers: options.headers,\n }\n : isOllamaChatModelInferenceExecutor(options)\n ? {\n baseURL: options.baseURL,\n headers: options.headers,\n }\n : isOpenRouterChatModelInferenceExecutor(options)\n ? {\n apiKey: options.apiKey,\n baseURL: options.baseURL,\n headers: options.headers,\n }\n : undefined\n\n return {\n aliases: options.aliases ?? [],\n executionPolicy: resolveModelExecutionPolicy(options),\n id: options.id ?? createDefaultModelId(inferenceExecutorId, options.model),\n inferenceExecutor: fallbackInferenceExecutor,\n inferenceExecutorId,\n model: options.model,\n parameters: options.parameters,\n provider: options.provider,\n runtimeResolvers,\n }\n}\n\n/**\n * Builds one normalized chat provider definition.\n *\n * Use when:\n * - one provider preset should be reused across multiple chat models\n * - provider configuration should support required/optional env-backed parameters\n */\nexport function chatProviderFrom(options: ChatProviderFromOptions): ChatProviderDefinition {\n return {\n id: options.id,\n inferenceExecutor: options.inferenceExecutor,\n inferenceExecutorId: normalizeInferenceExecutorId(options.inferenceExecutor, options.inferenceExecutorId),\n optionalEnv: options.optionalEnv,\n parameters: options.parameters,\n requiredEnv: options.requiredEnv,\n }\n}\n\n/**\n * Options for the built-in `ChatModels` plugin.\n */\nexport interface ChatModelsPluginOptions {\n /**\n * Chat model definitions to append to config.\n */\n models: readonly ChatModelDefinition[]\n}\n\n/**\n * Creates a run-matrix `model` axis from configured chat model names.\n *\n * Use when:\n * - run matrix should iterate over explicit chat model ids/aliases\n * - project configs want a concise model-axis helper\n *\n * Expects:\n * - each provided name to match a configured model id or alias at runtime\n *\n * Returns:\n * - matrix axis object compatible with `runMatrix.extend/override`\n */\nexport function chatModelMatrix(...names: string[]): MatrixDefinition {\n return {\n model: Array.from(new Set(names)),\n }\n}\n\n/**\n * Built-in chat providers plugin that contributes provider presets to config.\n *\n * Use when:\n * - provider runtime config should be centralized and reusable\n * - provider parameters should be resolved from env via `envFrom`/`requiredEnvFrom`\n */\nexport function ChatProviders(options: ChatProvidersPluginOptions): Plugin {\n return {\n configVieval(config) {\n const env = config.env ?? options.env ?? process.env\n const normalizedProviders = options.providers.map(provider => normalizeChatProviderDefinition(provider, env))\n\n return {\n ...config,\n chatProviders: [\n ...(config.chatProviders ?? []),\n ...normalizedProviders,\n ],\n }\n },\n name: 'vieval:chat-providers',\n }\n}\n\n/**\n * Built-in chat models plugin that contributes model definitions to vieval config.\n *\n * Use when:\n * - chat-model registration should stay in config-level plugin setup\n * - tasks and assertions resolve models by name or alias at runtime\n */\nexport function ChatModels(options: ChatModelsPluginOptions): Plugin {\n return {\n async configVieval(config) {\n const resolvedModels = await Promise.all(options.models.map(async model => resolveChatModelDefinition(model, config)))\n\n return {\n ...config,\n models: [\n ...(config.models ?? []),\n ...resolvedModels,\n ],\n }\n },\n name: 'vieval:chat-models',\n }\n}\n\nexport * from './runtime-config'\nex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
+ {"version":3,"file":"index.mjs","names":[],"sources":["../../../src/plugins/chat-models/runtime-config.ts","../../../src/plugins/chat-models/telemetry.ts","../../../src/plugins/chat-models/index.ts"],"sourcesContent":["import type { ModelDefinition } from '../../config/models'\nimport type { ChatModelHeaders } from './index'\n\nimport { envFrom, requiredEnvFrom } from '../../core/inference-executors/env'\n\n/**\n * Runtime config consumed by OpenAI-compatible provider constructors.\n */\nexport interface OpenAIChatModelRuntimeConfig {\n /**\n * Resolved inference executor kind.\n */\n inferenceExecutor: 'openai'\n /**\n * Concrete model name.\n */\n model: string\n /**\n * Required API key.\n */\n apiKey: string\n /**\n * Optional base URL override.\n */\n baseURL?: string\n /**\n * Optional request headers.\n */\n headers?: ChatModelHeaders\n}\n\n/**\n * Runtime config consumed by Ollama provider constructors.\n */\nexport interface OllamaChatModelRuntimeConfig {\n /**\n * Resolved inference executor kind.\n */\n inferenceExecutor: 'ollama'\n /**\n * Concrete model name.\n */\n model: string\n /**\n * Optional base URL override.\n */\n baseURL?: string\n /**\n * Optional request headers.\n */\n headers?: ChatModelHeaders\n}\n\n/**\n * Runtime config consumed by OpenRouter provider constructors.\n */\nexport interface OpenRouterChatModelRuntimeConfig {\n /**\n * Resolved inference executor kind.\n */\n inferenceExecutor: 'openrouter'\n /**\n * Concrete model name.\n */\n model: string\n /**\n * Required API key.\n */\n apiKey: string\n /**\n * Optional base URL override.\n */\n baseURL?: string\n /**\n * Optional request headers.\n */\n headers?: ChatModelHeaders\n}\n\n/**\n * Union of normalized runtime configs for supported chat-model executors.\n */\nexport type ChatModelRuntimeConfig\n = OpenAIChatModelRuntimeConfig\n | OllamaChatModelRuntimeConfig\n | OpenRouterChatModelRuntimeConfig\n\nfunction getParameters(model: ModelDefinition): Record<string, unknown> {\n return model.parameters ?? {}\n}\n\nfunction parseOptionalStringParameter(\n parameters: Record<string, unknown>,\n key: string,\n modelId: string,\n): string | undefined {\n const value = parameters[key]\n const normalized = value == null ? undefined : String(value)\n\n return envFrom(normalized, {\n name: `${modelId}.parameters.${key}`,\n type: 'string',\n })\n}\n\nfunction parseRequiredStringParameter(\n parameters: Record<string, unknown>,\n key: string,\n modelId: string,\n): string {\n const value = parameters[key]\n const normalized = value == null ? undefined : String(value)\n\n return requiredEnvFrom(normalized, {\n name: `${modelId}.parameters.${key}`,\n type: 'string',\n })\n}\n\nfunction parseHeadersParameter(\n parameters: Record<string, unknown>,\n modelId: string,\n): ChatModelHeaders | undefined {\n const headers = parameters.headers\n if (headers == null) {\n return undefined\n }\n\n if (typeof headers !== 'object' || Array.isArray(headers)) {\n throw new TypeError(`Invalid ${modelId}.parameters.headers: expected an object.`)\n }\n\n const normalized: Record<string, string | string[]> = {}\n for (const [key, value] of Object.entries(headers as Record<string, unknown>)) {\n if (typeof value === 'string') {\n normalized[key] = value\n continue\n }\n\n if (Array.isArray(value) && value.every(item => typeof item === 'string')) {\n normalized[key] = value\n continue\n }\n\n throw new Error(`Invalid ${modelId}.parameters.headers.${key}: expected string or string[].`)\n }\n\n return normalized\n}\n\n/**\n * Normalizes one configured chat model into runtime executor config.\n *\n * Use when:\n * - eval code needs typed provider constructor options from a resolved model\n * - model parameters should be validated once with clear error messages\n *\n * Expects:\n * - `model.inferenceExecutorId` to be one of the supported executor ids\n * - required OpenAI fields (apiKey) to exist in `model.parameters`\n *\n * Returns:\n * - validated runtime config union for OpenAI or Ollama\n */\nexport function toChatModelRuntimeConfig(model: ModelDefinition): ChatModelRuntimeConfig {\n const parameters = getParameters(model)\n\n if (model.inferenceExecutorId === 'openai') {\n return {\n apiKey: parseRequiredStringParameter(parameters, 'apiKey', model.id),\n baseURL: parseOptionalStringParameter(parameters, 'baseURL', model.id),\n headers: parseHeadersParameter(parameters, model.id),\n inferenceExecutor: 'openai',\n model: model.model,\n }\n }\n\n if (model.inferenceExecutorId === 'ollama') {\n return {\n baseURL: parseOptionalStringParameter(parameters, 'baseURL', model.id),\n headers: parseHeadersParameter(parameters, model.id),\n inferenceExecutor: 'ollama',\n model: model.model,\n }\n }\n\n if (model.inferenceExecutorId === 'openrouter') {\n return {\n apiKey: parseRequiredStringParameter(parameters, 'apiKey', model.id),\n baseURL: parseOptionalStringParameter(parameters, 'baseURL', model.id),\n headers: parseHeadersParameter(parameters, model.id),\n inferenceExecutor: 'openrouter',\n model: model.model,\n }\n }\n\n throw new Error(`Unsupported chat inference executor \"${model.inferenceExecutorId}\" for model \"${model.id}\".`)\n}\n\n/**\n * Resolves OpenAI runtime config from one resolved run-context model.\n *\n * Use when:\n * - task execution already has a model resolved through chat-model helpers\n * - eval code wants typed OpenAI provider options with a concise helper name\n *\n * Expects:\n * - `model` to resolve to an OpenAI-backed chat model\n *\n * Returns:\n * - validated OpenAI runtime config\n */\nexport function openaiFromRunContext(model: ModelDefinition): OpenAIChatModelRuntimeConfig {\n const runtimeConfig = toChatModelRuntimeConfig(model)\n if (runtimeConfig.inferenceExecutor !== 'openai') {\n throw new Error(`Expected openai model, got \"${runtimeConfig.inferenceExecutor}\" for \"${model.id}\".`)\n }\n\n return runtimeConfig\n}\n\n/**\n * Resolves Ollama runtime config from one resolved run-context model.\n *\n * Use when:\n * - task execution already has a model resolved through chat-model helpers\n * - eval code wants typed Ollama provider options with a concise helper name\n *\n * Expects:\n * - `model` to resolve to an Ollama-backed chat model\n *\n * Returns:\n * - validated Ollama runtime config\n */\nexport function ollamaFromRunContext(model: ModelDefinition): OllamaChatModelRuntimeConfig {\n const runtimeConfig = toChatModelRuntimeConfig(model)\n if (runtimeConfig.inferenceExecutor !== 'ollama') {\n throw new Error(`Expected ollama model, got \"${runtimeConfig.inferenceExecutor}\" for \"${model.id}\".`)\n }\n\n return runtimeConfig\n}\n\n/**\n * Resolves OpenRouter runtime config from one resolved run-context model.\n *\n * Use when:\n * - task execution already has a model resolved through chat-model helpers\n * - eval code wants typed OpenRouter provider options with a concise helper name\n *\n * Expects:\n * - `model` to resolve to an OpenRouter-backed chat model\n *\n * Returns:\n * - validated OpenRouter runtime config\n */\nexport function openrouterFromRunContext(model: ModelDefinition): OpenRouterChatModelRuntimeConfig {\n const runtimeConfig = toChatModelRuntimeConfig(model)\n if (runtimeConfig.inferenceExecutor !== 'openrouter') {\n throw new Error(`Expected openrouter model, got \"${runtimeConfig.inferenceExecutor}\" for \"${model.id}\".`)\n }\n\n return runtimeConfig\n}\n","import type { TaskRunContext } from '../../config/types'\n\nimport { errorMessageFrom } from '@moeru/std'\n\n/**\n * Represents one normalized chat-model tool call.\n *\n * Use when:\n * - report events need tool-call level payloads that remain provider-neutral\n *\n * Expects:\n * - `name` to be stable enough for aggregation and assertion checks\n * - `args` to be JSON-serializable\n */\nexport interface ChatModelToolCall {\n /**\n * Optional provider-assigned tool-call identifier.\n */\n id?: string\n /**\n * Tool name.\n */\n name: string\n /**\n * Parsed tool arguments object/value.\n */\n args: unknown\n}\n\n/**\n * Provider identity attached to chat-model telemetry events.\n */\nexport interface ChatModelTelemetryProvider {\n /**\n * Provider id, for example `openai`.\n */\n id: string\n /**\n * Optional concrete model id/name.\n */\n model?: string\n}\n\n/**\n * Input options for response telemetry emission.\n */\nexport interface EmitChatModelResponseTelemetryOptions {\n /**\n * Optional case id for case-scoped telemetry events.\n */\n caseId?: string\n /**\n * Optional response latency in milliseconds.\n */\n latencyMs?: number\n /**\n * Optional provider identity payload.\n */\n provider?: ChatModelTelemetryProvider\n /**\n * Raw chat-model response object from the inference library/provider.\n */\n response: unknown\n}\n\n/**\n * Input options for request telemetry emission.\n */\nexport interface EmitChatModelRequestTelemetryOptions {\n /**\n * Optional case id for case-scoped telemetry events.\n */\n caseId?: string\n /**\n * Optional request payload metadata.\n */\n data?: unknown\n /**\n * Optional provider identity payload.\n */\n provider?: ChatModelTelemetryProvider\n}\n\n/**\n * Input options for error telemetry emission.\n */\nexport interface EmitChatModelErrorTelemetryOptions {\n /**\n * Optional case id for case-scoped telemetry events.\n */\n caseId?: string\n /**\n * Error payload emitted by the inference client/runtime.\n */\n error: unknown\n /**\n * Optional provider identity payload.\n */\n provider?: ChatModelTelemetryProvider\n}\n\nfunction asRecord(value: unknown): Record<string, unknown> | undefined {\n if (value == null || typeof value !== 'object') {\n return undefined\n }\n\n return value as Record<string, unknown>\n}\n\nfunction parseMaybeJson(value: unknown): unknown {\n if (typeof value !== 'string') {\n return value\n }\n\n try {\n return JSON.parse(value)\n }\n catch {\n return value\n }\n}\n\n/**\n * Extracts normalized tool calls from one chat-model response shape.\n *\n * Use when:\n * - downstream scoring, reporting, or analysis should inspect tool call usage\n * - provider payload differences should stay hidden behind one stable shape\n *\n * Returns:\n * - normalized list of `{ id?, name, args }` tool calls\n */\nexport function extractChatModelToolCalls(response: unknown): ChatModelToolCall[] {\n const responseRecord = asRecord(response)\n if (responseRecord == null) {\n return []\n }\n\n const rawToolCalls = responseRecord.toolCalls ?? responseRecord.tool_calls\n if (!Array.isArray(rawToolCalls)) {\n return []\n }\n\n const toolCalls: ChatModelToolCall[] = []\n\n for (const rawToolCall of rawToolCalls) {\n const toolCallRecord = asRecord(rawToolCall)\n if (toolCallRecord == null) {\n continue\n }\n\n const functionPayload = asRecord(toolCallRecord.function)\n const name = typeof toolCallRecord.name === 'string'\n ? toolCallRecord.name\n : typeof functionPayload?.name === 'string'\n ? functionPayload.name\n : undefined\n\n if (name == null || name.length === 0) {\n continue\n }\n\n const rawArgs = toolCallRecord.args\n ?? toolCallRecord.arguments\n ?? functionPayload?.args\n ?? functionPayload?.arguments\n\n toolCalls.push({\n args: parseMaybeJson(rawArgs),\n id: typeof toolCallRecord.id === 'string' ? toolCallRecord.id : undefined,\n name,\n })\n }\n\n return toolCalls\n}\n\n/**\n * Extracts numeric metering dimensions from one chat-model response usage block.\n *\n * Use when:\n * - report events should capture usage dimensions in a modality-neutral map\n *\n * Returns:\n * - numeric dimensions keyed by provider usage field names\n */\nexport function extractMeteringDimensions(response: unknown): Record<string, number> {\n const responseRecord = asRecord(response)\n const usage = asRecord(responseRecord?.usage)\n if (usage == null) {\n return {}\n }\n\n const dimensions: Record<string, number> = {}\n\n for (const [key, value] of Object.entries(usage)) {\n if (typeof value !== 'number' || Number.isNaN(value)) {\n continue\n }\n\n dimensions[key] = value\n }\n\n return dimensions\n}\n\n/**\n * Emits chat-model response telemetry as reportable task events.\n *\n * Use when:\n * - task code receives one chat-model response and wants standardized report events\n * - `ToolCall*` and metering metrics should be persisted in `events.jsonl`\n *\n * Expects:\n * - `context.reporterHooks?.onEvent` to be available in CLI execution paths\n *\n * Returns:\n * - no return value; this is a best-effort reporting helper\n */\nexport function emitChatModelResponseTelemetry(\n context: TaskRunContext,\n options: EmitChatModelResponseTelemetryOptions,\n): void {\n const toolCalls = extractChatModelToolCalls(options.response)\n const meteringDimensions = extractMeteringDimensions(options.response)\n\n if (toolCalls.length > 0) {\n meteringDimensions.tool_call_count = toolCalls.length\n }\n\n const data = {\n metering: {\n dimensions: meteringDimensions,\n latency_ms: options.latencyMs,\n },\n metrics: {\n 'vieval.chat.tool_call_count': toolCalls.length,\n },\n modality: 'chat',\n provider: options.provider,\n toolCalls,\n }\n\n context.reporterHooks?.onEvent?.({\n caseId: options.caseId,\n data,\n event: 'InferenceResponse',\n })\n\n for (const toolCall of toolCalls) {\n context.reporterHooks?.onEvent?.({\n caseId: options.caseId,\n data: {\n modality: 'chat',\n provider: options.provider,\n toolCall,\n },\n event: 'ToolCallStarted',\n })\n context.reporterHooks?.onEvent?.({\n caseId: options.caseId,\n data: {\n modality: 'chat',\n provider: options.provider,\n toolCall,\n },\n event: 'ToolCallEnded',\n })\n }\n}\n\n/**\n * Emits chat-model request telemetry as a reportable task event.\n *\n * Use when:\n * - task code submits one model request and wants request-side traceability\n *\n * Expects:\n * - `context.reporterHooks?.onEvent` to be available in CLI execution paths\n */\nexport function emitChatModelRequestTelemetry(\n context: TaskRunContext,\n options: EmitChatModelRequestTelemetryOptions,\n): void {\n context.reporterHooks?.onEvent?.({\n caseId: options.caseId,\n data: {\n data: options.data,\n modality: 'chat',\n provider: options.provider,\n },\n event: 'InferenceRequest',\n })\n}\n\n/**\n * Emits chat-model failure telemetry as a reportable task event.\n *\n * Use when:\n * - one inference call fails and report artifacts should include normalized error context\n *\n * Expects:\n * - `context.reporterHooks?.onEvent` to be available in CLI execution paths\n */\nexport function emitChatModelErrorTelemetry(\n context: TaskRunContext,\n options: EmitChatModelErrorTelemetryOptions,\n): void {\n context.reporterHooks?.onEvent?.({\n caseId: options.caseId,\n data: {\n error: errorMessageFrom(options.error) ?? 'Unknown inference error.',\n modality: 'chat',\n provider: options.provider,\n },\n event: 'InferenceError',\n })\n}\n","import type { MatrixDefinition, TaskExecutionPolicy } from '../../config'\nimport type { ModelDefinition } from '../../config/models'\nimport type { ConfigHookPlugin } from '../../config/plugin'\nimport type { TaskRunContext } from '../../config/types'\nimport type { EnvFromOptions, RequiredEnvFromOptions } from '../../core/inference-executors/env'\n\nimport process from 'node:process'\n\nimport { resolveModelByName } from '../../config/models'\nimport { envFrom, requiredEnvFrom } from '../../core/inference-executors/env'\n\n/**\n * Minimal inference-executor shape expected by chat model runtime callers.\n */\nexport interface ChatModelExecutorLike {\n chat: (model: string) => Record<string, unknown>\n}\n\n/**\n * Inference-executor input accepted by `chatModelFrom`.\n */\nexport type ChatModelExecutorInput = string | ChatModelExecutorLike\n\n/**\n * Chat-model header payload accepted by executor parameters.\n */\nexport type ChatModelHeaders = Record<string, string | string[]>\n\n/**\n * Runtime env context passed to model callback resolvers.\n */\nexport interface ChatModelResolverContext {\n env: Record<string, string>\n}\n\n/**\n * Value-or-callback resolver used by model runtime fields.\n */\nexport type ChatModelResolverValue<TValue> = TValue | ((config: ChatModelResolverContext) => Promise<TValue> | TValue)\n\n/**\n * OpenAI-specific inference executor config shape.\n */\nexport interface OpenAIChatModelInferenceExecutor {\n inferenceExecutor: 'openai'\n apiKey?: ChatModelResolverValue<string>\n baseURL?: ChatModelResolverValue<string>\n headers?: ChatModelResolverValue<ChatModelHeaders>\n}\n\n/**\n * Ollama-specific inference executor config shape.\n */\nexport interface OllamaChatModelInferenceExecutor {\n inferenceExecutor: 'ollama'\n baseURL?: ChatModelResolverValue<string>\n headers?: ChatModelResolverValue<ChatModelHeaders>\n}\n\n/**\n * OpenRouter-specific inference executor config shape.\n */\nexport interface OpenRouterChatModelInferenceExecutor {\n inferenceExecutor: 'openrouter'\n apiKey?: ChatModelResolverValue<string>\n baseURL?: ChatModelResolverValue<string>\n headers?: ChatModelResolverValue<ChatModelHeaders>\n}\n\n/**\n * Generic inference executor config shape.\n */\nexport interface GenericChatModelInferenceExecutor {\n inferenceExecutor?: ChatModelExecutorInput\n}\n\n/**\n * Union of supported inference executor config shapes for `chatModelFrom`.\n */\nexport type ChatModelInferenceExecutor\n = OpenAIChatModelInferenceExecutor\n | OllamaChatModelInferenceExecutor\n | OpenRouterChatModelInferenceExecutor\n | GenericChatModelInferenceExecutor\n\n/**\n * Common builder input fields for `chatModelFrom`.\n */\nexport interface ChatModelFromBaseOptions {\n /**\n * Provider id registered through `ChatProviders`.\n *\n * Use when:\n * - model runtime transport and credentials should be delegated to a named provider preset\n *\n * Expects:\n * - one `ChatProviders` plugin entry to expose the same id\n */\n provider?: string\n /**\n * Inference-executor id or inference-executor instance.\n */\n inferenceExecutor?: ChatModelExecutorInput\n /**\n * Optional explicit inference-executor id for inference-executor instances.\n *\n * @default 'custom'\n */\n inferenceExecutorId?: string\n /**\n * Concrete model name.\n */\n model: string\n /**\n * Optional stable model id.\n *\n * @default `${inferenceExecutorId}:${model}`\n */\n id?: string\n /**\n * Alias names used by `resolveModelByName`.\n */\n aliases?: string[]\n /**\n * Optional execution policy hints attached to this model.\n */\n executionPolicy?: TaskExecutionPolicy\n /**\n * Additional retries allowed within the current attempt.\n *\n * @default 0\n */\n autoRetry?: number\n /**\n * Delay in milliseconds before a retry starts.\n *\n * @default retryIndex => 500 * 2 ** (retryIndex - 1)\n */\n autoRetryDelay?: TaskExecutionPolicy['autoRetryDelay']\n /**\n * Additional full task attempts allowed after the current attempt settles.\n *\n * @default 0\n */\n autoAttempt?: number\n /**\n * Timeout in milliseconds for model-backed work.\n */\n timeout?: number\n /**\n * Optional model-level call parameters.\n */\n parameters?: Record<string, unknown>\n}\n\n/**\n * Builder input for `chatModelFrom`.\n */\nexport type ChatModelFromOptions = ChatModelInferenceExecutor & ChatModelFromBaseOptions\n\n/**\n * Chat-model specific specialization of the canonical `ModelDefinition`.\n */\nexport type ChatModelDefinition = Omit<ModelDefinition, 'inferenceExecutor'> & {\n inferenceExecutor: ChatModelExecutorInput\n provider?: string\n runtimeResolvers?: {\n apiKey?: ChatModelResolverValue<string>\n baseURL?: ChatModelResolverValue<string>\n headers?: ChatModelResolverValue<ChatModelHeaders>\n }\n}\n\nfunction normalizeExecutionPolicy(\n policy: TaskExecutionPolicy | undefined,\n): TaskExecutionPolicy | undefined {\n if (policy == null) {\n return undefined\n }\n\n const normalized = {\n autoAttempt: policy.autoAttempt,\n autoRetry: policy.autoRetry,\n autoRetryDelay: policy.autoRetryDelay,\n timeout: policy.timeout,\n }\n\n return Object.values(normalized).some(value => value != null)\n ? normalized\n : undefined\n}\n\nfunction hasJudgeAlias(model: Pick<ChatModelFromBaseOptions, 'aliases' | 'id' | 'model'>): boolean {\n return [\n ...(model.aliases ?? []),\n ...(model.id == null ? [] : [model.id]),\n model.model,\n ].some(value => value.toLowerCase().includes('judge'))\n}\n\nfunction resolveModelExecutionPolicy(options: ChatModelFromOptions): TaskExecutionPolicy | undefined {\n const explicitPolicy = normalizeExecutionPolicy({\n autoAttempt: options.autoAttempt ?? options.executionPolicy?.autoAttempt,\n autoRetry: options.autoRetry ?? options.executionPolicy?.autoRetry,\n autoRetryDelay: options.autoRetryDelay ?? options.executionPolicy?.autoRetryDelay,\n timeout: options.timeout ?? options.executionPolicy?.timeout,\n })\n\n if (explicitPolicy != null && Object.keys(explicitPolicy).length > 0) {\n return explicitPolicy\n }\n\n if (hasJudgeAlias(options)) {\n return {\n autoRetry: 3,\n }\n }\n\n return undefined\n}\n\n/**\n * Env-key map for optional provider parameters.\n *\n * Use when:\n * - provider parameter values should be read from env keys\n * - missing keys should resolve to `undefined`\n */\nexport type OptionalProviderEnvMap = Record<string, string>\n\n/**\n * Env-key map for required provider parameters.\n *\n * Use when:\n * - provider parameter values must exist before model execution\n * - missing keys should throw with key-aware error messages\n */\nexport type RequiredProviderEnvMap = Record<string, string>\n\n/**\n * One provider definition consumed by chat model presets.\n */\nexport interface ChatProviderDefinition {\n /**\n * Stable provider id referenced by `chatModelFrom({ provider })`.\n */\n id: string\n /**\n * Inference-executor id or instance used by this provider preset.\n */\n inferenceExecutor: ChatModelExecutorInput\n /**\n * Optional explicit inference-executor id for inference-executor instances.\n *\n * @default 'custom'\n */\n inferenceExecutorId?: string\n /**\n * Optional literal provider-level parameters.\n */\n parameters?: Record<string, unknown>\n /**\n * Optional provider parameters resolved via `envFrom`.\n *\n * Expects:\n * - map key is the provider parameter name\n * - map value is the env key name\n */\n optionalEnv?: OptionalProviderEnvMap\n /**\n * Required provider parameters resolved via `requiredEnvFrom`.\n *\n * Expects:\n * - map key is the provider parameter name\n * - map value is the env key name\n */\n requiredEnv?: RequiredProviderEnvMap\n}\n\n/**\n * Builder input for `chatProviderFrom`.\n */\nexport interface ChatProviderFromOptions extends ChatProviderDefinition {\n}\n\n/**\n * Options for the built-in `ChatProviders` plugin.\n */\nexport interface ChatProvidersPluginOptions {\n /**\n * Provider definitions to append to config.\n */\n providers: readonly ChatProviderDefinition[]\n /**\n * Optional explicit env source used for env-backed provider parameters.\n *\n * @default process.env\n */\n env?: NodeJS.ProcessEnv\n}\n\n/**\n * Partial config shape needed by the chat models plugin.\n */\nexport interface PluginConfig {\n env?: NodeJS.ProcessEnv\n chatProviders?: ChatProviderDefinition[]\n models?: ModelDefinition[]\n}\n\n/**\n * Plugin type bound to the minimal config shape used by model plugins.\n */\nexport type Plugin = ConfigHookPlugin<PluginConfig>\n\nfunction normalizeInferenceExecutorId(\n inferenceExecutor: ChatModelExecutorInput,\n inferenceExecutorId: string | undefined,\n): string {\n if (typeof inferenceExecutor === 'string') {\n return inferenceExecutor\n }\n\n return inferenceExecutorId ?? 'custom'\n}\n\nfunction createDefaultModelId(inferenceExecutorId: string, model: string): string {\n return `${inferenceExecutorId}:${model}`\n}\n\nfunction normalizeEnvRecord(env: NodeJS.ProcessEnv): Record<string, string> {\n const normalized: Record<string, string> = {}\n for (const [key, value] of Object.entries(env)) {\n if (typeof value === 'string') {\n normalized[key] = value\n }\n }\n\n return normalized\n}\n\nasync function resolveChatModelResolverValue<TValue>(\n value: ChatModelResolverValue<TValue>,\n context: ChatModelResolverContext,\n): Promise<TValue> {\n if (typeof value === 'function') {\n const resolver = value as (config: ChatModelResolverContext) => Promise<TValue> | TValue\n return await resolver(context)\n }\n\n return value\n}\n\nfunction resolveRequiredStringValue(value: string | undefined, name: string): string {\n return requiredEnvFrom(value, {\n name,\n type: 'string',\n })\n}\n\nfunction resolveOptionalStringValue(value: string | undefined, name: string): string | undefined {\n return envFrom(value, {\n name,\n type: 'string',\n })\n}\n\nfunction resolveOptionalEnvValue(\n env: NodeJS.ProcessEnv,\n envKey: string,\n): string | undefined {\n const options: EnvFromOptions = {\n name: envKey,\n type: 'string',\n }\n\n return envFrom(env[envKey], options)\n}\n\nfunction resolveRequiredEnvValue(\n env: NodeJS.ProcessEnv,\n envKey: string,\n): string {\n const options: RequiredEnvFromOptions = {\n name: envKey,\n type: 'string',\n }\n\n return requiredEnvFrom(env[envKey], options)\n}\n\nfunction resolveProviderParameters(\n provider: ChatProviderDefinition,\n env: NodeJS.ProcessEnv,\n): Record<string, unknown> | undefined {\n const parameters: Record<string, unknown> = {\n ...provider.parameters,\n }\n\n for (const [parameterName, envKey] of Object.entries(provider.optionalEnv ?? {})) {\n const resolved = resolveOptionalEnvValue(env, envKey)\n if (resolved != null) {\n parameters[parameterName] = resolved\n }\n }\n\n for (const [parameterName, envKey] of Object.entries(provider.requiredEnv ?? {})) {\n parameters[parameterName] = resolveRequiredEnvValue(env, envKey)\n }\n\n return Object.keys(parameters).length > 0 ? parameters : undefined\n}\n\nfunction normalizeChatProviderDefinition(\n provider: ChatProviderDefinition,\n env: NodeJS.ProcessEnv,\n): ChatProviderDefinition {\n return {\n id: provider.id,\n inferenceExecutor: provider.inferenceExecutor,\n inferenceExecutorId: normalizeInferenceExecutorId(provider.inferenceExecutor, provider.inferenceExecutorId),\n optionalEnv: provider.optionalEnv,\n parameters: resolveProviderParameters(provider, env),\n requiredEnv: provider.requiredEnv,\n }\n}\n\nfunction createProviderMap(config: PluginConfig): Map<string, ChatProviderDefinition> {\n const providerMap = new Map<string, ChatProviderDefinition>()\n for (const provider of config.chatProviders ?? []) {\n providerMap.set(provider.id, provider)\n }\n\n return providerMap\n}\n\nfunction resolveModelProvider(\n model: ChatModelDefinition,\n providerMap: ReadonlyMap<string, ChatProviderDefinition>,\n): ChatModelDefinition {\n if (model.provider == null) {\n return model\n }\n\n const provider = providerMap.get(model.provider)\n if (provider == null) {\n throw new Error(`Unknown chat provider \"${model.provider}\" referenced by model \"${model.id}\".`)\n }\n\n return {\n ...model,\n inferenceExecutor: provider.inferenceExecutor,\n inferenceExecutorId: provider.inferenceExecutorId ?? normalizeInferenceExecutorId(provider.inferenceExecutor, provider.inferenceExecutorId),\n parameters: {\n ...provider.parameters,\n ...model.parameters,\n },\n }\n}\n\nasync function resolveModelRuntimeResolvers(\n model: ChatModelDefinition,\n context: ChatModelResolverContext,\n): Promise<Record<string, unknown> | undefined> {\n if (model.runtimeResolvers == null) {\n return undefined\n }\n\n const resolvedParameters: Record<string, unknown> = {}\n\n if (model.runtimeResolvers.apiKey != null) {\n const resolvedApiKey = await resolveChatModelResolverValue(model.runtimeResolvers.apiKey, context)\n resolvedParameters.apiKey = resolveRequiredStringValue(resolvedApiKey, `${model.id}.apiKey`)\n }\n\n if (model.runtimeResolvers.baseURL != null) {\n const resolvedBaseURL = await resolveChatModelResolverValue(model.runtimeResolvers.baseURL, context)\n const normalizedBaseURL = resolveOptionalStringValue(resolvedBaseURL, `${model.id}.baseURL`)\n if (normalizedBaseURL != null) {\n resolvedParameters.baseURL = normalizedBaseURL\n }\n }\n\n if (model.runtimeResolvers.headers != null) {\n const resolvedHeaders = await resolveChatModelResolverValue(model.runtimeResolvers.headers, context)\n resolvedParameters.headers = resolvedHeaders\n }\n\n return Object.keys(resolvedParameters).length > 0 ? resolvedParameters : undefined\n}\n\nasync function resolveChatModelDefinition(\n model: ChatModelDefinition,\n config: PluginConfig,\n): Promise<ChatModelDefinition> {\n const providerResolvedModel = resolveModelProvider(model, createProviderMap(config))\n const resolvedRuntimeParameters = await resolveModelRuntimeResolvers(providerResolvedModel, {\n env: normalizeEnvRecord(config.env ?? process.env),\n })\n\n if (resolvedRuntimeParameters == null) {\n return providerResolvedModel\n }\n\n return {\n ...providerResolvedModel,\n parameters: {\n ...providerResolvedModel.parameters,\n ...resolvedRuntimeParameters,\n },\n }\n}\n\nfunction isOpenAIChatModelInferenceExecutor(\n options: ChatModelFromOptions,\n): options is ChatModelFromBaseOptions & OpenAIChatModelInferenceExecutor {\n return options.inferenceExecutor === 'openai'\n}\n\nfunction isOllamaChatModelInferenceExecutor(\n options: ChatModelFromOptions,\n): options is ChatModelFromBaseOptions & OllamaChatModelInferenceExecutor {\n return options.inferenceExecutor === 'ollama'\n}\n\nfunction isOpenRouterChatModelInferenceExecutor(\n options: ChatModelFromOptions,\n): options is ChatModelFromBaseOptions & OpenRouterChatModelInferenceExecutor {\n return options.inferenceExecutor === 'openrouter'\n}\n\n/**\n * Builds one normalized chat model definition.\n *\n * Use when:\n * - registering chat models through config plugins\n * - a single model needs aliases for matrix selection or judge lookup\n */\nexport function chatModelFrom(options: ChatModelFromOptions): ChatModelDefinition {\n const fallbackInferenceExecutor = options.inferenceExecutor ?? options.provider ?? 'custom'\n const inferenceExecutorId = normalizeInferenceExecutorId(fallbackInferenceExecutor, options.inferenceExecutorId)\n const runtimeResolvers = isOpenAIChatModelInferenceExecutor(options)\n ? {\n apiKey: options.apiKey,\n baseURL: options.baseURL,\n headers: options.headers,\n }\n : isOllamaChatModelInferenceExecutor(options)\n ? {\n baseURL: options.baseURL,\n headers: options.headers,\n }\n : isOpenRouterChatModelInferenceExecutor(options)\n ? {\n apiKey: options.apiKey,\n baseURL: options.baseURL,\n headers: options.headers,\n }\n : undefined\n\n return {\n aliases: options.aliases ?? [],\n executionPolicy: resolveModelExecutionPolicy(options),\n id: options.id ?? createDefaultModelId(inferenceExecutorId, options.model),\n inferenceExecutor: fallbackInferenceExecutor,\n inferenceExecutorId,\n model: options.model,\n parameters: options.parameters,\n provider: options.provider,\n runtimeResolvers,\n }\n}\n\n/**\n * Builds one normalized chat provider definition.\n *\n * Use when:\n * - one provider preset should be reused across multiple chat models\n * - provider configuration should support required/optional env-backed parameters\n */\nexport function chatProviderFrom(options: ChatProviderFromOptions): ChatProviderDefinition {\n return {\n id: options.id,\n inferenceExecutor: options.inferenceExecutor,\n inferenceExecutorId: normalizeInferenceExecutorId(options.inferenceExecutor, options.inferenceExecutorId),\n optionalEnv: options.optionalEnv,\n parameters: options.parameters,\n requiredEnv: options.requiredEnv,\n }\n}\n\n/**\n * Options for the built-in `ChatModels` plugin.\n */\nexport interface ChatModelsPluginOptions {\n /**\n * Chat model definitions to append to config.\n */\n models: readonly ChatModelDefinition[]\n}\n\n/**\n * Matrix scope that can carry a chat model selector.\n */\nexport type MatrixModelScope = 'eval' | 'run'\n\n/**\n * Options for resolving a chat model from a matrix axis.\n */\nexport interface ModelFromMatrixOptions {\n /**\n * Matrix axis whose selected value is a model id, model name, or alias.\n */\n axis: string\n}\n\ntype MatrixModelContext = Pick<TaskRunContext, 'models' | 'task'>\n\n/**\n * Resolves a configured chat model from one scoped matrix axis.\n *\n * Use when:\n * - a matrix axis selects the agent, judge, or another chat model role\n * - eval code should keep model lookup semantics inside the chat-models plugin\n *\n * Expects:\n * - `scope` to identify `context.task.matrix.run` or `context.task.matrix.eval`\n * - `options.axis` to exist and contain a model id, model name, or alias\n *\n * Returns:\n * - the configured model matching the selected matrix value\n */\nexport function modelFromMatrix(\n context: MatrixModelContext,\n scope: MatrixModelScope,\n options: ModelFromMatrixOptions,\n): ModelDefinition {\n const selectedModelName = context.task.matrix[scope][options.axis]\n\n if (selectedModelName == null) {\n throw new Error(`Missing ${scope} matrix axis \"${options.axis}\".`)\n }\n\n const model = resolveModelByName(context.models, selectedModelName)\n if (model == null) {\n throw new Error(`Unknown configured chat model \"${selectedModelName}\" from ${scope} matrix axis \"${options.axis}\".`)\n }\n\n return model\n}\n\n/**\n * Resolves a configured chat model from one run-matrix axis.\n *\n * Use when:\n * - run matrix selects the model used by the system under evaluation\n * - callers want the scoped helper instead of passing `scope: 'run'`\n *\n * Expects:\n * - `options.axis` to exist in `context.task.matrix.run`\n *\n * Returns:\n * - the configured model matching the selected run-matrix value\n */\nexport function modelFromRun(\n context: MatrixModelContext,\n options: ModelFromMatrixOptions,\n): ModelDefinition {\n return modelFromMatrix(context, 'run', options)\n}\n\n/**\n * Resolves a configured chat model from one eval-matrix axis.\n *\n * Use when:\n * - eval matrix selects a judge, rubric, or evaluator model\n * - callers want the scoped helper instead of passing `scope: 'eval'`\n *\n * Expects:\n * - `options.axis` to exist in `context.task.matrix.eval`\n *\n * Returns:\n * - the configured model matching the selected eval-matrix value\n */\nexport function modelFromEval(\n context: MatrixModelContext,\n options: ModelFromMatrixOptions,\n): ModelDefinition {\n return modelFromMatrix(context, 'eval', options)\n}\n\n/**\n * Creates a run-matrix `model` axis from configured chat model names.\n *\n * Use when:\n * - run matrix should iterate over explicit chat model ids/aliases\n * - project configs want a concise model-axis helper\n *\n * Expects:\n * - each provided name to match a configured model id or alias at runtime\n *\n * Returns:\n * - matrix axis object compatible with `runMatrix.extend/override`\n */\nexport function chatModelMatrix(...names: string[]): MatrixDefinition {\n return {\n model: Array.from(new Set(names)),\n }\n}\n\n/**\n * Built-in chat providers plugin that contributes provider presets to config.\n *\n * Use when:\n * - provider runtime config should be centralized and reusable\n * - provider parameters should be resolved from env via `envFrom`/`requiredEnvFrom`\n */\nexport function ChatProviders(options: ChatProvidersPluginOptions): Plugin {\n return {\n configVieval(config) {\n const env = config.env ?? options.env ?? process.env\n const normalizedProviders = options.providers.map(provider => normalizeChatProviderDefinition(provider, env))\n\n return {\n ...config,\n chatProviders: [\n ...(config.chatProviders ?? []),\n ...normalizedProviders,\n ],\n }\n },\n name: 'vieval:chat-providers',\n }\n}\n\n/**\n * Built-in chat models plugin that contributes model definitions to vieval config.\n *\n * Use when:\n * - chat-model registration should stay in config-level plugin setup\n * - tasks and assertions resolve models by name or alias at runtime\n */\nexport function ChatModels(options: ChatModelsPluginOptions): Plugin {\n return {\n async configVieval(config) {\n const resolvedModels = await Promise.all(options.models.map(async model => resolveChatModelDefinition(model, config)))\n\n return {\n ...config,\n models: [\n ...(config.models ?? []),\n ...resolvedModels,\n ],\n }\n },\n name: 'vieval:chat-models',\n }\n}\n\nexport * from './runtime-config'\nexport * from './telemetry'\n"],"mappings":";;;;;AAuFA,SAAS,cAAc,OAAiD;AACtE,QAAO,MAAM,cAAc,EAAE;;AAG/B,SAAS,6BACP,YACA,KACA,SACoB;CACpB,MAAM,QAAQ,WAAW;AAGzB,QAAO,QAFY,SAAS,OAAO,KAAA,IAAY,OAAO,MAAM,EAEjC;EACzB,MAAM,GAAG,QAAQ,cAAc;EAC/B,MAAM;EACP,CAAC;;AAGJ,SAAS,6BACP,YACA,KACA,SACQ;CACR,MAAM,QAAQ,WAAW;AAGzB,QAAO,gBAFY,SAAS,OAAO,KAAA,IAAY,OAAO,MAAM,EAEzB;EACjC,MAAM,GAAG,QAAQ,cAAc;EAC/B,MAAM;EACP,CAAC;;AAGJ,SAAS,sBACP,YACA,SAC8B;CAC9B,MAAM,UAAU,WAAW;AAC3B,KAAI,WAAW,KACb;AAGF,KAAI,OAAO,YAAY,YAAY,MAAM,QAAQ,QAAQ,CACvD,OAAM,IAAI,UAAU,WAAW,QAAQ,0CAA0C;CAGnF,MAAM,aAAgD,EAAE;AACxD,MAAK,MAAM,CAAC,KAAK,UAAU,OAAO,QAAQ,QAAmC,EAAE;AAC7E,MAAI,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