Skip to main content

VariableValue

Discriminated union representing the value supplied for a PromptVariable. The modality field determines the concrete type.

Import

import type { VariableValue } from '@adaline/api';

Type Definition

type VariableValue =
  | TextContent
  | ImageContent
  | PdfContent
  | ApiContent
  | PromptContent;

Variants

modalityTypeDescription
"text"TextContentPlain text value
"image"ImageContentImage (URL or base64)
"pdf"PdfContentPDF document
"api"ApiContentExternal API data source
"prompt"PromptContentNested prompt reference

Example

import type { VariableValue } from '@adaline/api';

const textVar: VariableValue = {
  modality: 'text',
  value: 'John Doe'
};

const imageVar: VariableValue = {
  modality: 'image',
  detail: 'auto',
  value: { type: 'url', url: 'https://example.com/logo.png' }
};

const pdfVar: VariableValue = {
  modality: 'pdf',
  value: { type: 'url', url: 'https://example.com/report.pdf' },
  file: { name: 'report.pdf', id: 'file_123' }
};

Type narrowing

function processVariable(v: VariableValue) {
  switch (v.modality) {
    case 'text':
      console.log('Text:', v.value);
      break;
    case 'image':
      console.log('Image:', v.value.type);
      break;
    case 'pdf':
      console.log('PDF:', v.file.name);
      break;
  }
}