@etaio/core-types
v2.0.0
Published
Core TypeScript type definitions for the Etaio generative AI ecosystem
Readme
@etaio/core-types
Core TypeScript type definitions and interfaces for the Etaio generative AI ecosystem.
Installation
npm install @etaio/core-types
# or
pnpm add @etaio/core-typesOverview
This package provides the foundational types and interfaces used across all Etaio packages, ensuring type safety and consistency throughout the ecosystem.
Core Types
GenerativeAsset
Base interface for all generated assets (images, videos, audio):
import { GenerativeAsset } from '@etaio/core-types';
const asset: GenerativeAsset = {
id: 'asset-123',
type: 'image',
url: 'https://example.com/image.jpg',
metadata: {
provider: 'openai',
model: 'dall-e-3',
generatedAt: '2024-01-01T00:00:00Z'
}
};GenerationCost
Track and estimate generation costs:
import { GenerationCost } from '@etaio/core-types';
const cost: GenerationCost = {
provider: 'stability',
model: 'sdxl',
estimatedCost: 0.05,
actualCost: 0.048,
currency: 'USD',
confidence: 'high',
breakdown: {
credits: { count: 1, costPerCredit: 0.048 }
}
};UsageRecord
Track usage across providers:
import { UsageRecord } from '@etaio/core-types';
const usage: UsageRecord = {
id: 'usage-123',
userId: 'user-456',
projectId: 'project-789',
provider: 'openai',
model: 'dall-e-3',
type: 'image',
cost: 0.04,
currency: 'USD',
timestamp: '2024-01-01T00:00:00Z'
};GenerativeProvider
Base interface for implementing providers:
import { GenerativeProvider } from '@etaio/core-types';
class MyProvider implements GenerativeProvider {
type = 'image' as const;
name = 'my-provider';
models = ['model-1', 'model-2'];
async isAvailable(): Promise<boolean> {
// Check if provider is available
return true;
}
async generate(request: any): Promise<any> {
// Generate content
}
async estimateCost(request: any): Promise<GenerationCost> {
// Estimate generation cost
}
validateRequest(request: any): ValidationResult {
// Validate request
}
getLimits(): ProviderLimits {
// Return provider limits
}
getCapabilities(): ProviderCapabilities {
// Return provider capabilities
}
}Provider Capabilities & Limits
import { ProviderCapabilities, ProviderLimits } from '@etaio/core-types';
const capabilities: ProviderCapabilities = {
streaming: true,
batching: true,
variations: true,
editing: false,
customModels: false
};
const limits: ProviderLimits = {
maxPromptLength: 4000,
maxBatchSize: 10,
maxDimensions: { width: 2048, height: 2048 },
minDimensions: { width: 256, height: 256 },
supportedFormats: ['png', 'jpeg', 'webp'],
rateLimit: {
requests: 100,
window: 60 // seconds
}
};Budget Management
import { GenerationBudget } from '@etaio/core-types';
const budget: GenerationBudget = {
daily: 10.00,
monthly: 200.00,
perRequest: 1.00,
currency: 'USD'
};Error Handling
import { ProviderError } from '@etaio/core-types';
throw new ProviderError(
'Provider unavailable',
'PROVIDER_UNAVAILABLE',
'openai',
true // retryable
);Asset Types
ImageAsset
import { ImageAsset } from '@etaio/core-types';
const image: ImageAsset = {
id: 'img-123',
type: 'image',
url: 'https://example.com/image.jpg',
thumbnailUrl: 'https://example.com/thumb.jpg',
dimensions: { width: 1024, height: 1024 },
format: 'jpeg',
size: 2048000, // bytes
metadata: {
provider: 'openai',
model: 'dall-e-3',
prompt: 'A beautiful sunset'
}
};VideoAsset
import { VideoAsset } from '@etaio/core-types';
const video: VideoAsset = {
id: 'vid-123',
type: 'video',
url: 'https://example.com/video.mp4',
duration: 5.0, // seconds
fps: 24,
resolution: { width: 1920, height: 1080 },
format: 'mp4',
codec: 'h264'
};AudioAsset
import { AudioAsset } from '@etaio/core-types';
const audio: AudioAsset = {
id: 'aud-123',
type: 'audio',
url: 'https://example.com/audio.mp3',
duration: 30.5, // seconds
format: 'mp3',
sampleRate: 44100,
bitrate: 128000,
channels: 2
};Usage Statistics
import { UsageStats } from '@etaio/core-types';
const stats: UsageStats = {
totalCost: 42.50,
totalCount: 150,
byProvider: {
openai: { cost: 30.00, count: 100 },
stability: { cost: 12.50, count: 50 }
},
byType: {
image: { cost: 25.00, count: 80 },
video: { cost: 15.00, count: 50 },
audio: { cost: 2.50, count: 20 }
},
daily: [
{ date: '2024-01-01', cost: 10.00, count: 30 }
],
monthly: [
{ month: '2024-01', cost: 42.50, count: 150 }
]
};TypeScript Benefits
- ✅ Full type safety across all Etaio packages
- ✅ IntelliSense support in modern IDEs
- ✅ Compile-time error checking
- ✅ Self-documenting code
- ✅ Consistent API interfaces
License
MIT © Etaio
Support
For issues and feature requests, please visit our GitHub repository.
