<!-- source-hash: 8a6f81705a1810d60982ff3e397e9ebc -->
Defines TypeScript types and constants for all network and communication layers in the Flamingo platform, including NATS messaging, WebSocket connections, streaming chunk data, and API response shapes.

## Key Components

### Types & Enums

| Export | Description |
|--------|-------------|
| `NatsMessageType` | Union type for NATS message categories: `'message'` or `'admin-message'` |
| `NatsConnectionStatus` | Connection lifecycle states: `connecting`, `connected`, `disconnected`, `reconnecting`, `closed`, `error` |
| `NatsConnectionSource` | Origin of a NATS connection: `client`, `agent`, or `dashboard` |

### Constants

| Export | Description |
|--------|-------------|
| `NETWORK_CONFIG` | Frozen config object with timeouts, retry backoff, ping intervals, and message limits |
| `NetworkConfig` | Inferred type from `NETWORK_CONFIG` |

### Interfaces

| Export | Description |
|--------|-------------|
| `ChunkData` | Streaming dialog chunk payload — carries sequence IDs, tool execution data, approval requests, model metadata, and stream state |
| `BufferedChunk` | Wraps a `ChunkData` with its `NatsMessageType` for buffered delivery |
| `WebSocketMessage` | Generic WebSocket envelope with `type`, `payload`, and optional metadata |
| `WebSocketConfig` | Full WebSocket client configuration including reconnect strategy and event handlers |
| `FetchChunksFunction` | Async function signature for polling dialog chunks by `dialogId` and `ChatType` |
| `NetworkResponse<T>` | Standard API response wrapper with `success`, `data`, `error`, and `message` |
| `PaginatedResponse<T>` | Extends `NetworkResponse<T>` with pagination metadata |
| `NetworkError` | Structured error shape with `code`, `message`, optional `details`, and `timestamp` |

## Usage Example

```typescript
import type {
  ChunkData,
  FetchChunksFunction,
  NetworkResponse,
  PaginatedResponse,
  NatsConnectionStatus,
} from './network.types'
import { NETWORK_CONFIG } from './network.types'

// Use constants for consistent timeout configuration
const client = createNatsClient({
  timeout: NETWORK_CONFIG.CONNECT_TIMEOUT_MS,
  reconnectTimeWait: NETWORK_CONFIG.RECONNECT_TIME_WAIT_MS,
  maxPingOut: NETWORK_CONFIG.MAX_PING_OUT,
})

// Type-safe connection state handler
function onStatusChange(status: NatsConnectionStatus) {
  if (status === 'reconnecting') {
    console.warn('NATS reconnecting...')
  }
}

// Typed chunk fetch implementation
const fetchChunks: FetchChunksFunction = async (dialogId, chatType, fromSequenceId) => {
  const res = await api.get<ChunkData[]>(`/dialogs/${dialogId}/chunks`, {
    params: { chatType, from: fromSequenceId },
  })
  return res.data
}

// Paginated API response
const response: PaginatedResponse<ChunkData[]> = await fetchPage(dialogId, 1)
console.log(`Page ${response.page} of ${response.totalPages}`)
```