Each API namespace should follow this specific structure:
```
src/api/{namespace}/
├── {namespace}Requests.ts # Contains all request interfaces and types
├── {namespace}Responses.ts # Contains all response interfaces and types
└── index.ts # Exports all public interfaces and functions
```
## File Requirements
### {namespace}Requests.ts
- Must contain all request interfaces and types for the namespace
- Each request interface should be prefixed with the namespace
- Must include proper TypeScript types and documentation
```typescript
// Example from chatRequests.ts
import type { BusterSocketRequestBase } from '../base_interfaces';
/**
* Request type for creating a new chat session or continuing an existing one.
*@interface ChatCreateNewChat
*@extends BusterSocketRequestBase
*/
export type ChatCreateNewChat = BusterSocketRequestBase<
'/chats/post',
{
/** The ID of the dataset to associate with the chat. Null if no dataset is associated */
dataset_id: string | null;
/** The initial message or prompt to start the chat conversation */
prompt: string;
/** Optional ID of an existing chat for follow-up messages. Null for new chats */
chat_id?: string | null;
/** Optional ID of a clicked suggestion. If provided, returns that specific chat */
suggestion_id?: string | null;
/** Optional ID of a message to replace in an existing chat */
message_id?: string;
/** Optional ID of a metric to initialize the chat from */
metric_id?: string;
/** Optional ID of a dashboard to initialize the chat from */
dashboard_id?: string;
}
>;
```
This example demonstrates:
- Proper namespace prefixing (ChatCreateNewChat)
- Comprehensive JSDoc documentation
- Clear type definitions with proper optional/required fields
- Extension of a base interface (BusterSocketRequestBase)
- Strict typing without use of `any`
### {namespace}Responses.ts
- Must contain all response interfaces and types for the namespace
- Each response interface should be prefixed with the namespace
- Must include proper TypeScript types and documentation
- All response callback types must be imported from `@/api/asset_interfaces` directory
- Response types are typically found under the same namespace in the asset_interfaces directory (e.g., chat types in `asset_interfaces/chat`)
- Must define an enum at the top of the file containing all response routes/events
- Must export a union type at the bottom of the file that includes all response types (e.g., `export type ChatResponseTypes = | Type1 | Type2 | Type3`)