conversation

package
v6.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2025 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MetadataMessagesKey = "gemini_web_messages"
	MetadataMatchKey    = "gemini_web_match"
)

Variables

This section is empty.

Functions

func AliasFromModelID

func AliasFromModelID(modelID string) string

AliasFromModelID mirrors the original helper for deriving alias IDs.

func EnsureGeminiWebAliasMap

func EnsureGeminiWebAliasMap()

EnsureGeminiWebAliasMap populates the alias map once.

func EqualMessages

func EqualMessages(a, b []Message) bool

EqualMessages compares two message slices for equality.

func GetGeminiWebAliasedModels

func GetGeminiWebAliasedModels() []*registry.ModelInfo

GetGeminiWebAliasedModels returns alias metadata for registry exposure.

func HashConversationForAccount

func HashConversationForAccount(clientID, model string, msgs []StoredMessage) string

HashConversationForAccount keeps compatibility with the per-account hash previously used.

func HashConversationGlobal

func HashConversationGlobal(model string, msgs []StoredMessage) string

HashConversationGlobal produces a hash suitable for cross-account lookups.

func HashConversationWithPrefix

func HashConversationWithPrefix(prefix, model string, msgs []StoredMessage) string

HashConversationWithPrefix computes a conversation hash using the provided prefix (client identifier) and model.

func MapAliasToUnderlying

func MapAliasToUnderlying(name string) string

MapAliasToUnderlying normalizes a model alias to its underlying identifier.

func NormalizeModel

func NormalizeModel(model string) string

NormalizeModel returns the canonical identifier used for hashing.

func RemoveMatch

func RemoveMatch(hash string) error

RemoveMatch deletes all mappings for the given hash (all labels and legacy key).

func RemoveMatchForLabel

func RemoveMatchForLabel(hash, label string) error

RemoveMatchForLabel deletes the mapping for the given hash and label only.

func RemoveMatchesByLabel

func RemoveMatchesByLabel(label string) error

RemoveMatchesByLabel removes all entries associated with the specified label.

func RemoveThinkTags

func RemoveThinkTags(s string) string

RemoveThinkTags strips <think>...</think> blocks and trims whitespace.

func Sha256Hex

func Sha256Hex(s string) string

Sha256Hex computes SHA-256 hex digest for the specified string.

func StoreConversation

func StoreConversation(label, model string, msgs []Message, metadata []string) error

StoreConversation updates all hashes representing the provided conversation snapshot.

func StoreMatch

func StoreMatch(hash string, record MatchRecord) error

StoreMatch persists or updates a conversation hash mapping.

Types

type MatchRecord

type MatchRecord struct {
	AccountLabel string   `json:"account_label"`
	Metadata     []string `json:"metadata,omitempty"`
	PrefixLen    int      `json:"prefix_len"`
	UpdatedAt    int64    `json:"updated_at"`
}

MatchRecord stores persisted mapping metadata for a conversation prefix.

func LookupMatch

func LookupMatch(hash string) (MatchRecord, bool, error)

LookupMatch retrieves a stored mapping. It prefers namespaced entries (hash:label). If multiple labels exist for the same hash, it returns not found to avoid redirecting to the wrong credential. Falls back to legacy single-key entries if present.

type MatchResult

type MatchResult struct {
	Hash   string
	Record MatchRecord
	Model  string
}

MatchResult combines a persisted record with the hash that produced it.

type Message

type Message struct {
	Role string `json:"role"`
	Text string `json:"text"`
}

Message represents a minimal role-text pair used for hashing and comparison.

func ExtractMessages

func ExtractMessages(handlerType string, raw []byte) []Message

ExtractMessages attempts to build a message list from the inbound request payload.

func SanitizeAssistantMessages

func SanitizeAssistantMessages(msgs []Message) []Message

SanitizeAssistantMessages removes think tags from assistant messages while leaving others untouched.

func StoredToMessages

func StoredToMessages(msgs []StoredMessage) []Message

StoredToMessages converts stored messages back into the in-memory representation.

type PrefixHash

type PrefixHash struct {
	Hash      string
	PrefixLen int
}

PrefixHash represents a hash candidate for a specific prefix length.

func BuildLookupHashes

func BuildLookupHashes(model string, msgs []Message) []PrefixHash

BuildLookupHashes generates hash candidates ordered from longest to shortest prefix.

func BuildStorageHashes

func BuildStorageHashes(model string, msgs []Message) []PrefixHash

BuildStorageHashes returns hashes representing the full conversation snapshot.

type StoredMessage

type StoredMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
	Name    string `json:"name,omitempty"`
}

StoredMessage mirrors the persisted conversation message structure.

func ToStoredMessages

func ToStoredMessages(msgs []Message) []StoredMessage

ToStoredMessages converts in-memory messages into the persisted representation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL