Commit Graph

47 Commits

Author SHA1 Message Date
Oleg Proskurin 3e3f15cd9c fix: live endpoint 2025-11-16 22:46:39 +07:00
Oleg Proskurin bbc007bccd feat: add images references 2025-11-16 18:57:23 +07:00
Oleg Proskurin d6ca79152c fix: service and tests 2025-11-10 00:57:06 +07:00
Oleg Proskurin 874cc4fcba fix: add resolve endpoint and correct live path
CRITICAL FIXES:
- Add GET /api/v1/images/resolve/:alias endpoint with 3-tier alias resolution
  - Supports optional flowId query parameter
  - Returns image, scope (technical/flow/project), and flowId
  - Placed before GET /:id to avoid route conflict
- Change live endpoint from /api/v1/live/generate to /api/v1/live
  - Corrects path to match specification

PARAMETER NAMING:
- Rename outputAlias to assignAlias in requests and service
- Rename flowAliases to assignFlowAlias in requests and service
- Update generations route to use new parameter names

FLOW TIMESTAMP UPDATES:
- Add flow.updatedAt trigger in ImageService.create()
  - Updates flow timestamp when image is uploaded to a flow
- Flow.updatedAt already updated in GenerationService.create()

AUDIT TRAIL VERIFICATION:
- Confirmed apiKeyId is properly saved in generations table
- Confirmed apiKeyId is properly saved in images table (both upload and generation)

TYPE FIXES:
- Add explicit | undefined to AliasResolutionResponse.flowId

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 23:40:31 +07:00
Oleg Proskurin ca112886e5 feat: implement Phase 5 live generation with prompt caching
Implement cached generation endpoint that streams image bytes directly with
intelligent caching based on prompt hashing for optimal performance.

**Core Service:**
- **PromptCacheService**: Prompt-based cache management
  - SHA-256 hashing of prompts for cache lookup
  - Cache hit/miss tracking with statistics
  - Support for cache entry creation and retrieval
  - Hit count and last accessed timestamp tracking
  - Cache statistics per project

**v1 API Routes:**
- `GET /api/v1/live/generate` - Generate with caching, stream image bytes

**Endpoint Features:**
- Prompt-based caching with SHA-256 hashing
- Cache HIT: Streams existing image with X-Cache-Status: HIT header
- Cache MISS: Generates new image, caches it, streams with X-Cache-Status: MISS
- Direct image byte streaming (not JSON response)
- Cache-Control headers for browser caching (1 year max-age)
- Hit count tracking for cache analytics
- Integration with promptUrlCache database table

**Caching Logic:**
- Compute SHA-256 hash of prompt for cache key
- Check cache by promptHash and projectId
- On HIT: Fetch image from database, download from storage, stream bytes
- On MISS: Generate new image, create cache entry, stream bytes
- Record cache hits with incremented hit count

**Response Headers:**
- Content-Type: image/jpeg (or appropriate MIME type)
- Content-Length: Actual byte length
- Cache-Control: public, max-age=31536000 (1 year)
- X-Cache-Status: HIT | MISS
- X-Cache-Hit-Count: Number of cache hits (on HIT)
- X-Generation-Id: UUID (on MISS)
- X-Image-Id: UUID (always)

**Technical Notes:**
- Uses ImageService to fetch cached images by ID
- Uses StorageFactory to download image buffers from MinIO
- Parses storage keys to extract org/project/category/filename
- Validates storage key format before download
- All Phase 5 code is fully type-safe with zero TypeScript errors

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 23:00:10 +07:00
Oleg Proskurin 4785d23179 feat: implement Phase 4 image management with upload and CRUD endpoints
Implement complete image management system with file upload, listing, retrieval,
updates, alias assignment, and soft deletion.

**v1 API Routes:**
- `POST /api/v1/images/upload` - Upload single image file with database record
- `GET /api/v1/images` - List images with filters and pagination
- `GET /api/v1/images/:id` - Get single image by ID
- `PUT /api/v1/images/:id` - Update image metadata (alias, focal point, meta)
- `PUT /api/v1/images/:id/alias` - Assign project-scoped alias to image
- `DELETE /api/v1/images/:id` - Soft delete image

**Upload Endpoint Features:**
- Uses uploadSingleImage middleware for file handling
- Creates database record with image metadata
- Stores file in MinIO storage (uploads category)
- Supports optional alias and flowId parameters
- Returns ImageResponse with all metadata

**Route Features:**
- Authentication via validateApiKey middleware
- Project key requirement
- Rate limiting on upload endpoint
- Request validation with pagination
- Error handling with proper status codes
- Response transformation with toImageResponse converter
- Project ownership verification for all operations

**ImageService Integration:**
- Uses existing ImageService methods
- Supports filtering by flowId, source, alias
- Soft delete with deletedAt timestamp
- Alias validation and conflict detection

**Type Updates:**
- Updated ImageFilters with explicit | undefined for optional properties
- All response types already defined in responses.ts

**Technical Notes:**
- Upload creates both storage record and database entry atomically
- Focal point stored as JSON with x/y coordinates
- Meta field for flexible metadata storage
- File hash set to null (TODO: implement hashing)
- All Phase 4 code is fully type-safe with zero TypeScript errors

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 22:41:59 +07:00
Oleg Proskurin 85395084b7 feat: implement Phase 3 flow management with service and endpoints
Implement complete flow management system with CRUD operations, computed counts,
and alias management capabilities for organizing generation chains.

**Core Service:**
- **FlowService**: Complete flow lifecycle management
  - Create flows with initial empty aliases
  - CRUD operations (create, read, update, delete)
  - Computed counts for generations and images per flow
  - Alias management (add, update, remove)
  - Get flow's generations and images with pagination
  - No soft delete (flows use hard delete)

**v1 API Routes:**
- `POST /api/v1/flows` - Create new flow
- `GET /api/v1/flows` - List flows with pagination and counts
- `GET /api/v1/flows/:id` - Get single flow with computed counts
- `GET /api/v1/flows/:id/generations` - List flow's generations
- `GET /api/v1/flows/:id/images` - List flow's images
- `PUT /api/v1/flows/:id/aliases` - Update flow aliases (add/modify)
- `DELETE /api/v1/flows/:id/aliases/:alias` - Remove specific alias
- `DELETE /api/v1/flows/:id` - Delete flow (hard delete)

**Route Features:**
- Authentication via validateApiKey middleware
- Project key requirement
- Request validation with pagination
- Error handling with proper status codes
- Response transformation with toFlowResponse converter
- Project ownership verification for all operations

**Type Updates:**
- Added ListFlowGenerationsResponse and ListFlowImagesResponse
- Updated GetFlowResponse to return FlowResponse (not FlowWithDetailsResponse)
- FlowService methods return FlowWithCounts where appropriate

**Technical Notes:**
- Flows don't have deletedAt column (no soft delete support)
- All count queries filter active generations/images only
- Alias updates are merged with existing aliases
- Empty flows return generationCount: 0, imageCount: 0
- All Phase 3 code is fully type-safe with zero TypeScript errors

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 22:24:40 +07:00
Oleg Proskurin 2c67dad9c2 feat: implement Phase 2 core generation flow with services and endpoints
Implement the complete image generation lifecycle with ImageService, GenerationService,
and v1 API endpoints. This enables end-to-end generation with alias support and flow management.

**Core Services:**
- **ImageService**: Full CRUD for images table
  - Create/read/update/delete operations
  - Soft delete support with deletedAt
  - Project and flow alias assignment
  - Storage key and file hash tracking
  - Pagination and filtering

- **GenerationService**: Complete generation lifecycle orchestration
  - Create generation records with pending status
  - Resolve reference images via AliasService
  - Call ImageGenService for AI generation
  - Create image records in database
  - Link images to generations
  - Update generation status (processing → success/failed)
  - Support for flow association and alias assignment
  - Retry failed generations
  - Soft/hard delete operations

**v1 API Routes:**
- `POST /api/v1/generations` - Create with references & aliases
- `GET /api/v1/generations` - List with filters & pagination
- `GET /api/v1/generations/:id` - Get with full relations
- `POST /api/v1/generations/:id/retry` - Retry failed generation
- `DELETE /api/v1/generations/:id` - Delete generation & output

**Route Features:**
- Authentication via validateApiKey middleware
- Project key requirement
- Rate limiting per API key
- Request validation with pagination
- Error handling with proper status codes
- Response transformation with type converters

**Type Updates:**
- Add explicit undefined to optional properties for exactOptionalPropertyTypes
- CreateGenerationParams interface for service layer
- GenerationFilters with proper optionals

**Infrastructure:**
- Mount v1Router at /api/v1 in app.ts
- Keep legacy routes for backward compatibility
- Versioned API structure for future iterations

**Technical Notes:**
- Reference image download temporarily skipped (TODO: storage key parsing)
- File hash computation temporarily disabled (TODO: helper method)
- File size set to 0 (TODO: get from storage)
- All Phase 2 code is fully type-safe with zero TypeScript errors

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 22:14:49 +07:00
Oleg Proskurin c185ea3ff4 feat: add Phase 1 foundation for API v2.0
Implement foundational components for Banatie API v2.0 with dual alias system,
flows support, and comprehensive type safety.

**Type Definitions:**
- Add models.ts with database types (Generation, Image, Flow, etc.)
- Add requests.ts with all v2 API request types
- Add responses.ts with standardized response types and converters
- Support for pagination, filters, and complex relations

**Constants:**
- Define technical aliases (@last, @first, @upload)
- Define reserved aliases and validation patterns
- Add rate limits for master/project keys (2-bucket system)
- Add pagination, image, generation, and flow limits
- Comprehensive error messages and codes

**Validators:**
- aliasValidator: Format validation, reserved alias checking
- paginationValidator: Bounds checking with normalization
- queryValidator: UUID, aspect ratio, focal point, date range validation

**Helpers:**
- paginationBuilder: Standardized pagination response construction
- hashHelper: SHA-256 utilities for caching and file deduplication
- queryHelper: Reusable WHERE clause builders with soft delete support

**Core Services:**
- AliasService: 3-tier alias resolution (technical → flow → project)
  - Technical alias computation (@last, @first, @upload)
  - Flow-scoped alias lookup from JSONB
  - Project-scoped alias lookup with uniqueness
  - Conflict detection and validation
  - Batch resolution support

**Dependencies:**
- Add drizzle-orm to api-service for direct ORM usage

All Phase 1 code is type-safe with zero TypeScript errors.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-09 21:53:50 +07:00
Oleg Proskurin d1806bfd7e feat: enhance api key api 2025-10-25 18:57:19 +07:00
Oleg Proskurin b0943606e1 fix: ts issue 2025-10-12 23:01:52 +07:00
Oleg Proskurin 7416c6d441 chore: code cleanup 2025-10-12 22:59:24 +07:00
Oleg Proskurin e0924f9c4b fix: get images endpoint 2025-10-12 22:55:37 +07:00
Oleg Proskurin 3cbb366a9d chore: update docs 2025-10-12 22:19:10 +07:00
Oleg Proskurin 9a9c7260e2 fix: return correct codes 2025-10-12 22:13:34 +07:00
Oleg Proskurin 691e472a2e chore: add todo 2025-10-12 22:05:23 +07:00
Oleg Proskurin 55c8d23c1b feat: update config 2025-10-12 21:49:42 +07:00
Oleg Proskurin dd48d4e1a1 feat: update setup 2025-10-12 21:12:58 +07:00
Oleg Proskurin eb11db753e chore: debug logs 2025-10-12 16:42:33 +07:00
Oleg Proskurin 1b3a357b5d feat: add gallery 2025-10-12 00:30:16 +07:00
Oleg Proskurin f942480fc8 feat: filename sanitization 2025-10-11 18:11:56 +07:00
Oleg Proskurin 237443194f feat: add file upload endpoint 2025-10-11 00:08:51 +07:00
Oleg Proskurin 6944e6b750 feat: detect network issues 2025-10-10 00:17:29 +07:00
Oleg Proskurin 83303f8890 feat: remove unused endpoints 2025-10-09 23:48:25 +07:00
Oleg Proskurin 2a4ba8f4ed feat: cover Enhancemet service by tests 2025-10-09 23:37:17 +07:00
Oleg Proskurin df6596d53c chore: prettier 2025-10-09 23:16:42 +07:00
Oleg Proskurin 3462971e30 feat: add prettier 2025-10-09 22:48:29 +07:00
Oleg Proskurin 1ea8492e21 refactor: expand enhancement service 2025-10-08 23:41:02 +07:00
Oleg Proskurin a97029a2b4 feat: log enhancement work 2025-10-08 22:19:06 +07:00
Oleg Proskurin 7c31644824 feat: add meta tags 2025-10-08 00:03:08 +07:00
Oleg Proskurin 847145c385 feat: update API 2025-10-07 22:28:27 +07:00
Oleg Proskurin 63aa812f5e chore: prettify 2025-10-07 22:05:00 +07:00
Oleg Proskurin 585b446ca5 feat: add aspect ratio 2025-10-07 21:13:05 +07:00
Oleg Proskurin 620a2a9caa chore: update the model 2025-10-06 23:41:26 +07:00
Oleg Proskurin 367f1d1946 feat: log generation requests 2025-10-06 23:25:20 +07:00
Oleg Proskurin 680d2d2bad feat: improve demo page 2025-10-05 23:30:49 +07:00
Oleg Proskurin 97502ddae1 fix: demo page inlanding 2025-10-05 19:41:04 +07:00
Oleg Proskurin bfff9b49ec fix: org project and apikey creating 2025-10-05 18:45:15 +07:00
Oleg Proskurin bdf2c80782 feat: stored under org/project path 2025-10-05 17:36:01 +07:00
Oleg Proskurin e2cfd6e27f fix: service config 2025-10-05 16:50:09 +07:00
Oleg Proskurin 91ba71cc23 fix: image paths 2025-10-04 01:42:58 +07:00
Oleg Proskurin 960183c9c4 fix: CORS settings 2025-10-04 01:29:59 +07:00
Oleg Proskurin c6f359c126 fix: pass organization id 2025-10-04 00:13:02 +07:00
Oleg Proskurin 35df8a031d fix: add apikeys 2025-10-01 21:29:10 +07:00
Oleg Proskurin 298898f79d feat: implement apikey auth 2025-10-01 00:14:14 +07:00
Oleg Proskurin f572428a87 fix: image generation 2025-09-29 22:49:32 +07:00
Oleg Proskurin babcbe29db feat: move to monorepo 2025-09-29 21:58:43 +07:00