33 lines
1.3 KiB
Go
33 lines
1.3 KiB
Go
package workflow
|
||
|
||
import (
|
||
"ai_scheduler/internal/config"
|
||
"ai_scheduler/internal/domain/component"
|
||
"ai_scheduler/internal/domain/repo"
|
||
"ai_scheduler/internal/domain/workflow/runtime"
|
||
"ai_scheduler/internal/pkg/utils_ollama"
|
||
|
||
toolManager "ai_scheduler/internal/domain/tools"
|
||
|
||
"github.com/google/wire"
|
||
)
|
||
|
||
var ProviderSetWorkflow = wire.NewSet(NewRegistry)
|
||
|
||
// NewRegistry 注入共享依赖并注册默认 Registry,确保自注册工作流可被发现
|
||
func NewRegistry(conf *config.Config, llm *utils_ollama.Client, repos *repo.Repos, components *component.Components) *runtime.Registry {
|
||
// 步骤1:设置运行时依赖(配置与LLM客户端),供工作流工厂在首次实例化时使用;必须在任何调用 Invoke 之前完成,否则会触发 "deps not set"
|
||
runtime.SetDeps(&runtime.Deps{
|
||
Conf: conf,
|
||
LLM: llm,
|
||
ToolManager: toolManager.NewManager(conf),
|
||
Repos: repos,
|
||
Component: components,
|
||
})
|
||
// 步骤2:创建新的工作流注册表;注册表负责按工作流ID惰性实例化并缓存单例实例,保障并发访问下的安全
|
||
r := runtime.NewRegistry()
|
||
// 步骤3:将该注册表设置为全局默认,便于通过 runtime.Default() 获取;自注册的工作流可通过默认注册表被发现并调用
|
||
runtime.SetDefault(r)
|
||
return r
|
||
}
|