Files
agent/backend/internal/logic/projects/dto.go

163 lines
5.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package projects
import (
"time"
"senlinai-agent/backend/internal/models"
)
// ProjectDTO 是项目 API 的稳定响应ID 使用公开 identity避免泄漏数据库自增主键。
type ProjectDTO struct {
ID string `json:"id"`
Name string `json:"name"`
Identifier string `json:"identifier"`
Icon string `json:"icon"`
Background string `json:"background"`
Description string `json:"description"`
}
// CreateProjectRequest 描述创建项目时允许客户端写入的字段。
type CreateProjectRequest struct {
Name string `json:"name"`
Identifier string `json:"identifier"`
Icon string `json:"icon"`
Background string `json:"background"`
Description string `json:"description"`
}
// UpdateProjectRequest 使用指针区分“未提供”和“显式清空”,且只开放项目设置字段。
type UpdateProjectRequest struct {
Name *string `json:"name"`
Identifier *string `json:"identifier"`
Icon *string `json:"icon"`
Background *string `json:"background"`
Description *string `json:"description"`
}
type CreateCronPlanInput struct {
Title string
Schedule string
Enabled bool
NextRunAt *time.Time
}
type CreateProjectChannelInput struct {
Title string `json:"title"`
Icon string `json:"icon"`
URL string `json:"url"`
}
// WorkspaceDTO 是项目工作区首屏聚合响应,所有数据库对象均以公开 identity 关联。
type WorkspaceDTO struct {
Project WorkspaceProjectDTO `json:"project"`
Channels []WorkspaceChannelDTO `json:"channels"`
Tags []WorkspaceTagDTO `json:"tags"`
RecentSessions []WorkspaceAISessionDTO `json:"recentSessions"`
Inbox []WorkspaceInboxDTO `json:"inbox"`
Tasks []WorkspaceTaskDTO `json:"tasks"`
AISessions []WorkspaceAISessionDTO `json:"aiSessions"`
Documents []WorkspaceDocumentDTO `json:"documents"`
CronPlans []WorkspaceCronPlanDTO `json:"cronPlans"`
}
// WorkspaceProjectDTO 补充工作区导航所需的项目摘要和未读计数。
type WorkspaceProjectDTO struct {
ID string `json:"id"`
Name string `json:"name"`
Identifier string `json:"identifier"`
Icon string `json:"icon"`
Background string `json:"background"`
Description string `json:"description"`
Initials string `json:"initials"`
UnreadCount int64 `json:"unreadCount"`
}
// WorkspaceChannelDTO 描述系统频道或项目内自定义链接频道。
type WorkspaceChannelDTO struct {
ID string `json:"id"`
ProjectID string `json:"projectId"`
Type string `json:"type"`
Title string `json:"title"`
Icon string `json:"icon"`
Count int64 `json:"count"`
URL string `json:"url"`
SortOrder int `json:"sortOrder"`
}
// WorkspaceTagDTO 是项目范围内的真实标签,不包含仅用于展示的虚拟标签。
type WorkspaceTagDTO struct {
ID string `json:"id"`
Name string `json:"name"`
}
// WorkspaceInboxDTO 是工作区 Inbox 行Time 保留 UTC 时间语义供前端格式化。
type WorkspaceInboxDTO struct {
ID string `json:"id"`
ProjectID string `json:"projectId"`
Source string `json:"source"`
Title string `json:"title"`
Summary string `json:"summary"`
Status string `json:"status"`
Tag string `json:"tag"`
Time time.Time `json:"time"`
}
// WorkspaceTaskDTO 是工作区任务响应,标签和项目关联均使用 identity。
type WorkspaceTaskDTO struct {
ID string `json:"id"`
ProjectID string `json:"projectId"`
Title string `json:"title"`
Summary string `json:"summary"`
Completed bool `json:"completed"`
Owner string `json:"owner"`
Due *time.Time `json:"due"`
CreatedAt time.Time `json:"createdAt"`
CompletedAt *time.Time `json:"completedAt"`
TagID *string `json:"tagId"`
Tag string `json:"tag"`
}
// WorkspaceAISessionDTO 是工作区 AI 会话摘要。
type WorkspaceAISessionDTO struct {
ID string `json:"id"`
ProjectID string `json:"projectId"`
Title string `json:"title"`
Summary string `json:"summary"`
UpdatedAt time.Time `json:"updatedAt"`
References []string `json:"references"`
}
// WorkspaceDocumentDTO is the recent document summary used by the workspace.
type WorkspaceDocumentDTO struct {
ID string `json:"id"`
ProjectID string `json:"projectId"`
Kind string `json:"kind"`
Name string `json:"name"`
Extension string `json:"extension"`
MimeType string `json:"mimeType"`
UpdatedAt time.Time `json:"updatedAt"`
}
// WorkspaceCronPlanDTO 是只展示元数据、不执行自主 Agent 的计划任务摘要。
type WorkspaceCronPlanDTO struct {
ID string `json:"id"`
ProjectID string `json:"projectId"`
Title string `json:"title"`
Schedule string `json:"schedule"`
NextRun *time.Time `json:"nextRun"`
Enabled bool `json:"enabled"`
LastResult string `json:"lastResult"`
Owner string `json:"owner"`
}
func projectDTO(project models.SaProject) ProjectDTO {
return ProjectDTO{
ID: project.Identity,
Name: project.Name,
Identifier: project.Identifier,
Icon: project.Icon,
Background: project.Background,
Description: project.Description,
}
}