---
name: Cross-Language Type Definitions
status: closed
created: 2025-10-13T11:02:21Z
updated: 2025-10-14T07:35:14Z
github: https://github.com/BuzzTrail/video-extension/issues/135
depends_on: [004, 006, 007]
parallel: false
conflicts_with: []
---
When changing versions or addding or subtracking packages always use pnpm commands.  Don't just edit the package.json directly.

# Task: Cross-Language Type Definitions

## Description

Create shared type definitions for data structures used in both TypeScript and Python codebases. Establish TypeScript as the canonical source of truth and create corresponding Python TypedDict definitions. Document the synchronization process for future updates.

## Acceptance Criteria

- [ ] Shared types identified and documented (Supabase schemas, API payloads, bot configs)
- [ ] TypeScript-first canonical definitions created in `libs/shared/types/`
- [ ] Python TypedDict equivalents created for Python bots
- [ ] Synchronization process documented in `libs/shared/types/TYPES.md`
- [ ] All shared types have matching TypeScript and Python definitions
- [ ] Example usage provided for both languages
- [ ] Update checklist included in documentation

## Technical Details

**Phase 1: Identify Shared Types**

Audit codebase for types used in both TypeScript and Python:

1. **Supabase Schema Types**:
   - `ConversationSession`
   - `SlidevDeck`
   - `SlideControlCommand`

2. **API Payload Types**:
   - `GenerateCustomDeckRequest`
   - `GenerateCustomDeckResponse`
   - Bot spawn/status types

3. **Bot Configuration Types**:
   - `BotConfig`
   - `RoomConfig`
   - Environment settings

**Phase 2: Create TypeScript-First Definitions**

Create `libs/shared/types/src/lib/supabase.ts`:
```typescript
// Database schema types
export interface ConversationSession {
  id: string;
  tavus_conversation_id: string;
  daily_room_url: string;
  status: 'generating_deck' | 'deck_ready' | 'bot_active' | 'completed';
  created_at: string;
  updated_at: string;
}

export interface SlidevDeck {
  id: string;
  session_id: string;
  github_url: string;
  template_id: string;
  created_at: string;
}

export interface SlideControlCommand {
  id: string;
  session_id: string;
  command: 'next' | 'prev' | 'goto' | 'sync' | 'reload';
  slide_number?: number;
  created_at: string;
}
```

Create `libs/shared/types/src/lib/api.ts`:
```typescript
// API request/response types
export interface GenerateCustomDeckRequest {
  company: string;
  slides: Array<{ title: string; content: string }>;
  template_id?: string;
}

export interface GenerateCustomDeckResponse {
  deck_id: string;
  github_url: string;
  session_id: string;
}
```

**Phase 3: Create Python TypedDict Equivalents**

Create `libs/shared/types/types.py`:
```python
from typing import TypedDict, Literal, Optional, List

# Database schema types
class ConversationSession(TypedDict):
    id: str
    tavus_conversation_id: str
    daily_room_url: str
    status: Literal['generating_deck', 'deck_ready', 'bot_active', 'completed']
    created_at: str
    updated_at: str

class SlidevDeck(TypedDict):
    id: str
    session_id: str
    github_url: str
    template_id: str
    created_at: str

class SlideControlCommand(TypedDict):
    id: str
    session_id: str
    command: Literal['next', 'prev', 'goto', 'sync', 'reload']
    slide_number: Optional[int]
    created_at: str

# API types
class GenerateCustomDeckRequest(TypedDict):
    company: str
    slides: List[SlideData]
    template_id: Optional[str]

class SlideData(TypedDict):
    title: str
    content: str

class GenerateCustomDeckResponse(TypedDict):
    deck_id: str
    github_url: str
    session_id: str
```

**Phase 4: Document Synchronization Process**

Create `libs/shared/types/TYPES.md`:
```markdown
# Cross-Language Type Synchronization

## Overview
TypeScript types in `libs/shared/types/src/lib/` are the canonical source of truth.
Python types in `libs/shared/types/types.py` must be kept in sync manually.

## Update Checklist
When updating shared types:
- [ ] Update TypeScript interface first
- [ ] Update corresponding Python TypedDict
- [ ] Verify both match exactly (field names, types, optionality)
- [ ] Update version comment in types.py
- [ ] Run TypeScript typecheck: `pnpm nx typecheck shared-types`
- [ ] Run Python mypy: `mypy libs/shared/types/types.py`
- [ ] Update this document if new types added

## Type Mapping Reference
TypeScript → Python:
- string → str
- number → int | float
- boolean → bool
- T[] → List[T]
- T | null → Optional[T]
- 'a' | 'b' → Literal['a', 'b']
- interface → TypedDict

## Examples
[Include usage examples for both languages]
```

**Phase 5: Integration**

Update Python bots to import shared types:
```python
import sys
sys.path.append('../../../../libs/shared/types')
from types import ConversationSession, SlideControlCommand
```

Update TypeScript apps to use shared types:
```typescript
import { ConversationSession, SlideControlCommand } from '@buzztrail/shared/types';
```

## Dependencies

- [ ] Task 004 completed (TypeScript types in place)
- [ ] Task 006 completed (Screenshare bot ready for type imports)
- [ ] Task 007 completed (Tool forwarder bot ready for type imports)

## Effort Estimate

- **Size**: M
- **Hours**: 8 hours
- **Parallel**: false (needs TypeScript and Python foundations)

## Definition of Done

- [ ] All shared types identified and documented
- [ ] TypeScript canonical definitions created
- [ ] Python TypedDict equivalents created
- [ ] Types match exactly across languages
- [ ] Synchronization process documented
- [ ] Both languages can import and use shared types
- [ ] Examples provided for common use cases
- [ ] Code review completed
- [ ] Documentation reviewed by team
