Skip to content

refactor(ai): tighten EvaluationRequest typing and deduplicate request normalization - #57601

Merged
rekram1-node merged 1 commit into
devfrom
evaluation-request-typing
Oct 21, 2026
Merged

rekram1-node merged 1 commit into
devfrom
evaluation-request-typing

Conversation

@rekram1-node

Copy link
Copy Markdown
Contributor

Problem

EvaluationModel<Options> was invariant in Options because _Options used (options: Options) => Options and EvaluationRoute.evaluate used a contravariant function property signature. As a result, EvaluationModel<SpecificOptions> was not assignable to EvaluationModel:

  • EvaluationRequestInput had to constrain Model extends object with a conditional intersection check (Model extends EvaluationModel<EvaluationModelOptions<Model>> ? unknown : never).
  • request() had to cast input.model as unknown as EvaluationModel.
  • run() had to duplicate input instanceof EvaluationRequest ? input : request(input) and cast request as EvaluationRequestFor<EvaluationOptions, EvaluationQuestions>.

Change

Make EvaluationModel<Options> covariant in Options (matching LanguageModel and MediaModel) and allow request() to accept EvaluationRequest | EvaluationRequestInput directly so run() delegates normalization to request(input) without casts.

 export interface EvaluationRoute<Options extends EvaluationOptions = EvaluationOptions> {
   readonly id: string
-  readonly evaluate: (
-    request: EvaluationRequestFor<Options>,
-    execute: Execute,
-  ) => Effect.Effect<EvaluationResponse, AIError>
+  evaluate(request: EvaluationRequestFor<Options>, execute: Execute): Effect.Effect<EvaluationResponse, AIError>
 }

 export class EvaluationModel<Options extends EvaluationOptions = EvaluationOptions> {
-  declare protected readonly _Options: (options: Options) => Options
+  declare protected readonly _Options: Options
 run(input)
   Effect.try
-    input instanceof EvaluationRequest ? input : request(input)
+    request(input)
-  Effect.flatMap(req => EvaluationClient.evaluate(req as EvaluationRequestFor<...>))
+  Effect.flatMap(EvaluationClient.evaluate)

Out of scope

  • Runtime evaluation client validation or provider route behavior.

@opencode-agent opencode-agent Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks sound. Type checking for packages/ai, including the evaluation type tests in test/evaluation.types.ts, passes on both the base and this PR, and test/evaluation.test.ts passes. The per-model option types are still enforced after the covariance change, and passing EvaluationClient.evaluate straight to flatMap is fine. There's nothing to run, since runtime behaviour doesn't change.

Public API: only the experimental evaluation types in @opencode/ai change, and existing callers keep working. EvaluationRoute.evaluate changes from a function property to a method signature. EvaluationModel is now covariant in Options. The Model constraint on EvaluationRequestInput, request and run changes from object (plus a conditional check) to EvaluationModel. request gets a new EvaluationRequest | EvaluationRequestInput overload. Runtime behaviour, the CLI, the server, the SDK and config are untouched.

No concerns.

@rekram1-node
rekram1-node merged commit 51626ee into dev Oct 21, 2026
20 of 21 checks passed
@rekram1-node
rekram1-node deleted the evaluation-request-typing branch October 21, 2026 03:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant