Appearance
模块:Shared Types
唯一职责:定义跨包共享的 TypeScript 类型和常量,作为
@stormflow/shared包发布。
边界
属于本模块:
- 节点相关类型(
NodeType、NodeStatus、节点数据接口、CanvasNode) - 画布类型(
Canvas、Viewport) - 边类型(
CanvasEdge) - 模型类型(
ModelModality、AiModelInfo、AiModel) - 缩放常量(
ZOOM_MIN、ZOOM_MAX、ZOOM_STEP)
不属于本模块:
- 运行时逻辑(纯类型和常量,无运行时代码)
- 组件 Props / Emits 类型(定义在各组件内部)
- API 请求/响应类型(定义在
services/内部)
导出清单
node.ts
typescript
type NodeType = 'text' | 'image' | 'video'
type NodeStatus = 'idle' | 'generating' | 'done' | 'error'
type ContentOrigin = 'empty' | 'uploaded' | 'generated' // M6 已实现
interface TextNodeData {
title: string
content: string
prompt: string
model: string
variations: 1 | 2 | 4
status: NodeStatus
result?: string
}
interface ImageNodeData {
title: string
imageUrl?: string
prompt: string
model: string
variations: 1 | 2 | 4
status: NodeStatus
origin: ContentOrigin // M6 已实现
results?: string[]
aspectRatio?: string
imageSize?: string
}
interface VideoNodeData {
title: string
videoUrl?: string
duration?: number
prompt: string
model: string
status: NodeStatus
origin: ContentOrigin // M6 已实现
result?: string
}
interface BaseNode<T> { id: string, type: NodeType, position: { x: number, y: number }, data: T }
type CanvasNode = TextNode | ImageNode | VideoNodecanvas.ts
typescript
interface Canvas { id: string, name: string, nodes: CanvasNode[], edges: CanvasEdge[], viewport: Viewport, createdAt: string, updatedAt: string }
interface Viewport { x: number, y: number, zoom: number }
const ZOOM_MIN = 0.3
const ZOOM_MAX = 2.0
const ZOOM_STEP = 0.1edge.ts
typescript
interface CanvasEdge { id: string, source: string, target: string, sourceHandle?: string, targetHandle?: string }model.ts
typescript
type ModelModality = 'text' | 'image' | 'video' | 'audio'
interface AiModelInfo { readonly name: string, readonly provider: string, readonly inputPrice: number, readonly outputPrice: number, readonly modalities: ModelModality[], readonly enabled: boolean }
interface AiModel { readonly id: string, readonly label: string }不变量
- 所有类型为
interface或type,不含运行时逻辑(常量除外) - 所有导出通过
index.ts统一 re-export - 被
apps/web和将来的其他 apps 共同依赖
错误场景
纯类型和常量模块,无运行时逻辑,不产生错误场景。类型误用由 TypeScript 编译期检查捕获。
实现位置
| 角色 | 文件路径 |
|---|---|
| 入口 | packages/shared/src/index.ts |
| 节点类型 | packages/shared/src/node.ts |
| 画布类型 | packages/shared/src/canvas.ts |
| 边类型 | packages/shared/src/edge.ts |
| 模型类型 | packages/shared/src/model.ts |