# All files / src/chat Validation.ts

66.66% Statements 12/18
77.77% Branches 21/27
100% Functions 3/3
73.33% Lines 11/15

Press n or j to go to the next uncovered block, b, p or k for the previous block.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72

    11x

    10x

    2x

    8x

    26x

    26x

    1x

    25x

    5x

    5x

    5x

     import { Provider } from "../providers/Provider.js";
    import { logger } from "../utils/logger.js";

    export interface ValidationOptions {
      assumeModelExists?: boolean;
    }

    export class ChatValidator {
      static validateVision(
        provider: Provider,
        model: string,
        hasBinary: boolean,
        options: ValidationOptions
      ) {
        if (!hasBinary) return;

        if (
          !options.assumeModelExists &&
          provider.capabilities &&
          !provider.capabilities.supportsVision(model)
        ) {
          throw new Error(`Model ${model} does not support vision/binary files.`);
        }

        Iif (options.assumeModelExists) {
          logger.warn(`Skipping vision capability validation for model ${model}`);
        }
      }

      static validateTools(
        provider: Provider,
        model: string,
        hasTools: boolean,
        options: ValidationOptions
      ) {
        Iif (!hasTools) return;

        if (
          !options.assumeModelExists &&
          provider.capabilities &&
          !provider.capabilities.supportsTools(model)
        ) {
          throw new Error(`Model ${model} does not support tool calling.`);
        }

        Iif (options.assumeModelExists) {
          logger.warn(`Skipping tool capability validation for model ${model}`);
        }
      }

      static validateStructuredOutput(
        provider: Provider,
        model: string,
        hasSchema: boolean,
        options: ValidationOptions
      ) {
        Iif (!hasSchema) return;

        Iif (
          !options.assumeModelExists &&
          provider.capabilities &&
          !provider.capabilities.supportsStructuredOutput(model)
        ) {
          throw new Error(`Model ${model} does not support structured output.`);
        }

        Iif (options.assumeModelExists) {
          logger.warn(`Skipping structured output capability validation for model ${model}`);
        }
      }
    }