Files
goclaw/internal/http/summoner_utils.go
T
viettranx e85624ce96 refactor: split large Go files into smaller modules for maintainability
Split 11 Go files exceeding 500 lines into smaller, focused files:
- channels/manager.go → manager.go + dispatch.go + runs.go + events.go
- channels/slack/channel.go → channel.go + send.go + utils.go
- channels/slack/handlers.go → handlers.go + handlers_mention.go + handlers_files.go
- channels/telegram/handlers.go → handlers.go + handlers_utils.go
- channels/zalo/personal/channel.go → channel.go + send.go + listen.go + handlers.go
- gateway/methods/agents.go → agents.go + agents_create.go + agents_update.go + agents_delete.go
- http/summoner.go → summoner.go + summoner_regenerate.go + summoner_prompts.go + summoner_utils.go
- http/skills.go → skills.go + skills_upload.go + skills_versions.go + skills_grants.go
- http/mcp.go → mcp.go + mcp_tools.go + mcp_grants.go + mcp_requests.go
- store/pg/cron.go → cron.go + cron_crud.go + cron_update.go + cron_exec.go

No logic changes — pure file reorganization to keep files under 200 lines.
2026-03-09 10:41:54 +07:00

58 lines
1.4 KiB
Go

package http
import (
"strings"
)
// extractIdentityName extracts the Name field from IDENTITY.md content.
// Matches format: - **Name:** value
func extractIdentityName(content string) string {
if content == "" {
return ""
}
m := identityNameRe.FindStringSubmatch(content)
if len(m) < 2 {
return ""
}
return strings.TrimSpace(m[1])
}
// suffixString returns the last n runes of s.
func suffixString(s string, n int) string {
runes := []rune(s)
if len(runes) <= n {
return s
}
return string(runes[len(runes)-n:])
}
// truncateUTF8 truncates s to at most maxLen runes, appending "…" if truncated.
func truncateUTF8(s string, maxLen int) string {
runes := []rune(s)
if len(runes) <= maxLen {
return s
}
return string(runes[:maxLen]) + "…"
}
// parseFileResponse extracts file contents and frontmatter from XML-tagged LLM output.
// Frontmatter is stored under the special key "__frontmatter__".
func parseFileResponse(content string) map[string]string {
files := make(map[string]string)
matches := fileTagRe.FindAllStringSubmatch(content, -1)
for _, m := range matches {
name := strings.TrimSpace(m[1])
body := strings.TrimSpace(m[2])
if name != "" && body != "" {
files[name] = body
}
}
// Extract frontmatter tag if present
if fm := frontmatterTagRe.FindStringSubmatch(content); len(fm) > 1 {
if trimmed := strings.TrimSpace(fm[1]); trimmed != "" {
files[frontmatterKey] = trimmed
}
}
return files
}