Documentation
¶
Index ¶
- func LooksLikePatternFilePath(source string) bool
- func ValidateStorageName(name string) error
- type Context
- type ContextsEntity
- type Db
- func (o *Db) ApplyEnvUpdates(updates map[string]string) error
- func (o *Db) Configure() (err error)
- func (o *Db) FilePath(fileName string) (ret string)
- func (o *Db) IsEnvFileExists() (ret bool)
- func (o *Db) LoadEnvFile() (err error)
- func (o *Db) ReadEnvFile() (map[string]string, error)
- func (o *Db) SaveEnv(content string) error
- func (o *Db) UpdateEnvVars(updates map[string]string) error
- func (o *Db) WithEnvLock(fn func() error) error
- type DirectoryChange
- type InvalidStorageNameError
- type Pattern
- type PatternsEntity
- func (o *PatternsEntity) Get(name string) (*Pattern, error)
- func (o *PatternsEntity) GetApplyVariables(source string, variables map[string]string, input string) (pattern *Pattern, err error)
- func (o *PatternsEntity) GetNames() (ret []string, err error)
- func (o *PatternsEntity) GetRaw(name string) (*Pattern, error)
- func (o *PatternsEntity) GetWithoutVariables(source, input string) (pattern *Pattern, err error)
- func (o *PatternsEntity) ListNames(shellCompleteList bool) (err error)
- func (o *PatternsEntity) PrintLatestPatterns(latestNumber int) (err error)
- func (o *PatternsEntity) PrintPattern(name string) (err error)
- func (o *PatternsEntity) Rename(oldName, newName string) error
- func (o *PatternsEntity) Save(name string, content []byte) (err error)
- type Session
- type SessionsEntity
- type StorageEntity
- func (o *StorageEntity) BuildFilePath(fileName string) (ret string)
- func (o *StorageEntity) Configure() (err error)
- func (o *StorageEntity) Delete(name string) (err error)
- func (o *StorageEntity) Exists(name string) (ret bool)
- func (o *StorageEntity) GetNames() (ret []string, err error)
- func (o *StorageEntity) ListNames(shellCompleteList bool) (err error)
- func (o *StorageEntity) Load(name string) (ret []byte, err error)
- func (o *StorageEntity) LoadAsJson(name string, item any) (err error)
- func (o *StorageEntity) Rename(oldName, newName string) (err error)
- func (o *StorageEntity) Save(name string, content []byte) (err error)
- func (o *StorageEntity) SaveAsJson(name string, item any) (err error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func LooksLikePatternFilePath ¶ added in v1.4.474
LooksLikePatternFilePath reports whether loadPattern uses source as a filesystem path. HTTP handlers must reject these names to keep the CLI file-path feature out of the REST API.
func ValidateStorageName ¶ added in v1.4.474
ValidateStorageName rejects an empty name, ".", "..", and each name that is not a single path element. It also rejects names that are dangerous only on Windows: names with ":" (an NTFS alternate data stream suffix), names with a dot or space at the end, and reserved DOS device names. Windows removes a dot or space at the end, and the shortened name then collides with an existing entry. The policy is the same on each platform, and an entry made on one system stays valid on the other systems. A Unix entry that already has a name against these rules shows in GetNames but is not accessible. To repair it, rename its file or directory on disk. Call this function before you join a name to a storage directory.
Types ¶
type ContextsEntity ¶
type ContextsEntity struct {
*StorageEntity
}
func (*ContextsEntity) Get ¶
func (o *ContextsEntity) Get(name string) (ret *Context, err error)
Get Load a context from file
func (*ContextsEntity) PrintContext ¶
func (o *ContextsEntity) PrintContext(name string) (err error)
type Db ¶
type Db struct {
Dir string
Patterns *PatternsEntity
Sessions *SessionsEntity
Contexts *ContextsEntity
EnvFilePath string
// contains filtered or unexported fields
}
func (*Db) ApplyEnvUpdates ¶ added in v1.4.471
ApplyEnvUpdates writes non-empty updates atomically. Callers holding WithEnvLock use this.
func (*Db) IsEnvFileExists ¶
func (*Db) LoadEnvFile ¶
func (*Db) UpdateEnvVars ¶ added in v1.4.471
UpdateEnvVars merges non-empty values into .env under a file lock. Comments and key order are not preserved.
func (*Db) WithEnvLock ¶ added in v1.4.471
type DirectoryChange ¶
type InvalidStorageNameError ¶ added in v1.4.474
type InvalidStorageNameError struct {
Name string
Message string // optional: the default is the storage_invalid_name translation
}
InvalidStorageNameError reports a name that storage-name validation rejected. HTTP handlers map it to 400 Bad Request. All other storage errors stay 500 errors.
func (*InvalidStorageNameError) Error ¶ added in v1.4.474
func (e *InvalidStorageNameError) Error() string
type PatternsEntity ¶
type PatternsEntity struct {
*StorageEntity
SystemPatternFile string
UniquePatternsFilePath string
CustomPatternsDir string
}
func (*PatternsEntity) Get ¶
func (o *PatternsEntity) Get(name string) (*Pattern, error)
Get required for Storage interface
func (*PatternsEntity) GetApplyVariables ¶
func (o *PatternsEntity) GetApplyVariables( source string, variables map[string]string, input string) (pattern *Pattern, err error)
GetApplyVariables main entry point for getting patterns from any source
func (*PatternsEntity) GetNames ¶
func (o *PatternsEntity) GetNames() (ret []string, err error)
GetNames overrides StorageEntity.GetNames to include custom patterns directory
func (*PatternsEntity) GetRaw ¶ added in v1.4.429
func (o *PatternsEntity) GetRaw(name string) (*Pattern, error)
GetRaw returns a pattern from storage without applying variable processing.
func (*PatternsEntity) GetWithoutVariables ¶ added in v1.4.289
func (o *PatternsEntity) GetWithoutVariables(source, input string) (pattern *Pattern, err error)
GetWithoutVariables returns a pattern with only the {{input}} placeholder processed and skips template variable replacement
func (*PatternsEntity) ListNames ¶
func (o *PatternsEntity) ListNames(shellCompleteList bool) (err error)
ListNames overrides StorageEntity.ListNames to use PatternsEntity.GetNames
func (*PatternsEntity) PrintLatestPatterns ¶
func (o *PatternsEntity) PrintLatestPatterns(latestNumber int) (err error)
func (*PatternsEntity) PrintPattern ¶ added in v1.4.446
func (o *PatternsEntity) PrintPattern(name string) (err error)
PrintPattern prints the raw contents of the named pattern to the terminal. It checks the custom patterns directory first, then falls back to the main directory.
func (*PatternsEntity) Rename ¶ added in v1.4.474
func (o *PatternsEntity) Rename(oldName, newName string) error
Rename applies the file-path guard from Save to the destination name. Without the guard, the inherited StorageEntity.Rename accepts ".foo" or "~foo", and loadPattern then reads these names from the filesystem. A path-like source stays permitted, which lets you rename a legacy entry to a valid name.
type Session ¶
type Session struct {
Name string
Messages []*chat.ChatCompletionMessage
// contains filtered or unexported fields
}
func (*Session) Append ¶
func (o *Session) Append(messages ...*chat.ChatCompletionMessage)
func (*Session) GetLastMessage ¶
func (o *Session) GetLastMessage() (ret *chat.ChatCompletionMessage)
func (*Session) GetVendorMessages ¶
func (o *Session) GetVendorMessages() (ret []*chat.ChatCompletionMessage)
type SessionsEntity ¶
type SessionsEntity struct {
*StorageEntity
}
func (*SessionsEntity) Get ¶
func (o *SessionsEntity) Get(name string) (session *Session, err error)
func (*SessionsEntity) PrintSession ¶
func (o *SessionsEntity) PrintSession(name string) (err error)
func (*SessionsEntity) SaveSession ¶
func (o *SessionsEntity) SaveSession(session *Session) (err error)
type StorageEntity ¶
StorageEntity is the filesystem-backed db.Storage implementation. Each method that gets a name requires one that obeys ValidateStorageName. It rejects other names with *InvalidStorageNameError, which HTTP handlers map to 400.
func (*StorageEntity) BuildFilePath ¶
func (o *StorageEntity) BuildFilePath(fileName string) (ret string)
func (*StorageEntity) Configure ¶
func (o *StorageEntity) Configure() (err error)
func (*StorageEntity) Delete ¶
func (o *StorageEntity) Delete(name string) (err error)
func (*StorageEntity) Exists ¶
func (o *StorageEntity) Exists(name string) (ret bool)
func (*StorageEntity) GetNames ¶
func (o *StorageEntity) GetNames() (ret []string, err error)
GetNames finds all patterns in the patterns directory and enters the id, name, and pattern into a slice of Entry structs. it returns these entries or an error
func (*StorageEntity) ListNames ¶
func (o *StorageEntity) ListNames(shellCompleteList bool) (err error)
func (*StorageEntity) LoadAsJson ¶
func (o *StorageEntity) LoadAsJson(name string, item any) (err error)
func (*StorageEntity) Rename ¶
func (o *StorageEntity) Rename(oldName, newName string) (err error)
func (*StorageEntity) SaveAsJson ¶
func (o *StorageEntity) SaveAsJson(name string, item any) (err error)