Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/core/src/routing/modelRouterService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class ModelRouterService {
*/
async route(context: RoutingContext): Promise<RoutingDecision> {
const startTime = Date.now();
let decision: RoutingDecision;
let decision: RoutingDecision | undefined;

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.

high

Changing the type of decision to RoutingDecision | undefined will cause a TypeScript compilation error at the return statement (line 133), as the function's return type is Promise<RoutingDecision>. Instead of using a non-null assertion (!), you should handle the undefined case explicitly (e.g., by providing a default with ?? or throwing an error) to satisfy the compiler. This ensures you are coding against the interface contract rather than relying on implementation details that might change. Note that line 133 is outside the current diff hunks, so you will need to apply this fix manually.

References
  1. When a property or variable is optional in its type definition, callers must handle the undefined case explicitly (e.g., by providing a default) rather than relying on implementation details to guarantee a value.


const [enableNumericalRouting, thresholdValue] = await Promise.all([
this.config.getNumericalRoutingEnabled(),
Expand Down Expand Up @@ -117,10 +117,10 @@ export class ModelRouterService {
);
} finally {
const event = new ModelRoutingEvent(
decision!.model,
decision!.metadata.source,
decision!.metadata.latencyMs,
decision!.metadata.reasoning,
decision?.model || 'unknown',
decision?.metadata?.source || 'unknown',
decision?.metadata?.latencyMs || 0,
decision?.metadata?.reasoning,
failed,
error_message,
this.config.getApprovalMode(),
Expand Down
Loading