service

package
v0.0.0-...-ca21e7b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 16, 2025 License: Apache-2.0 Imports: 37 Imported by: 0

Documentation

Overview

* @Date: 2025-01-27 * @LastEditors: AI Assistant * @FilePath: /thinking-map/server/internal/service/context_manager.go

* @Date: 2025-01-27 * @LastEditors: AI Assistant * @FilePath: /thinking-map/server/internal/service/dependency_checker.go

* @Date: 2025-06-22 14:56:38 * @LastEditors: peng pgs1108pgs@gmail.com * @LastEditTime: 2025-06-22 15:09:02 * @FilePath: /thinking-map/server/internal/service/test_utils.go

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CleanupTestEnvironment

func CleanupTestEnvironment(testConfig *TestConfig)

CleanupTestEnvironment 清理测试环境

func InitTestDatabase

func InitTestDatabase(cfg *config.Config) (*gorm.DB, error)

InitTestDatabase 初始化测试数据库

func InitTestRedis

func InitTestRedis(cfg *config.Config) (*redis.Client, error)

InitTestRedis 初始化测试Redis

func LoadTestConfig

func LoadTestConfig() (*config.Config, error)

LoadTestConfig 加载测试配置

Types

type AuthService

type AuthService interface {
	Register(ctx context.Context, req *dto.RegisterRequest) (*dto.AuthData, error)
	Login(ctx context.Context, req *dto.LoginRequest) (*dto.AuthData, error)
	RefreshToken(ctx context.Context, refreshToken string) (*dto.AuthData, error)
	Logout(ctx context.Context, accessToken string, refreshToken string) error
	ValidateToken(ctx context.Context, token string) (*model.TokenInfo, error)
}

AuthService defines the interface for authentication operations

func NewAuthService

func NewAuthService(db *gorm.DB, redis *redis.Client, jwtConfig JWTConfig) AuthService

NewAuthService creates a new instance of AuthService

type ConclusionService

type ConclusionService struct {
	// contains filtered or unexported fields
}

func NewConclusionV3Service

func NewConclusionV3Service(contextManager *ContextManager, nodeRepo repository.ThinkingNode) *ConclusionService

func (*ConclusionService) Conclusion

func (c *ConclusionService) Conclusion(ctx *gin.Context, req dto.ConclusionRequest) error

func (*ConclusionService) Generate

func (c *ConclusionService) Generate(ctx *gin.Context, contextInfo *ContextInfo, messages []*schema.Message) error

func (ConclusionService) Optimize

func (c ConclusionService) Optimize(ctx *gin.Context, messages []*schema.Message) error

func (*ConclusionService) ResetConclusion

func (c *ConclusionService) ResetConclusion(ctx *gin.Context, nodeID string) error

ResetConclusion 重置结论

func (*ConclusionService) SaveConclusion

func (c *ConclusionService) SaveConclusion(ctx *gin.Context, nodeID string, req dto.SaveConclusionRequest) error

SaveConclusion 保存结论

type ContextInfo

type ContextInfo struct {
	MapInfo             *model.ThinkingMap     `json:"mapInfo"`
	NodeInfo            *model.ThinkingNode    `json:"nodeInfo"`
	AncestorsContext    []NodeContextInfo      `json:"ancestorsContext,omitempty"`
	DependencyContext   []NodeContextInfo      `json:"dependencyContext,omitempty"`
	ChildrenContext     []NodeContextInfo      `json:"childrenContext,omitempty"`
	ConversationContext []ConversationMessage  `json:"conversationContext,omitempty"`
	UserContext         map[string]interface{} `json:"userContext,omitempty"`
}

ContextInfo 节点完整上下文信息

type ContextManager

type ContextManager struct {
	// contains filtered or unexported fields
}

ContextManager 上下文管理器 职责:通过工程化方式管理思考导图的上下文信息,基于导图结构自动收集相关上下文

func NewContextManager

func NewContextManager(nodeRepo repository.ThinkingNode, mapRepo repository.ThinkingMap, messageRepo repository.Message) *ContextManager

NewContextManager 创建新的上下文管理器实例

func (*ContextManager) FormatContextForAgent

func (cm *ContextManager) FormatContextForAgent(contextInfo *ContextInfo) string

FormatContextForAgent 格式化上下文信息供Agent使用

func (*ContextManager) GetContextInfo

func (cm *ContextManager) GetContextInfo(ctx context.Context, nodeID string) (*ContextInfo, error)

GetContextInfo 获取节点的完整上下文

func (*ContextManager) GetNodeContextWithConversation

func (cm *ContextManager) GetNodeContextWithConversation(ctx context.Context, nodeID string, parentMsgID string) (*ContextInfo, error)

GetNodeContextWithConversation 获取包含对话历史的节点完整上下文

func (*ContextManager) RefreshNodeContext

func (cm *ContextManager) RefreshNodeContext(ctx *gin.Context, nodeID string) (*dto.NodeResponse, error)

RefreshNodeContext 刷新节点上下文(重新计算所有上下文信息)

func (*ContextManager) UpdateNodeDependencies

func (cm *ContextManager) UpdateNodeDependencies(ctx context.Context, nodeID string, dependencies []string) error

UpdateNodeDependencies 更新节点依赖关系

type ConversationMessage

type ConversationMessage struct {
	MessageID string    `json:"messageID"`
	ParentID  string    `json:"parentID"`
	Role      string    `json:"role"`
	Content   string    `json:"content"`
	Timestamp time.Time `json:"timestamp"`
}

ConversationMessage 对话消息

type DecompositionService

type DecompositionService struct {
	// contains filtered or unexported fields
}

DecompositionService handles intent recognition business logic

func NewDecompositionService

func NewDecompositionService(contextManager *ContextManager, nodeRepo repository.ThinkingNode) *DecompositionService

NewDecompositionService creates a new intent service

func (*DecompositionService) Analyze

func (s *DecompositionService) Analyze(ctx *gin.Context, contextInfo *ContextInfo, messages []*schema.Message) (err error)

Analyze performs intent analysis for a given node

func (*DecompositionService) Decompose

func (s *DecompositionService) Decompose(ctx *gin.Context, contextInfo *ContextInfo, messages []*schema.Message) (err error)

Decompose 拆解节点

func (*DecompositionService) Decomposition

func (s *DecompositionService) Decomposition(ctx *gin.Context, req dto.DecompositionRequest) (err error)

func (*DecompositionService) ResetDecomposition

func (s *DecompositionService) ResetDecomposition(ctx context.Context, nodeID string) error

ResetDecomposition resets the decomposition of a node.

type DependencyChecker

type DependencyChecker struct {
	// contains filtered or unexported fields
}

DependencyChecker 依赖检查器 职责:通过工程化方式检查节点的依赖关系,确保执行顺序的正确性

func NewDependencyChecker

func NewDependencyChecker(nodeRepo repository.ThinkingNode) *DependencyChecker

NewDependencyChecker 创建新的依赖检查器实例

func (*DependencyChecker) CheckExecutionReadiness

func (dc *DependencyChecker) CheckExecutionReadiness(ctx context.Context, nodeID string) (*ExecutionReadinessResult, error)

CheckExecutionReadiness 检查节点是否可以执行

func (*DependencyChecker) GetBlockedNodes

func (dc *DependencyChecker) GetBlockedNodes(ctx context.Context, nodeID string) ([]string, error)

GetBlockedNodes 获取被指定节点阻塞的所有节点

func (*DependencyChecker) GetDependencyChain

func (dc *DependencyChecker) GetDependencyChain(ctx context.Context, nodeID string) ([]string, error)

GetDependencyChain 获取节点的完整依赖链

func (*DependencyChecker) GetExecutionOrder

func (dc *DependencyChecker) GetExecutionOrder(ctx context.Context, nodeIDs []string) ([]string, error)

GetExecutionOrder 获取节点的执行顺序(拓扑排序)

func (*DependencyChecker) ValidateDependencyCycle

func (dc *DependencyChecker) ValidateDependencyCycle(ctx context.Context, fromNodeID, toNodeID string) (bool, error)

ValidateDependencyCycle 检查是否会产生循环依赖

type ExecutionReadinessResult

type ExecutionReadinessResult struct {
	Ready   bool   `json:"ready"`
	Message string `json:"message"`
}

ExecutionReadinessResult 执行就绪检查结果

type JWTConfig

type JWTConfig struct {
	SecretKey       string
	AccessTokenTTL  time.Duration
	RefreshTokenTTL time.Duration
	TokenIssuer     string
}

JWTConfig holds the JWT configuration

type MapService

type MapService struct {
	// contains filtered or unexported fields
}

func NewMapService

func NewMapService(mapRepo repository.ThinkingMap) *MapService

func (*MapService) CreateMap

func (s *MapService) CreateMap(ctx context.Context, req dto.CreateMapRequest, userID string) (*dto.MapResponse, error)

CreateMap creates a new thinking map

func (*MapService) DeleteMap

func (s *MapService) DeleteMap(ctx context.Context, mapID string, userID string) error

DeleteMap deletes a thinking map

func (*MapService) GetMap

func (s *MapService) GetMap(ctx context.Context, mapID string) (*dto.MapResponse, error)

GetMap retrieves a specific thinking map

func (*MapService) ListMaps

func (s *MapService) ListMaps(ctx context.Context, query dto.MapListQuery, userID string) (*dto.MapListResponse, error)

ListMaps retrieves a list of thinking maps

func (*MapService) UpdateMap

func (s *MapService) UpdateMap(ctx context.Context, mapID string, req dto.UpdateMapRequest, userID string) (*dto.MapResponse, error)

UpdateMap updates a thinking map

type NodeContextInfo

type NodeContextInfo struct {
	NodeID     string `json:"nodeID"`
	Question   string `json:"question"`
	Target     string `json:"target"`
	Conclusion string `json:"conclusion,omitempty"`
	Status     string `json:"status"`
}

NodeContextInfo 节点上下文信息

type NodeService

type NodeService struct {
	// contains filtered or unexported fields
}

func NewNodeService

func NewNodeService(nodeRepo repository.ThinkingNode, mapRepo repository.ThinkingMap) *NodeService

func (*NodeService) CreateNode

func (s *NodeService) CreateNode(ctx context.Context, mapID string, req dto.CreateNodeRequest) (*dto.NodeResponse, error)

CreateNode 创建节点

func (*NodeService) DeleteNode

func (s *NodeService) DeleteNode(ctx context.Context, nodeID string) error

DeleteNode 删除节点

func (*NodeService) ExecutableNodes

func (s *NodeService) ExecutableNodes(ctx context.Context, mapID, nodeID string) (*dto.ExecutableNodesResponse, error)

ExecutableNodes 获取下一个可执行节点

func (*NodeService) GetNode

func (s *NodeService) GetNode(ctx context.Context, nodeID string) (*dto.NodeResponse, error)

func (*NodeService) GetNodeContext

func (s *NodeService) GetNodeContext(ctx *gin.Context, node *model.ThinkingNode) model.DependentContext

func (*NodeService) ListNodes

func (s *NodeService) ListNodes(ctx *gin.Context, mapID string) ([]dto.NodeResponse, error)

ListNodes 获取某个map下的所有节点

func (*NodeService) ResetNodeContext

func (s *NodeService) ResetNodeContext(ctx *gin.Context, nodeID string) (*dto.NodeResponse, error)

ResetNodeContext 重置上下文

func (*NodeService) UpdateNode

func (s *NodeService) UpdateNode(ctx context.Context, nodeID string, req dto.UpdateNodeRequest) (*dto.NodeResponse, error)

UpdateNode 更新节点

func (*NodeService) UpdateNodeContext

func (s *NodeService) UpdateNodeContext(ctx *gin.Context, nodeID string, req dto.UpdateNodeContextRequest) (*dto.NodeResponse, error)

UpdateNodeContext 更新节点上下文

type TestConfig

type TestConfig struct {
	DB    *gorm.DB
	Redis *redis.Client
}

TestConfig 测试配置结构体

func SetupTestEnvironment

func SetupTestEnvironment() (*TestConfig, error)

SetupTestEnvironment 设置测试环境

type UnderstandingService

type UnderstandingService struct {
	// contains filtered or unexported fields
}

func NewUnderstandingService

func NewUnderstandingService(messageRepo repository.Message, nodeRepo repository.ThinkingNode) *UnderstandingService

func (*UnderstandingService) Understanding

func (s *UnderstandingService) Understanding(ctx *gin.Context, req dto.UnderstandingRequest) (lastMsgID, event string, sr *schema.StreamReader[*schema.Message], err error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL