# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

### Changed

- **[2025-10-07] Fixed hardcoded project ID in `label-studio-label-page.ts`**
  - **Impact**: Critical bug fix - Now supports dynamic project routing
  - **Changes**:
    - Replaced hardcoded `/projects/3` with dynamic project ID extraction from URL route
    - Added `projectId` property to LabelStudioLabelPage component
    - Implemented `_extractProjectIdFromRoute()` method to parse project ID from window.location.pathname
    - Added error handling for missing project ID
  - **Files modified**:
    - `client/label-studio-label-page.ts:28,33-60`
  - **Migration**: No breaking changes - component now accepts optional `projectId` property

- **[2025-10-07] Enhanced error handling and loading states**
  - **Impact**: Improved user experience with better feedback
  - **Changes**:
    - Added iframe load timeout detection (15 seconds)
    - Added iframe error event handler
    - Added `iframeLoaded` state tracking
    - Improved error messages for iframe loading failures
  - **Files modified**:
    - `client/label-studio-wrapper.ts:124,127-137,168-178,223`
  - **Benefits**: Users now get clear feedback when Label Studio fails to load

- **[2025-10-07] Uncommented webhook exports in server/index.ts**
  - **Impact**: Public API now properly exports webhook-related types and functions
  - **Changes**:
    - Uncommented exports for: `WebhookAction`, `WebhookPayload`, `WebhookHandler`, `registerWebhookHandler`, `unregisterWebhookHandler`, `clearWebhookHandlers`
    - These exports were previously commented out but are fully implemented and functional
  - **Files modified**:
    - `server/index.ts:5-12`
  - **Benefits**: Users can now extend webhook functionality for custom Label Studio event handling

### Technical Details

#### Dynamic Project ID Implementation

```typescript
// Before
const path = '/projects/3' // Hardcoded project ID

// After
const projectId = this.projectId || this._extractProjectIdFromRoute()
const path = `/projects/${projectId}`
```

#### Error Handling Enhancement

- Added `@error=${this.handleIframeError}` event listener on iframe element
- Added timeout detection to catch cases where iframe loads but never fires load event
- Clear error messages guide users to check server connectivity

#### Webhook API Exports

Users can now register custom webhook handlers:

```typescript
import { registerWebhookHandler, WebhookAction } from 'integration-label-studio'

registerWebhookHandler(WebhookAction.ANNOTATION_CREATED, async (payload, ctx) => {
  // Custom annotation handling logic
})
```

### Summary

**Total Files Modified**: 3

- `client/label-studio-label-page.ts` - Fixed hardcoded project ID
- `client/label-studio-wrapper.ts` - Enhanced error handling
- `server/index.ts` - Enabled webhook API exports

**Impact**:

- ✅ Fixes critical routing bug
- ✅ Improves user experience with loading states
- ✅ Enables webhook extensibility

**Production Ready**: Yes - All changes are backward compatible
