Documentation
¶
Index ¶
- func DerefStr(s *string, fallback string) string
- func DoRequestWithRetry(client *http.Client, req *http.Request) (*http.Response, error)
- func DownloadFile(url, filename string, opts DownloadOptions) string
- func DownloadFileSimple(url, filename string) string
- func DownloadToFile(ctx context.Context, client *http.Client, req *http.Request, maxBytes int64) (string, error)
- func ExtractZipFile(zipPath string, targetDir string) error
- func IsAudioFile(filename, contentType string) bool
- func SanitizeFilename(filename string) string
- func SanitizeMessageContent(input string) string
- func Truncate(s string, maxLen int) string
- func ValidateSkillIdentifier(identifier string) error
- type DownloadOptions
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DerefStr ¶ added in v0.2.0
DerefStr dereferences a pointer to a string and returns the value or a fallback if the pointer is nil.
func DoRequestWithRetry ¶ added in v0.2.0
func DownloadFile ¶
func DownloadFile(url, filename string, opts DownloadOptions) string
DownloadFile downloads a file from URL to a local temp directory. Returns the local file path or empty string on error.
func DownloadFileSimple ¶
DownloadFileSimple is a simplified version of DownloadFile without options
func DownloadToFile ¶ added in v0.2.0
func DownloadToFile(ctx context.Context, client *http.Client, req *http.Request, maxBytes int64) (string, error)
DownloadToFile streams an HTTP response body to a temporary file in small chunks (~32KB), keeping peak memory usage constant regardless of file size.
Parameters:
- ctx: context for cancellation/timeout
- client: HTTP client to use (caller controls timeouts, transport, etc.)
- req: fully prepared *http.Request (method, URL, headers, etc.)
- maxBytes: maximum bytes to download; 0 means no limit
Returns the path to the temporary file. The caller is responsible for removing it when done (defer os.Remove(path)).
On any error the temp file is cleaned up automatically.
func ExtractZipFile ¶ added in v0.2.0
ExtractZipFile extracts a ZIP archive from disk to targetDir. It reads entries one at a time from disk, keeping memory usage minimal.
Security: rejects path traversal attempts and symlinks.
func IsAudioFile ¶
IsAudioFile checks if a file is an audio file based on its filename extension and content type.
func SanitizeFilename ¶
SanitizeFilename removes potentially dangerous characters from a filename and returns a safe version for local filesystem storage.
func SanitizeMessageContent ¶ added in v0.2.0
SanitizeMessageContent removes Unicode control characters, format characters (RTL overrides, zero-width characters), and other non-graphic characters that could confuse an LLM or cause display issues in the agent UI.
func Truncate ¶
Truncate returns a truncated version of s with at most maxLen runes. Handles multi-byte Unicode characters properly. If the string is truncated, "..." is appended to indicate truncation.
func ValidateSkillIdentifier ¶ added in v0.2.0
ValidateSkillIdentifier validates that the given skill identifier (slug or registry name) is non-empty and does not contain path separators ("/", "\\") or ".." for security.