- Updated Stream and Run methods in the Assistant to use pointer receivers for context, enhancing performance and clarity. - Introduced stack management in context handling, including initialization and cleanup of stack references. - Enhanced the Release method in Context to ensure proper cleanup of resources, including stacks and writer references. - Added new stack status constants and validation to improve traceability and error handling in agent operations. - Removed the obsolete JavaScript API file to streamline the codebase.
27 lines
806 B
Go
27 lines
806 B
Go
package trace
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
gonanoid "github.com/matoous/go-nanoid/v2"
|
|
)
|
|
|
|
// GenTraceID generate a new trace ID using NanoID algorithm
|
|
// safe: optional parameter, reserved for future safe mode implementation (collision detection)
|
|
func GenTraceID(safe ...bool) string {
|
|
// TODO: Implement safe mode with collision detection when needed
|
|
// For now, NanoID provides sufficient uniqueness without collision checking
|
|
|
|
// URL-safe alphabet (no ambiguous characters like 0/O, 1/l/I)
|
|
const alphabet = "1234567890"
|
|
const length = 8 // 8 characters provides good balance of uniqueness and readability
|
|
|
|
id, err := gonanoid.Generate(alphabet, length)
|
|
if err != nil {
|
|
// Fallback to timestamp-based ID if NanoID generation fails
|
|
return fmt.Sprintf("%d", time.Now().UnixNano())
|
|
}
|
|
|
|
return id
|
|
}
|