Files
ai-agent/internal/ai/skills/service.go
T
mlogclub 5d7c10aeab refactor: rename agent widget references to AI agent for consistency
- Updated runtime configuration to use __CS_AI_AGENT_WIDGET_CONFIG__ instead of __CS_AGENT_WIDGET_CONFIG__.
- Changed message types in support host bridge from "cs-agent" to "cs-ai-agent".
- Minified SDK script updated to reflect new AI agent naming conventions.
- Adjusted scrollbar styles in main.scss to use .cs-ai-agent-scrollbar instead of .cs-agent-scrollbar.
2026-05-30 21:19:36 +08:00

73 lines
1.7 KiB
Go

package skills
import (
"context"
"strings"
"cs-ai-agent/internal/models"
)
var RuntimeService = newService()
func newService() *Service {
return &Service{
plan: newPlanService(),
runlog: newRunLogService(),
}
}
type Service struct {
plan *planService
runlog *RunLogService
}
// BuildExecutionPlan 构建当前请求的 Skill 执行计划。
func (s *Service) BuildExecutionPlan(execCtx context.Context, ctx RuntimeContext) (*ExecutionPlan, error) {
return s.plan.BuildExecutionPlan(execCtx, ctx)
}
// WriteRunLog 写入 Skill 路由日志。
func (s *Service) WriteRunLog(log *models.SkillRunLog) error {
return s.runlog.Write(log)
}
// Select 执行一次 Skill 路由并记录路由日志。
func (s *Service) Select(ctx context.Context, runtimeCtx RuntimeContext) (*ExecutionResult, error) {
plan, err := s.BuildExecutionPlan(ctx, runtimeCtx)
if err != nil {
trace := &ExecutionTrace{Status: "route_error"}
log := s.runlog.Build(runtimeCtx, nil, trace, err)
_ = s.WriteRunLog(log)
return nil, err
}
trace := &ExecutionTrace{Status: "ok"}
if plan == nil || plan.Skill == nil {
if plan != nil {
trace.Status = "not_matched"
trace.MatchReason = strings.TrimSpace(plan.MatchReason)
trace.Route = plan.RouteTrace
}
log := s.runlog.Build(runtimeCtx, plan, trace, nil)
_ = s.WriteRunLog(log)
return &ExecutionResult{
Plan: plan,
RunLog: log,
Trace: trace,
}, nil
}
trace.MatchReason = strings.TrimSpace(plan.MatchReason)
trace.Route = plan.RouteTrace
log := s.runlog.Build(runtimeCtx, plan, trace, err)
if writeErr := s.WriteRunLog(log); writeErr != nil && err == nil {
err = writeErr
}
if err != nil {
return nil, err
}
return &ExecutionResult{
Plan: plan,
RunLog: log,
Trace: trace,
}, nil
}