cherry-studio/packages/shared/data/api/schemas/topics.ts
fullex 7faff7ad4b feat(api): implement message branching API with tree structure support
- Add Topic and Message API endpoints for CRUD operations
  - Implement tree visualization queries (GET /topics/:id/tree)
  - Implement branch message queries with pagination (GET /topics/:id/messages)
  - Add multi-model response grouping via siblingsGroupId
  - Support topic forking from existing message nodes
  - Add INVALID_OPERATION error code for business rule violations
  - Update API design guidelines documentation
2025-12-28 12:54:06 +08:00

134 lines
3.1 KiB
TypeScript

/**
* Topic API Schema definitions
*
* Contains all topic-related endpoints for CRUD operations and branch switching.
*/
import type { AssistantMeta } from '@shared/data/types/meta'
import type { Topic } from '@shared/data/types/topic'
// ============================================================================
// DTOs
// ============================================================================
/**
* DTO for creating a new topic
*/
export interface CreateTopicDto {
/** Topic name */
name?: string
/** Associated assistant ID */
assistantId?: string
/** Preserved assistant info */
assistantMeta?: AssistantMeta
/** Topic-specific prompt */
prompt?: string
/** Group ID for organization */
groupId?: string
/**
* Source node ID for fork operation.
* When provided, copies the path from root to this node into the new topic.
*/
sourceNodeId?: string
}
/**
* DTO for updating an existing topic
*/
export interface UpdateTopicDto {
/** Updated topic name */
name?: string
/** Mark name as manually edited */
isNameManuallyEdited?: boolean
/** Updated assistant ID */
assistantId?: string
/** Updated assistant meta */
assistantMeta?: AssistantMeta
/** Updated prompt */
prompt?: string
/** Updated group ID */
groupId?: string
/** Updated sort order */
sortOrder?: number
/** Updated pin state */
isPinned?: boolean
/** Updated pin order */
pinnedOrder?: number
}
/**
* DTO for setting active node
*/
export interface SetActiveNodeDto {
/** Node ID to set as active */
nodeId: string
}
/**
* Response for active node update
*/
export interface ActiveNodeResponse {
/** The new active node ID */
activeNodeId: string
}
// ============================================================================
// API Schema Definitions
// ============================================================================
/**
* Topic API Schema definitions
*/
export interface TopicSchemas {
/**
* Topics collection endpoint
* @example POST /topics { "name": "New Topic", "assistantId": "asst_123" }
*/
'/topics': {
/** Create a new topic (optionally fork from existing node) */
POST: {
body: CreateTopicDto
response: Topic
}
}
/**
* Individual topic endpoint
* @example GET /topics/abc123
* @example PATCH /topics/abc123 { "name": "Updated Name" }
* @example DELETE /topics/abc123
*/
'/topics/:id': {
/** Get a topic by ID */
GET: {
params: { id: string }
response: Topic
}
/** Update a topic */
PATCH: {
params: { id: string }
body: UpdateTopicDto
response: Topic
}
/** Delete a topic and all its messages */
DELETE: {
params: { id: string }
response: void
}
}
/**
* Active node sub-resource endpoint
* High-frequency operation for branch switching
* @example PUT /topics/abc123/active-node { "nodeId": "msg456" }
*/
'/topics/:id/active-node': {
/** Set the active node for a topic */
PUT: {
params: { id: string }
body: SetActiveNodeDto
response: ActiveNodeResponse
}
}
}