// Code generated by go.wit.com/apps/autogenpb DO NOT EDIT. // This file was autogenerated with autogenpb v0.0.79 2025-09-01_01:52:08_UTC // go install go.wit.com/apps/autogenpb@latest // // define which structs (messages) you want to use in the .proto file // Then sort.pb.go and marshal.pb.go files are autogenerated // // autogenpb uses it and has an example .proto file with instructions // package chatpb import ( "fmt" "iter" "sort" "sync" "google.golang.org/protobuf/proto" ) // a simple global lock var chatMu sync.RWMutex func (x *Chats) fixUuid() { if x == nil { return } if x.Uuid == "9fd31f10-c25d-4d66-bc8d-5f6eb7c79057" { return } x.Uuid = "9fd31f10-c25d-4d66-bc8d-5f6eb7c79057" x.Version = "v0.0.1 go.wit.com/lib/protobuf/chatpb" } func NewChats() *Chats { x := new(Chats) x.Uuid = "9fd31f10-c25d-4d66-bc8d-5f6eb7c79057" x.Version = "v0.0.1 go.wit.com/lib/protobuf/chatpb" return x } // START SORT // DEFINE THE Chats SCANNER. // itializes a new scanner. func newChatsScanner(things []*Chats) *ChatsScanner { return &ChatsScanner{things: things} } type ChatsScanner struct { sync.Mutex things []*Chats index int } func (it *ChatsScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *ChatsScanner) Next() *Chats { if it.things[it.index-1] == nil { fmt.Println("Next() error in ChatsScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE Chat SCANNER. // itializes a new scanner. func newChatScanner(things []*Chat) *ChatScanner { return &ChatScanner{things: things} } type ChatScanner struct { sync.Mutex things []*Chat index int } func (it *ChatScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *ChatScanner) Next() *Chat { if it.things[it.index-1] == nil { fmt.Println("Next() error in ChatScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE GeminiRequest SCANNER. // itializes a new scanner. func newGeminiRequestScanner(things []*GeminiRequest) *GeminiRequestScanner { return &GeminiRequestScanner{things: things} } type GeminiRequestScanner struct { sync.Mutex things []*GeminiRequest index int } func (it *GeminiRequestScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *GeminiRequestScanner) Next() *GeminiRequest { if it.things[it.index-1] == nil { fmt.Println("Next() error in GeminiRequestScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE AbortSignal SCANNER. // itializes a new scanner. func newAbortSignalScanner(things []*AbortSignal) *AbortSignalScanner { return &AbortSignalScanner{things: things} } type AbortSignalScanner struct { sync.Mutex things []*AbortSignal index int } func (it *AbortSignalScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *AbortSignalScanner) Next() *AbortSignal { if it.things[it.index-1] == nil { fmt.Println("Next() error in AbortSignalScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE Schema SCANNER. // itializes a new scanner. func newSchemaScanner(things []*Schema) *SchemaScanner { return &SchemaScanner{things: things} } type SchemaScanner struct { sync.Mutex things []*Schema index int } func (it *SchemaScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *SchemaScanner) Next() *Schema { if it.things[it.index-1] == nil { fmt.Println("Next() error in SchemaScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE FunctionDeclaration SCANNER. // itializes a new scanner. func newFunctionDeclarationScanner(things []*FunctionDeclaration) *FunctionDeclarationScanner { return &FunctionDeclarationScanner{things: things} } type FunctionDeclarationScanner struct { sync.Mutex things []*FunctionDeclaration index int } func (it *FunctionDeclarationScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *FunctionDeclarationScanner) Next() *FunctionDeclaration { if it.things[it.index-1] == nil { fmt.Println("Next() error in FunctionDeclarationScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE GoogleSearch SCANNER. // itializes a new scanner. func newGoogleSearchScanner(things []*GoogleSearch) *GoogleSearchScanner { return &GoogleSearchScanner{things: things} } type GoogleSearchScanner struct { sync.Mutex things []*GoogleSearch index int } func (it *GoogleSearchScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *GoogleSearchScanner) Next() *GoogleSearch { if it.things[it.index-1] == nil { fmt.Println("Next() error in GoogleSearchScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE Tool SCANNER. // itializes a new scanner. func newToolScanner(things []*Tool) *ToolScanner { return &ToolScanner{things: things} } type ToolScanner struct { sync.Mutex things []*Tool index int } func (it *ToolScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *ToolScanner) Next() *Tool { if it.things[it.index-1] == nil { fmt.Println("Next() error in ToolScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE Config SCANNER. // itializes a new scanner. func newConfigScanner(things []*Config) *ConfigScanner { return &ConfigScanner{things: things} } type ConfigScanner struct { sync.Mutex things []*Config index int } func (it *ConfigScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *ConfigScanner) Next() *Config { if it.things[it.index-1] == nil { fmt.Println("Next() error in ConfigScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE ResponseJsonSchema SCANNER. // itializes a new scanner. func newResponseJsonSchemaScanner(things []*ResponseJsonSchema) *ResponseJsonSchemaScanner { return &ResponseJsonSchemaScanner{things: things} } type ResponseJsonSchemaScanner struct { sync.Mutex things []*ResponseJsonSchema index int } func (it *ResponseJsonSchemaScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *ResponseJsonSchemaScanner) Next() *ResponseJsonSchema { if it.things[it.index-1] == nil { fmt.Println("Next() error in ResponseJsonSchemaScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE Properties SCANNER. // itializes a new scanner. func newPropertiesScanner(things []*Properties) *PropertiesScanner { return &PropertiesScanner{things: things} } type PropertiesScanner struct { sync.Mutex things []*Properties index int } func (it *PropertiesScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *PropertiesScanner) Next() *Properties { if it.things[it.index-1] == nil { fmt.Println("Next() error in PropertiesScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE Confidence SCANNER. // itializes a new scanner. func newConfidenceScanner(things []*Confidence) *ConfidenceScanner { return &ConfidenceScanner{things: things} } type ConfidenceScanner struct { sync.Mutex things []*Confidence index int } func (it *ConfidenceScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *ConfidenceScanner) Next() *Confidence { if it.things[it.index-1] == nil { fmt.Println("Next() error in ConfidenceScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE CorrectedTargetSnippet SCANNER. // itializes a new scanner. func newCorrectedTargetSnippetScanner(things []*CorrectedTargetSnippet) *CorrectedTargetSnippetScanner { return &CorrectedTargetSnippetScanner{things: things} } type CorrectedTargetSnippetScanner struct { sync.Mutex things []*CorrectedTargetSnippet index int } func (it *CorrectedTargetSnippetScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *CorrectedTargetSnippetScanner) Next() *CorrectedTargetSnippet { if it.things[it.index-1] == nil { fmt.Println("Next() error in CorrectedTargetSnippetScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE CorrectedNewStringEscaping SCANNER. // itializes a new scanner. func newCorrectedNewStringEscapingScanner(things []*CorrectedNewStringEscaping) *CorrectedNewStringEscapingScanner { return &CorrectedNewStringEscapingScanner{things: things} } type CorrectedNewStringEscapingScanner struct { sync.Mutex things []*CorrectedNewStringEscaping index int } func (it *CorrectedNewStringEscapingScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *CorrectedNewStringEscapingScanner) Next() *CorrectedNewStringEscaping { if it.things[it.index-1] == nil { fmt.Println("Next() error in CorrectedNewStringEscapingScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE Reasoning SCANNER. // itializes a new scanner. func newReasoningScanner(things []*Reasoning) *ReasoningScanner { return &ReasoningScanner{things: things} } type ReasoningScanner struct { sync.Mutex things []*Reasoning index int } func (it *ReasoningScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *ReasoningScanner) Next() *Reasoning { if it.things[it.index-1] == nil { fmt.Println("Next() error in ReasoningScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE NextSpeaker SCANNER. // itializes a new scanner. func newNextSpeakerScanner(things []*NextSpeaker) *NextSpeakerScanner { return &NextSpeakerScanner{things: things} } type NextSpeakerScanner struct { sync.Mutex things []*NextSpeaker index int } func (it *NextSpeakerScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *NextSpeakerScanner) Next() *NextSpeaker { if it.things[it.index-1] == nil { fmt.Println("Next() error in NextSpeakerScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE Content SCANNER. // itializes a new scanner. func newContentScanner(things []*Content) *ContentScanner { return &ContentScanner{things: things} } type ContentScanner struct { sync.Mutex things []*Content index int } func (it *ContentScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *ContentScanner) Next() *Content { if it.things[it.index-1] == nil { fmt.Println("Next() error in ContentScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE Part SCANNER. // itializes a new scanner. func newPartScanner(things []*Part) *PartScanner { return &PartScanner{things: things} } type PartScanner struct { sync.Mutex things []*Part index int } func (it *PartScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *PartScanner) Next() *Part { if it.things[it.index-1] == nil { fmt.Println("Next() error in PartScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE FunctionCall SCANNER. // itializes a new scanner. func newFunctionCallScanner(things []*FunctionCall) *FunctionCallScanner { return &FunctionCallScanner{things: things} } type FunctionCallScanner struct { sync.Mutex things []*FunctionCall index int } func (it *FunctionCallScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *FunctionCallScanner) Next() *FunctionCall { if it.things[it.index-1] == nil { fmt.Println("Next() error in FunctionCallScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE ArgsInfo SCANNER. // itializes a new scanner. func newArgsInfoScanner(things []*ArgsInfo) *ArgsInfoScanner { return &ArgsInfoScanner{things: things} } type ArgsInfoScanner struct { sync.Mutex things []*ArgsInfo index int } func (it *ArgsInfoScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *ArgsInfoScanner) Next() *ArgsInfo { if it.things[it.index-1] == nil { fmt.Println("Next() error in ArgsInfoScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE FunctionResponse SCANNER. // itializes a new scanner. func newFunctionResponseScanner(things []*FunctionResponse) *FunctionResponseScanner { return &FunctionResponseScanner{things: things} } type FunctionResponseScanner struct { sync.Mutex things []*FunctionResponse index int } func (it *FunctionResponseScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *FunctionResponseScanner) Next() *FunctionResponse { if it.things[it.index-1] == nil { fmt.Println("Next() error in FunctionResponseScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE Response SCANNER. // itializes a new scanner. func newResponseScanner(things []*Response) *ResponseScanner { return &ResponseScanner{things: things} } type ResponseScanner struct { sync.Mutex things []*Response index int } func (it *ResponseScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *ResponseScanner) Next() *Response { if it.things[it.index-1] == nil { fmt.Println("Next() error in ResponseScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE Row SCANNER. // itializes a new scanner. func newRowScanner(things []*Row) *RowScanner { return &RowScanner{things: things} } type RowScanner struct { sync.Mutex things []*Row index int } func (it *RowScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *RowScanner) Next() *Row { if it.things[it.index-1] == nil { fmt.Println("Next() error in RowScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE Table SCANNER. // itializes a new scanner. func newTableScanner(things []*Table) *TableScanner { return &TableScanner{things: things} } type TableScanner struct { sync.Mutex things []*Table index int } func (it *TableScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *TableScanner) Next() *Table { if it.things[it.index-1] == nil { fmt.Println("Next() error in TableScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE ToolCall SCANNER. // itializes a new scanner. func newToolCallScanner(things []*ToolCall) *ToolCallScanner { return &ToolCallScanner{things: things} } type ToolCallScanner struct { sync.Mutex things []*ToolCall index int } func (it *ToolCallScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *ToolCallScanner) Next() *ToolCall { if it.things[it.index-1] == nil { fmt.Println("Next() error in ToolCallScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE CodeSnippet SCANNER. // itializes a new scanner. func newCodeSnippetScanner(things []*CodeSnippet) *CodeSnippetScanner { return &CodeSnippetScanner{things: things} } type CodeSnippetScanner struct { sync.Mutex things []*CodeSnippet index int } func (it *CodeSnippetScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *CodeSnippetScanner) Next() *CodeSnippet { if it.things[it.index-1] == nil { fmt.Println("Next() error in CodeSnippetScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE ChatEntry SCANNER. // itializes a new scanner. func newChatEntryScanner(things []*ChatEntry) *ChatEntryScanner { return &ChatEntryScanner{things: things} } type ChatEntryScanner struct { sync.Mutex things []*ChatEntry index int } func (it *ChatEntryScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *ChatEntryScanner) Next() *ChatEntry { if it.things[it.index-1] == nil { fmt.Println("Next() error in ChatEntryScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // DEFINE THE SessionStats SCANNER. // itializes a new scanner. func newSessionStatsScanner(things []*SessionStats) *SessionStatsScanner { return &SessionStatsScanner{things: things} } type SessionStatsScanner struct { sync.Mutex things []*SessionStats index int } func (it *SessionStatsScanner) Scan() bool { if it.index >= len(it.things) { return false } it.Lock() it.index++ it.Unlock() return true } // Next() returns the next thing in the array func (it *SessionStatsScanner) Next() *SessionStats { if it.things[it.index-1] == nil { fmt.Println("Next() error in SessionStatsScanner", it.index) } return it.things[it.index-1] } // END DEFINE THE SCANNER // sort struct by Uuid type sortChatUuid []*Chat func (a sortChatUuid) Len() int { return len(a) } func (a sortChatUuid) Less(i, j int) bool { return a[i].Uuid < a[j].Uuid } func (a sortChatUuid) Swap(i, j int) { a[i], a[j] = a[j], a[i] } // safely returns a slice of pointers to the FRUIT protobufs func (x *Chats) allChats() []*Chat { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each FRUIT var tmp []*Chat tmp = make([]*Chat, len(x.Chats)) for i, p := range x.Chats { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the FRUIT protobufs func (x *Chat) allEntries() []*ChatEntry { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each FRUIT var tmp []*ChatEntry tmp = make([]*ChatEntry, len(x.Entries)) for i, p := range x.Entries { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the FRUIT protobufs func (x *Chat) allSession() []*SessionStats { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each FRUIT var tmp []*SessionStats tmp = make([]*SessionStats, len(x.Session)) for i, p := range x.Session { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the FRUIT protobufs func (x *GeminiRequest) allContents() []*Content { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each FRUIT var tmp []*Content tmp = make([]*Content, len(x.Contents)) for i, p := range x.Contents { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the FRUIT protobufs func (x *Tool) allFunctionDeclarations() []*FunctionDeclaration { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each FRUIT var tmp []*FunctionDeclaration tmp = make([]*FunctionDeclaration, len(x.FunctionDeclarations)) for i, p := range x.FunctionDeclarations { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the FRUIT protobufs func (x *Config) allTools() []*Tool { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each FRUIT var tmp []*Tool tmp = make([]*Tool, len(x.Tools)) for i, p := range x.Tools { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the FRUIT protobufs func (x *Content) allParts() []*Part { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each FRUIT var tmp []*Part tmp = make([]*Part, len(x.Parts)) for i, p := range x.Parts { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the FRUIT protobufs func (x *Table) allRows() []*Row { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each FRUIT var tmp []*Row tmp = make([]*Row, len(x.Rows)) for i, p := range x.Rows { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the FRUIT protobufs func (x *ChatEntry) allToolCalls() []*ToolCall { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each FRUIT var tmp []*ToolCall tmp = make([]*ToolCall, len(x.ToolCalls)) for i, p := range x.ToolCalls { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the FRUIT protobufs func (x *ChatEntry) allSnippets() []*CodeSnippet { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each FRUIT var tmp []*CodeSnippet tmp = make([]*CodeSnippet, len(x.Snippets)) for i, p := range x.Snippets { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the FRUIT protobufs func (x *ChatEntry) allParts() []*Part { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each FRUIT var tmp []*Part tmp = make([]*Part, len(x.Parts)) for i, p := range x.Parts { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the Chat protobufs func (x *Chats) selectAllChats() []*Chat { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each Chat var tmp []*Chat tmp = make([]*Chat, len(x.Chats)) for i, p := range x.Chats { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the ChatEntry protobufs func (x *Chat) selectAllEntries() []*ChatEntry { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each ChatEntry var tmp []*ChatEntry tmp = make([]*ChatEntry, len(x.Entries)) for i, p := range x.Entries { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the SessionStats protobufs func (x *Chat) selectAllSession() []*SessionStats { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each SessionStats var tmp []*SessionStats tmp = make([]*SessionStats, len(x.Session)) for i, p := range x.Session { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the Content protobufs func (x *GeminiRequest) selectAllContents() []*Content { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each Content var tmp []*Content tmp = make([]*Content, len(x.Contents)) for i, p := range x.Contents { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the FunctionDeclaration protobufs func (x *Tool) selectAllFunctionDeclarations() []*FunctionDeclaration { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each FunctionDeclaration var tmp []*FunctionDeclaration tmp = make([]*FunctionDeclaration, len(x.FunctionDeclarations)) for i, p := range x.FunctionDeclarations { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the Tool protobufs func (x *Config) selectAllTools() []*Tool { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each Tool var tmp []*Tool tmp = make([]*Tool, len(x.Tools)) for i, p := range x.Tools { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the Part protobufs func (x *Content) selectAllParts() []*Part { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each Part var tmp []*Part tmp = make([]*Part, len(x.Parts)) for i, p := range x.Parts { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the Row protobufs func (x *Table) selectAllRows() []*Row { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each Row var tmp []*Row tmp = make([]*Row, len(x.Rows)) for i, p := range x.Rows { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the ToolCall protobufs func (x *ChatEntry) selectAllToolCalls() []*ToolCall { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each ToolCall var tmp []*ToolCall tmp = make([]*ToolCall, len(x.ToolCalls)) for i, p := range x.ToolCalls { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the CodeSnippet protobufs func (x *ChatEntry) selectAllSnippets() []*CodeSnippet { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each CodeSnippet var tmp []*CodeSnippet tmp = make([]*CodeSnippet, len(x.Snippets)) for i, p := range x.Snippets { tmp[i] = p // Copy pointers for safe iteration } return tmp } // safely returns a slice of pointers to the Part protobufs func (x *ChatEntry) selectAllParts() []*Part { x.RLock() defer x.RUnlock() // Create a new slice to hold pointers to each Part var tmp []*Part tmp = make([]*Part, len(x.Parts)) for i, p := range x.Parts { tmp[i] = p // Copy pointers for safe iteration } return tmp } func (x *Chats) SortByUuid() *ChatScanner { // copy the pointers as fast as possible. things := x.selectAllChats() // todo: try slices.SortFunc() instead to see what happens sort.Sort(sortChatUuid(things)) // slices.SortFunc(things, func(a, b *Chats) bool { // return a.Uuid < b.Uuid // Sort by ??. let the compiler work it out?? // }) return newChatScanner(things) } // 'for x := range' syntax using the awesome golang 1.24 'iter' func (x *Chats) IterByUuid() iter.Seq[*Chat] { items := x.selectAllChats() sort.Sort(sortChatUuid(items)) // log.Println("Made Iter.Seq[] with length", len(items)) return func(yield func(*Chat) bool) { for _, v := range items { if !yield(v) { return } } } } // END SORT func (x *Chats) Len() int { x.RLock() defer x.RUnlock() return len(x.Chats) } // a Append() shortcut (that does Clone() with a mutex) notsure if it really works func (x *Chats) Append(y *Chat) { x.Lock() defer x.Unlock() x.Chats = append(x.Chats, proto.Clone(y).(*Chat)) } func (x *Chats) All() *ChatScanner { ChatPointers := x.selectAllChats() scanner := newChatScanner(ChatPointers) return scanner } // Iterate 'for x := range' syntax using the awesome golang 1.24 'iter' func (x *Chats) IterAll() iter.Seq[*Chat] { items := x.selectAllChats() // log.Println("Made All() Iter.Seq[] with length", len(items)) return func(yield func(*Chat) bool) { for _, v := range items { if !yield(v) { return } } } } func (x *Chats) Delete(y *Chat) bool { x.Lock() defer x.Unlock() for i, _ := range x.Chats { if x.Chats[i] == y { x.Chats[i] = x.Chats[len(x.Chats)-1] x.Chats = x.Chats[:len(x.Chats)-1] return true } } return false } // lookup a Chats by the Uuid func (x *Chats) FindByUuid(s string) *Chat { if x == nil { return nil } x.RLock() defer x.RUnlock() for i, _ := range x.Chats { if x.Chats[i].Uuid == s { return x.Chats[i] } } return nil } // returns a Chat if Uuid matches, otherwise create func (x *Chats) InsertByUuid(y string) *Chat { x.Lock() defer x.Unlock() for _, z := range x.Chats { if z.Uuid == y { return z } } z := new(Chat) z.Uuid = y x.Chats = append(x.Chats, z) return z } func (x *Chats) DeleteByUuid(s string) bool { x.Lock() defer x.Unlock() for i, _ := range x.Chats { if x.Chats[i].Uuid == s { x.Chats[i] = x.Chats[len(x.Chats)-1] x.Chats = x.Chats[:len(x.Chats)-1] return true } } return false } func (x *Chats) AppendByUuid(y *Chat) bool { x.Lock() defer x.Unlock() for _, p := range x.Chats { if p.Uuid == y.Uuid { return false } } x.Chats = append(x.Chats, proto.Clone(y).(*Chat)) return true }