UNPKG

its-compiler-js

Version:

JavaScript/TypeScript implementation of the Instruction Template Specification (ITS) compiler

130 lines (129 loc) 3.83 kB
/** * Type definitions for ITS Compiler */ export interface ITSTemplate { $schema?: string; version: string; description?: string; extends?: string[]; variables?: Record<string, any>; customInstructionTypes?: Record<string, InstructionTypeDefinition>; content: ContentElement[]; compilerConfig?: CompilerConfig; } export interface ContentElement { type: 'text' | 'placeholder' | 'conditional'; id?: string; } export interface TextElement extends ContentElement { type: 'text'; text: string; } export interface PlaceholderElement extends ContentElement { type: 'placeholder'; instructionType: string; config: PlaceholderConfig; } export interface ConditionalElement extends ContentElement { type: 'conditional'; condition: string; content: ContentElement[]; else?: ContentElement[]; } export interface PlaceholderConfig { description: string; [key: string]: any; } export interface InstructionTypeDefinition { template: string; description?: string; configSchema?: Record<string, any>; source?: string; } export interface CompilerConfig { systemPrompt?: string; userContentWrapper?: string; instructionWrapper?: string; processingInstructions?: string[]; } export interface CompilationOptions { variables?: Record<string, any>; baseUrl?: string; allowHttp?: boolean; maxSchemaSize?: number; timeout?: number; cache?: boolean; strict?: boolean; } export interface CompilationResult { prompt: string; template: ITSTemplate; variables: Record<string, any>; overrides: TypeOverride[]; warnings: string[]; compilationTime?: number; } export interface ValidationResult { isValid: boolean; errors: string[]; warnings: string[]; securityIssues: string[]; validationTime?: number; } export interface TypeOverride { typeName: string; overrideSource: string; overriddenSource: string; overrideType: OverrideType; } export declare enum OverrideType { CUSTOM = "custom", SCHEMA_EXTENSION = "schema", STANDARD = "standard" } export interface SecurityConfig { allowHttp: boolean; blockLocalhost: boolean; blockPrivateNetworks: boolean; domainAllowlist?: string[]; maxTemplateSize: number; maxContentElements: number; maxNestingDepth: number; maxExpressionLength: number; requestTimeout: number; } export interface SchemaCache { [url: string]: { schema: any; cachedAt: number; expiresAt: number; }; } export declare class ITSError extends Error { details?: Record<string, any>; errorCode?: string; constructor(message: string, details?: Record<string, any>, errorCode?: string); } export declare class ITSValidationError extends ITSError { path?: string; validationErrors: string[]; securityIssues: string[]; constructor(message: string, path?: string, validationErrors?: string[], securityIssues?: string[], details?: Record<string, any>); } export declare class ITSCompilationError extends ITSError { elementId?: string; elementType?: string; compilationStage?: string; constructor(message: string, elementId?: string, elementType?: string, compilationStage?: string, details?: Record<string, any>); } export declare class ITSSecurityError extends ITSError { securityRule?: string; threatType?: string; blockedContent?: string; constructor(message: string, securityRule?: string, threatType?: string, blockedContent?: string, details?: Record<string, any>); } export declare class ITSVariableError extends ITSError { variablePath?: string; availableVariables?: string[]; constructor(message: string, variablePath?: string, availableVariables?: string[], details?: Record<string, any>); }