refactor(tools): extract shared logic for internal channels and tool definitions

- Add constants package with IsInternalChannel helper to centralize internal channel checks across agent, channels, and heartbeat services
- Add ToProviderDefs method to ToolRegistry to consolidate tool definition conversion logic used in agent loop and tool loop
- Refactor SubagentTool.Execute to use RunToolLoop for consistent tool execution with iteration tracking
- Remove duplicate inline map definitions and type assertion code throughout codebase
This commit is contained in:
yinwm
2026-02-13 15:05:16 +08:00
parent 0cce9fc905
commit 8851152cbd
7 changed files with 86 additions and 51 deletions

View File

@@ -13,6 +13,7 @@ import (
"github.com/sipeed/picoclaw/pkg/bus"
"github.com/sipeed/picoclaw/pkg/config"
"github.com/sipeed/picoclaw/pkg/constants"
"github.com/sipeed/picoclaw/pkg/logger"
)
@@ -218,9 +219,6 @@ func (m *Manager) StopAll(ctx context.Context) error {
func (m *Manager) dispatchOutbound(ctx context.Context) {
logger.InfoC("channels", "Outbound dispatcher started")
// Internal channels that don't have actual handlers
internalChannels := map[string]bool{"cli": true, "system": true, "subagent": true}
for {
select {
case <-ctx.Done():
@@ -233,7 +231,7 @@ func (m *Manager) dispatchOutbound(ctx context.Context) {
}
// Silently skip internal channels
if internalChannels[msg.Channel] {
if constants.IsInternalChannel(msg.Channel) {
continue
}