2026-02-28 17:48:33 +08:00
|
|
|
package toolhost
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"context"
|
|
|
|
|
"fmt"
|
|
|
|
|
"time"
|
|
|
|
|
|
|
|
|
|
"laodingbot/internal/config"
|
|
|
|
|
"laodingbot/internal/logger"
|
|
|
|
|
"laodingbot/internal/tools"
|
feat: implement streaming chat, skill routing, and SAFe PI planning tools
- Add /api/chat/stream endpoint with Server-Sent Events (SSE) for real-time message streaming
* Implement StreamEvent types (thought, tool_call, tool_result, final, error)
* Add StreamEventCallback mechanism for event propagation
* Create StreamChatHandler in webui/bot with proper HTTP headers and flushing
- Implement LLM-based skill router for intelligent capability selection
* Add optional routerLLM client for semantic routing
* Implement routeSkillsWithLLM() to match user intent to available skills
* Add matchSkillsByName() for fuzzy skill matching
* Update buildUnifiedSystemPrompt() to use routed skills
- Add streaming support to ReAct pipeline
* Implement runUnifiedReActStream() for streaming thought/action/observation
* Emit StreamEvent at each ReAct step
* Support callback error handling in streaming mode
- Integrate three new DevOps tools
* tools/filedoc: Extract document content from file_id via OpenAI
* tools/giteaticket: Create Gitea issues from PI plan items with SAFe metadata
* tools/piplan: Publish PI planning blueprints with dependency tracking
- Add SAFe PI Planning skill
* Implement PM/SA/RTE (iron triangle) workflow
* Support for Feature, Enabler, and Dependency definition
* Automatic task decomposition and Gitea integration
- Create frontend integration documentation
* Complete SSE protocol specification
* TypeScript fetch + ReadableStream example
* LLM-ready refactoring template for other projects
- Simplify file handling
* Remove legacy file context structures and dual-mode processing
* Consolidate file operations into UploadAndCacheFiles()
* Remove FilePromptMode configuration and related complexity
- Update configuration
* Add Router model support (LLM_ROUTER_MODEL)
* Add Gitea configuration (BaseURL, Token, Owner, Repo)
* WebSearch and additional tool infrastructure
Tests: All 22 test packages passing, 8/8 webui tests including 3 new stream tests
2026-03-11 17:58:19 +08:00
|
|
|
"laodingbot/tools/filedoc"
|
2026-03-05 17:44:19 +08:00
|
|
|
"laodingbot/tools/fileoperation"
|
2026-03-08 22:38:29 +08:00
|
|
|
"laodingbot/tools/git"
|
feat: implement streaming chat, skill routing, and SAFe PI planning tools
- Add /api/chat/stream endpoint with Server-Sent Events (SSE) for real-time message streaming
* Implement StreamEvent types (thought, tool_call, tool_result, final, error)
* Add StreamEventCallback mechanism for event propagation
* Create StreamChatHandler in webui/bot with proper HTTP headers and flushing
- Implement LLM-based skill router for intelligent capability selection
* Add optional routerLLM client for semantic routing
* Implement routeSkillsWithLLM() to match user intent to available skills
* Add matchSkillsByName() for fuzzy skill matching
* Update buildUnifiedSystemPrompt() to use routed skills
- Add streaming support to ReAct pipeline
* Implement runUnifiedReActStream() for streaming thought/action/observation
* Emit StreamEvent at each ReAct step
* Support callback error handling in streaming mode
- Integrate three new DevOps tools
* tools/filedoc: Extract document content from file_id via OpenAI
* tools/giteaticket: Create Gitea issues from PI plan items with SAFe metadata
* tools/piplan: Publish PI planning blueprints with dependency tracking
- Add SAFe PI Planning skill
* Implement PM/SA/RTE (iron triangle) workflow
* Support for Feature, Enabler, and Dependency definition
* Automatic task decomposition and Gitea integration
- Create frontend integration documentation
* Complete SSE protocol specification
* TypeScript fetch + ReadableStream example
* LLM-ready refactoring template for other projects
- Simplify file handling
* Remove legacy file context structures and dual-mode processing
* Consolidate file operations into UploadAndCacheFiles()
* Remove FilePromptMode configuration and related complexity
- Update configuration
* Add Router model support (LLM_ROUTER_MODEL)
* Add Gitea configuration (BaseURL, Token, Owner, Repo)
* WebSearch and additional tool infrastructure
Tests: All 22 test packages passing, 8/8 webui tests including 3 new stream tests
2026-03-11 17:58:19 +08:00
|
|
|
"laodingbot/tools/giteaticket"
|
|
|
|
|
"laodingbot/tools/piplan"
|
2026-03-05 17:44:19 +08:00
|
|
|
"laodingbot/tools/shell"
|
|
|
|
|
"laodingbot/tools/websearch"
|
2026-02-28 17:48:33 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func RunChild(ctx context.Context, cfg config.Config, log *logger.Logger) error {
|
|
|
|
|
var registryLog *logger.Logger
|
|
|
|
|
var fileLog *logger.Logger
|
2026-03-08 22:38:29 +08:00
|
|
|
var gitLog *logger.Logger
|
2026-02-28 17:48:33 +08:00
|
|
|
var shellLog *logger.Logger
|
2026-03-05 17:44:19 +08:00
|
|
|
var searchLog *logger.Logger
|
feat: implement streaming chat, skill routing, and SAFe PI planning tools
- Add /api/chat/stream endpoint with Server-Sent Events (SSE) for real-time message streaming
* Implement StreamEvent types (thought, tool_call, tool_result, final, error)
* Add StreamEventCallback mechanism for event propagation
* Create StreamChatHandler in webui/bot with proper HTTP headers and flushing
- Implement LLM-based skill router for intelligent capability selection
* Add optional routerLLM client for semantic routing
* Implement routeSkillsWithLLM() to match user intent to available skills
* Add matchSkillsByName() for fuzzy skill matching
* Update buildUnifiedSystemPrompt() to use routed skills
- Add streaming support to ReAct pipeline
* Implement runUnifiedReActStream() for streaming thought/action/observation
* Emit StreamEvent at each ReAct step
* Support callback error handling in streaming mode
- Integrate three new DevOps tools
* tools/filedoc: Extract document content from file_id via OpenAI
* tools/giteaticket: Create Gitea issues from PI plan items with SAFe metadata
* tools/piplan: Publish PI planning blueprints with dependency tracking
- Add SAFe PI Planning skill
* Implement PM/SA/RTE (iron triangle) workflow
* Support for Feature, Enabler, and Dependency definition
* Automatic task decomposition and Gitea integration
- Create frontend integration documentation
* Complete SSE protocol specification
* TypeScript fetch + ReadableStream example
* LLM-ready refactoring template for other projects
- Simplify file handling
* Remove legacy file context structures and dual-mode processing
* Consolidate file operations into UploadAndCacheFiles()
* Remove FilePromptMode configuration and related complexity
- Update configuration
* Add Router model support (LLM_ROUTER_MODEL)
* Add Gitea configuration (BaseURL, Token, Owner, Repo)
* WebSearch and additional tool infrastructure
Tests: All 22 test packages passing, 8/8 webui tests including 3 new stream tests
2026-03-11 17:58:19 +08:00
|
|
|
var fileDocLog *logger.Logger
|
|
|
|
|
var piPlanLog *logger.Logger
|
|
|
|
|
var giteaTicketLog *logger.Logger
|
2026-02-28 17:48:33 +08:00
|
|
|
var serverLog *logger.Logger
|
|
|
|
|
if log != nil {
|
|
|
|
|
log.Infof("toolhost child starting")
|
|
|
|
|
registryLog = log.WithComponent("toolhost.registry")
|
|
|
|
|
fileLog = log.WithComponent("toolhost.file")
|
2026-03-08 22:38:29 +08:00
|
|
|
gitLog = log.WithComponent("toolhost.git")
|
2026-02-28 17:48:33 +08:00
|
|
|
shellLog = log.WithComponent("toolhost.shell")
|
2026-03-05 17:44:19 +08:00
|
|
|
searchLog = log.WithComponent("toolhost.websearch")
|
feat: implement streaming chat, skill routing, and SAFe PI planning tools
- Add /api/chat/stream endpoint with Server-Sent Events (SSE) for real-time message streaming
* Implement StreamEvent types (thought, tool_call, tool_result, final, error)
* Add StreamEventCallback mechanism for event propagation
* Create StreamChatHandler in webui/bot with proper HTTP headers and flushing
- Implement LLM-based skill router for intelligent capability selection
* Add optional routerLLM client for semantic routing
* Implement routeSkillsWithLLM() to match user intent to available skills
* Add matchSkillsByName() for fuzzy skill matching
* Update buildUnifiedSystemPrompt() to use routed skills
- Add streaming support to ReAct pipeline
* Implement runUnifiedReActStream() for streaming thought/action/observation
* Emit StreamEvent at each ReAct step
* Support callback error handling in streaming mode
- Integrate three new DevOps tools
* tools/filedoc: Extract document content from file_id via OpenAI
* tools/giteaticket: Create Gitea issues from PI plan items with SAFe metadata
* tools/piplan: Publish PI planning blueprints with dependency tracking
- Add SAFe PI Planning skill
* Implement PM/SA/RTE (iron triangle) workflow
* Support for Feature, Enabler, and Dependency definition
* Automatic task decomposition and Gitea integration
- Create frontend integration documentation
* Complete SSE protocol specification
* TypeScript fetch + ReadableStream example
* LLM-ready refactoring template for other projects
- Simplify file handling
* Remove legacy file context structures and dual-mode processing
* Consolidate file operations into UploadAndCacheFiles()
* Remove FilePromptMode configuration and related complexity
- Update configuration
* Add Router model support (LLM_ROUTER_MODEL)
* Add Gitea configuration (BaseURL, Token, Owner, Repo)
* WebSearch and additional tool infrastructure
Tests: All 22 test packages passing, 8/8 webui tests including 3 new stream tests
2026-03-11 17:58:19 +08:00
|
|
|
fileDocLog = log.WithComponent("toolhost.filedoc")
|
|
|
|
|
piPlanLog = log.WithComponent("toolhost.piplan")
|
|
|
|
|
giteaTicketLog = log.WithComponent("toolhost.giteaticket")
|
2026-02-28 17:48:33 +08:00
|
|
|
serverLog = log.WithComponent("toolhost.server")
|
|
|
|
|
}
|
|
|
|
|
registry := tools.NewRegistry(registryLog)
|
2026-03-05 17:44:19 +08:00
|
|
|
registry.Register(fileoperation.New(cfg.Security.AllowedDirs, cfg.ToolOutputMaxChars, fileLog))
|
2026-03-08 22:38:29 +08:00
|
|
|
registry.Register(git.New(
|
|
|
|
|
cfg.Security.WorkDir,
|
|
|
|
|
time.Duration(cfg.ToolCallTimeoutSec)*time.Second,
|
|
|
|
|
cfg.ToolOutputMaxChars,
|
|
|
|
|
gitLog,
|
|
|
|
|
))
|
2026-03-05 17:44:19 +08:00
|
|
|
registry.Register(shell.New(
|
2026-02-28 17:48:33 +08:00
|
|
|
cfg.Security.AllowedCommands,
|
|
|
|
|
cfg.Security.WorkDir,
|
|
|
|
|
time.Duration(cfg.ToolCallTimeoutSec)*time.Second,
|
|
|
|
|
cfg.ToolOutputMaxChars,
|
|
|
|
|
shellLog,
|
|
|
|
|
))
|
2026-03-05 17:44:19 +08:00
|
|
|
registry.Register(websearch.New(
|
|
|
|
|
websearch.Config{
|
|
|
|
|
Engine: cfg.WebSearch.Engine,
|
|
|
|
|
APIKey: cfg.WebSearch.APIKey,
|
|
|
|
|
},
|
|
|
|
|
cfg.ToolOutputMaxChars,
|
|
|
|
|
searchLog,
|
|
|
|
|
))
|
feat: implement streaming chat, skill routing, and SAFe PI planning tools
- Add /api/chat/stream endpoint with Server-Sent Events (SSE) for real-time message streaming
* Implement StreamEvent types (thought, tool_call, tool_result, final, error)
* Add StreamEventCallback mechanism for event propagation
* Create StreamChatHandler in webui/bot with proper HTTP headers and flushing
- Implement LLM-based skill router for intelligent capability selection
* Add optional routerLLM client for semantic routing
* Implement routeSkillsWithLLM() to match user intent to available skills
* Add matchSkillsByName() for fuzzy skill matching
* Update buildUnifiedSystemPrompt() to use routed skills
- Add streaming support to ReAct pipeline
* Implement runUnifiedReActStream() for streaming thought/action/observation
* Emit StreamEvent at each ReAct step
* Support callback error handling in streaming mode
- Integrate three new DevOps tools
* tools/filedoc: Extract document content from file_id via OpenAI
* tools/giteaticket: Create Gitea issues from PI plan items with SAFe metadata
* tools/piplan: Publish PI planning blueprints with dependency tracking
- Add SAFe PI Planning skill
* Implement PM/SA/RTE (iron triangle) workflow
* Support for Feature, Enabler, and Dependency definition
* Automatic task decomposition and Gitea integration
- Create frontend integration documentation
* Complete SSE protocol specification
* TypeScript fetch + ReadableStream example
* LLM-ready refactoring template for other projects
- Simplify file handling
* Remove legacy file context structures and dual-mode processing
* Consolidate file operations into UploadAndCacheFiles()
* Remove FilePromptMode configuration and related complexity
- Update configuration
* Add Router model support (LLM_ROUTER_MODEL)
* Add Gitea configuration (BaseURL, Token, Owner, Repo)
* WebSearch and additional tool infrastructure
Tests: All 22 test packages passing, 8/8 webui tests including 3 new stream tests
2026-03-11 17:58:19 +08:00
|
|
|
registry.Register(filedoc.New(
|
|
|
|
|
filedoc.Config{
|
|
|
|
|
APIKey: cfg.LLM.APIKey,
|
|
|
|
|
BaseURL: cfg.LLM.BaseURL,
|
|
|
|
|
Model: cfg.LLM.FileModel,
|
|
|
|
|
Timeout: time.Duration(cfg.ToolCallTimeoutSec) * time.Second,
|
|
|
|
|
},
|
|
|
|
|
cfg.ToolOutputMaxChars,
|
|
|
|
|
fileDocLog,
|
|
|
|
|
))
|
|
|
|
|
registry.Register(piplan.New(cfg.ToolOutputMaxChars, piPlanLog))
|
|
|
|
|
registry.Register(giteaticket.New(
|
|
|
|
|
giteaticket.Config{
|
|
|
|
|
BaseURL: cfg.Gitea.BaseURL,
|
|
|
|
|
Token: cfg.Gitea.Token,
|
|
|
|
|
Owner: cfg.Gitea.Owner,
|
|
|
|
|
Repo: cfg.Gitea.Repo,
|
|
|
|
|
Timeout: time.Duration(cfg.ToolCallTimeoutSec) * time.Second,
|
|
|
|
|
},
|
|
|
|
|
giteaTicketLog,
|
|
|
|
|
))
|
2026-02-28 17:48:33 +08:00
|
|
|
|
|
|
|
|
server := NewServer(registry, serverLog)
|
|
|
|
|
if err := server.Serve(ctx, stdin(), stdout()); err != nil && ctx.Err() == nil {
|
|
|
|
|
return fmt.Errorf("toolhost serve failed: %w", err)
|
|
|
|
|
}
|
|
|
|
|
if log != nil {
|
|
|
|
|
log.Infof("toolhost child stopped")
|
|
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|