All files / shared/src/types/data ai-provider.ts

100% Statements 35/35
100% Branches 0/0
100% Functions 0/0
100% Lines 35/35

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 73 74 75 76 77 78 79 80 81 82 83 841x                               1x 1x 1x 1x 1x 1x 1x 1x 1x       1x 1x 1x 1x 1x 1x 1x 1x 1x                           1x 1x 1x 1x 1x 1x 1x 1x                           1x 1x 1x 1x 1x 1x 1x 1x          
import { z } from 'zod';
 
/**
 * AI Provider Config schema for database records
 * Represents a configured AI provider instance (ai_providers table)
 * @property {string} id - Unique identifier
 * @property {string} ai_provider - AI provider identifier (e.g., 'ollama', 'openai')
 * @property {string} name - User-defined name for the AI provider
 * @property {string} api_key - Encrypted API key value
 * @property {Record<string, unknown>} custom_fields - Dynamic JSONB object for provider-specific configuration.
 *   Can include custom_host, api_version, custom_endpoint, or any other provider-specific settings.
 *   Examples: { "custom_host": "http://localhost:8080" }, { "api_version": "v2", "region": "us-east-1" }
 *   SECURITY: Values should be validated by the specific provider implementation at runtime.
 * @property {string} created_at - ISO timestamp of creation
 * @property {string} updated_at - ISO timestamp of last update
 */
export const AIProviderConfig = z.object({
  id: z.string(),
  ai_provider: z.string(),
  name: z.string(),
  api_key: z.string().nullable(),
  custom_fields: z.record(z.string(), z.unknown()).default({}),
  created_at: z.string(),
  updated_at: z.string(),
});
 
export type AIProviderConfig = z.infer<typeof AIProviderConfig>;
 
export const AIProviderConfigQueryParams = z
  .object({
    id: z.string().optional(),
    ai_provider: z.string().optional(),
    name: z.string().optional(),
    limit: z.coerce.number().int().positive().optional(),
    offset: z.coerce.number().int().min(0).optional(),
  })
  .strict();
 
export type AIProviderConfigQueryParams = z.infer<
  typeof AIProviderConfigQueryParams
>;
 
/**
 * Parameters for creating a new AI Provider Config
 * @property {string} ai_provider - AI provider identifier (required)
 * @property {string} name - User-defined name for the AI provider (required)
 * @property {string} [api_key] - API key value (optional for self-hosted providers)
 * @property {Record<string, unknown>} [custom_fields] - Optional dynamic fields for provider-specific configuration.
 *   Can include custom_host, api_version, custom_endpoint, or any other provider-specific settings.
 */
export const AIProviderConfigCreateParams = z
  .object({
    ai_provider: z.string().min(1),
    name: z.string().min(1),
    api_key: z.string().nullable().optional(),
    custom_fields: z.record(z.string(), z.unknown()).optional().default({}),
  })
  .strict();
 
export type AIProviderConfigCreateParams = z.infer<
  typeof AIProviderConfigCreateParams
>;
 
/**
 * Parameters for updating an existing AI Provider Config
 * @property {string} [ai_provider] - AI provider identifier
 * @property {string} [name] - User-defined name for the AI provider
 * @property {string} [api_key] - API key value (only included if being updated)
 * @property {Record<string, unknown>} [custom_fields] - Dynamic fields for provider-specific configuration.
 *   Can include custom_host, api_version, custom_endpoint, or any other provider-specific settings.
 */
export const AIProviderConfigUpdateParams = z
  .object({
    ai_provider: z.string().min(1).optional(),
    name: z.string().min(1).optional(),
    api_key: z.string().nullable().optional(),
    custom_fields: z.record(z.string(), z.unknown()).optional(),
  })
  .strict();
 
export type AIProviderConfigUpdateParams = z.infer<
  typeof AIProviderConfigUpdateParams
>;