mirror of
https://github.com/coder/coder.git
synced 2026-06-04 21:48:22 +00:00
80a172f932
- Moves `coderd/chatd/`, `coderd/gitsync/`, `enterprise/coderd/chatd/` under `x/` parent directories to signal instability - Adds `Experimental:` glue code comments in `coderd/coderd.go` > 🤖 This PR was created with the help of Coder Agents, and was reviewed by my human. 🧑💻
34 lines
658 B
Go
34 lines
658 B
Go
package chattool
|
|
|
|
import (
|
|
"encoding/json"
|
|
"unicode/utf8"
|
|
|
|
"charm.land/fantasy"
|
|
)
|
|
|
|
// toolResponse builds a fantasy.ToolResponse from a JSON-serializable
|
|
// result payload.
|
|
func toolResponse(result map[string]any) fantasy.ToolResponse {
|
|
data, err := json.Marshal(result)
|
|
if err != nil {
|
|
return fantasy.NewTextResponse("{}")
|
|
}
|
|
return fantasy.NewTextResponse(string(data))
|
|
}
|
|
|
|
func truncateRunes(value string, maxLen int) string {
|
|
if maxLen <= 0 || value == "" {
|
|
return ""
|
|
}
|
|
if utf8.RuneCountInString(value) <= maxLen {
|
|
return value
|
|
}
|
|
|
|
runes := []rune(value)
|
|
if maxLen > len(runes) {
|
|
maxLen = len(runes)
|
|
}
|
|
return string(runes[:maxLen])
|
|
}
|