Documentation
¶
Index ¶
- Constants
- Variables
- func AddAgentRunStep(s *agents.AgentRunStep)
- func AuthenticateAPIToken(secret string) (*models.APIToken, error)
- func ComponentReferences(tx *gorm.DB, name string) ([]string, error)
- func CountUsers() (int64, error)
- func CountUsersWithRole(roleName string) (int64, error)
- func CreateAPIToken(in NewAPITokenInput) (*models.APIToken, string, error)
- func CreateAgentRun(r *agents.AgentRun) error
- func CreateComponent(cmp *models.Component) error
- func CreateItems(actor Actor, collection models.Collection, inputs []ItemInput) ([]*models.Item, error)
- func CreateLocale(code, name string) (*models.Locale, error)
- func CreateSingleItem(actor Actor, st *models.Singleton, itemData map[string]any) (*models.SingleItem, error)
- func CreateUser(user *models.User) error
- func CreateWebhook(w *models.Webhook) error
- func DefaultLocale() (string, error)
- func DeleteAgent(agentID uint) error
- func DeleteAgentRuns(agentID uint) error
- func DeleteCollection(collectionID uint) error
- func DeleteComponent(name string) error
- func DeleteCustomRole(name string) error
- func DeleteItem(actor Actor, id uint) error
- func DeleteLocale(code string, purge bool) (int64, error)
- func DeleteMedia(ctx context.Context, id uint) error
- func DeleteRole(id uint) error
- func DeleteSingleItem(actor Actor, SingletonName string) error
- func DeleteSingleton(SingletonID uint) error
- func DeleteUser(id uint) error
- func DeleteWebhook(id uint) error
- func EnsureDefaultLocale(code string) error
- func FetchNestedRelations(collection models.Collection, data models.JSONMap, level uint) (models.JSONMap, error)
- func FindAgentsByEventTrigger(collectionName string, eventType string) ([]models.Agent, error)
- func FlattenEntry(data, translations models.JSONMap) models.JSONMap
- func GetAPIToken(id uint) (*models.APIToken, error)
- func GetAgentByID(id uint) (*models.Agent, error)
- func GetAgentByName(name string) (*models.Agent, error)
- func GetAgentRun(agentID, runID uint) (*agents.AgentRun, error)
- func GetAllAgents(filters map[string]any, rangeValues []int) ([]models.Agent, int, error)
- func GetAllCollections(filters map[string]any, sortValues []string, rangeValues []int) ([]models.Collection, int, error)
- func GetAllComponents() ([]models.Component, error)
- func GetAllRoles() ([]models.UserRole, error)
- func GetAllSingletons() ([]models.Singleton, error)
- func GetAllUsers() ([]models.User, error)
- func GetCollectionByID(id uint) (*models.Collection, error)
- func GetCollectionByName(name string) (*models.Collection, error)
- func GetCollectionSchema(id int) (map[string]any, error)
- func GetComponentByName(name string) (*models.Component, error)
- func GetConversationHistory(agentID uint) ([]llm.Message, error)
- func GetItemByID(collectionID uint, itemID uint) (*models.Item, error)
- func GetItems(collectionID uint, page, pageSize int) ([]models.Item, int, error)
- func GetItemsByOffset(ct models.Collection, offset, limit int, status string) ([]models.Item, int, error)
- func GetMedia(id uint) (*models.Media, error)
- func GetRevision(entityType string, entityID, version uint) (*models.Revision, error)
- func GetRoleByID(id uint) (*models.UserRole, error)
- func GetRoleByName(name string) (*models.UserRole, error)
- func GetSingleItemByType(SingletonName string) (*models.SingleItem, error)
- func GetSingletonByName(name string) (*models.Singleton, error)
- func GetUserByID(id uint) (*models.User, error)
- func GetUserByUsername(username string) (*models.User, error)
- func GetVisibleItem(ct models.Collection, itemID uint, publishedOnly bool) (*models.Item, error)
- func GetWebhook(id uint) (*models.Webhook, error)
- func HashAPIToken(secret string) string
- func InitAsynqClient(client *asynq.Client)
- func InitMediaStore(s media.Store)
- func InvalidateComponentCache()
- func IsReferencedByOtherCollections(collectionName string, tx *gorm.DB) ([]models.Attribute, error)
- func ItemCollectionName(itemID uint) (string, error)
- func LatestRevision(entityType string, entityID uint) (*models.Revision, error)
- func ListAPITokens() ([]models.APIToken, error)
- func ListAgentRuns(agentID uint, q RunQuery) ([]agents.AgentRun, int, error)
- func ListAllRuns(q RunQuery) ([]agents.AgentRun, int, error)
- func ListLocales() ([]models.Locale, error)
- func ListMedia(q MediaQuery) ([]models.Media, int, error)
- func ListRevisions(q RevisionQuery) ([]models.Revision, int, error)
- func ListWebhookDeliveries(webhookID uint, limit int) ([]models.WebhookDelivery, error)
- func ListWebhooks() ([]models.Webhook, error)
- func LocaleExists(code string) bool
- func MediaStore() media.Store
- func MediaURL(ctx context.Context, m models.Media) string
- func NestedWriteTargets(ct models.Collection, data map[string]any) ([]string, error)
- func NormalizePermissions(p auth.Permissions) (auth.Permissions, error)
- func PopulateMedia(ctx context.Context, attrs []models.Attribute, data models.JSONMap) models.JSONMap
- func PopulateRelations(collection models.Collection, data models.JSONMap, level uint, ...) (models.JSONMap, error)
- func PopulateRelationsIn(collection models.Collection, data models.JSONMap, level uint, ...) (models.JSONMap, error)
- func PruneAgentRuns(agentID uint, keep int)
- func QueryItems(ct models.Collection, q ItemQuery) ([]models.Item, int, error)
- func RecordWebhookDelivery(d *models.WebhookDelivery)
- func RenameLocale(code, name string) (*models.Locale, error)
- func ResolveLocale(requested string) (locale, defaultLocale string, err error)
- func ResolveMediaValue(ctx context.Context, v any, multiple bool) any
- func RestoreOutcome(ct models.Collection, itemID, version uint) (undelete, published bool, err error)
- func RevokeAPIToken(id uint) (*models.APIToken, error)
- func SaveAgent(agent *models.Agent) error
- func SaveAgentRun(r *agents.AgentRun) error
- func SaveCollection(ct *models.Collection) error
- func SaveConversationHistory(agentID uint, messages []llm.Message) error
- func SaveItem(actor Actor, collection models.Collection, itemData models.JSONMap) (*models.Item, error)
- func SaveItems(actor Actor, collection models.Collection, batch []models.JSONMap) ([]*models.Item, error)
- func SaveMedia(ctx context.Context, in UploadFile, policy UploadPolicy) (*models.Media, error)
- func SaveOrUpdateSingleton(st *models.Singleton) error
- func SaveRole(role *models.UserRole) error
- func SaveWebhook(w *models.Webhook) error
- func SetDefaultLocale(code string) (*models.Locale, error)
- func SetItemPublished(actor Actor, collection models.Collection, itemID uint, publish bool) (*models.Item, error)
- func SetItemTranslation(actor Actor, ct models.Collection, itemID uint, locale string, ...) (*models.Item, error)
- func SetSingletonTranslation(actor Actor, st *models.Singleton, locale string, data map[string]any) (*models.SingleItem, error)
- func UpdateAgent(id uint, updated *models.Agent) error
- func UpdateCollection(id uint, updated *models.Collection) error
- func UpdateComponent(name string, updated *models.Component) error
- func UpdateItemContent(actor Actor, collection models.Collection, itemID uint, data models.JSONMap, ...) (*models.Item, error)
- func UpdateMedia(id uint, info MediaInfo) (*models.Media, error)
- func UpdateRole(id uint, updates map[string]interface{}) error
- func UpdateSingleItem(actor Actor, SingletonName string, newData map[string]any) (*models.SingleItem, error)
- func UpdateUser(id uint, updates map[string]interface{}) error
- func WebhooksFor(event, collection string) ([]models.Webhook, error)
- func WithActor(ctx context.Context, a Actor) context.Context
- type Actor
- type AgentUsage
- type DBToolCall
- type DuplicateEntryError
- type FieldChange
- type GeneralDatabaseError
- type ItemFilter
- type ItemInput
- type ItemQuery
- type ItemSort
- type ItemValidationError
- type LocaleInUseError
- type MediaError
- type MediaInfo
- type MediaQuery
- type NewAPITokenInput
- type Overview
- type QueryFieldError
- type ReadLocale
- type RecentItem
- type RestoreResult
- type RevertOutcome
- type RevisionQuery
- type RevisionScope
- type RoleInUseError
- type RoleView
- type RunQuery
- type UploadFile
- type UploadPolicy
Constants ¶
const ( OpEq = "$eq" OpNe = "$ne" OpLt = "$lt" OpLte = "$lte" OpGt = "$gt" OpGte = "$gte" OpContains = "$contains" )
Filter operators supported on item lists.
Variables ¶
var ( // ErrLocaleNotFound is returned for a locale that is not configured. ErrLocaleNotFound = errors.New("locale not found") // ErrLocaleExists is returned when adding a locale twice. ErrLocaleExists = errors.New("locale already exists") // ErrDefaultLocale is returned when deleting the default locale. ErrDefaultLocale = errors.New("the default locale cannot be deleted") )
var ( // ErrRevisionNotFound is returned for an unknown revision. ErrRevisionNotFound = errors.New("revision not found") // ErrRunHasNoChanges is returned when reverting a run that changed no content. ErrRunHasNoChanges = errors.New("this run made no content changes") )
var ( // ErrRoleNotFound is returned for an unknown role. ErrRoleNotFound = errors.New("role not found") // ErrRoleExists is returned when a role name is taken. ErrRoleExists = errors.New("a role with this name already exists") // ErrBuiltinRole is returned when changing admin, editor or viewer. ErrBuiltinRole = errors.New("built-in roles (admin, editor, viewer) cannot be changed") )
var DefaultLocaleCode = "en"
DefaultLocaleCode is the default locale used until one is stored (set from i18n.default_locale at startup).
var ErrComponentInUse = errors.New("component is in use")
ErrComponentInUse is returned when deleting or renaming a component that attributes still reference.
var ErrDefaultLocaleWrite = errors.New("this is the default locale: write the entry itself")
ErrDefaultLocaleWrite is returned when a translation is written in the default locale (its content is the entry's main data).
var ErrDraftAndPublishDisabled = errors.New("this collection does not use draft and publish")
ErrDraftAndPublishDisabled is returned when publishing an item of a collection that does not use draft and publish.
var ErrInvalidToken = errors.New("invalid API token")
ErrInvalidToken is returned for unknown, revoked or expired secrets.
var ErrItemNotFound = errors.New("item not found")
ErrItemNotFound is returned when an item does not exist in a collection.
var ErrMediaNotFound = errors.New("media not found")
ErrMediaNotFound is returned for unknown media IDs.
var ErrNoMediaStore = errors.New("media uploads are not configured")
ErrNoMediaStore is returned when no store is configured.
var ErrRunNotFound = errors.New("run not found")
ErrRunNotFound is returned for unknown runs.
var ErrTokenNotFound = errors.New("token not found")
ErrTokenNotFound is returned for unknown token IDs.
var ErrWebhookNotFound = errors.New("webhook not found")
ErrWebhookNotFound is returned for unknown webhook IDs.
var RevisionLimit = 100
RevisionLimit is how many revisions are kept per entry; older ones are pruned when a new one is recorded. 0 keeps every revision.
var SystemActor = Actor{Kind: models.ActorSystem, Name: "system"}
SystemActor is used for changes nobody in particular made (imports, tests, internal jobs).
Functions ¶
func AddAgentRunStep ¶ added in v0.5.0
func AddAgentRunStep(s *agents.AgentRunStep)
AddAgentRunStep records one step of a run.
func AuthenticateAPIToken ¶ added in v0.5.0
AuthenticateAPIToken returns the active token matching secret, and records its use (at most once a minute, to avoid a write per request).
func ComponentReferences ¶ added in v0.4.0
ComponentReferences lists the attributes (as "collection.attribute", "singleton.attribute" or "component.attribute") that use the component.
func CountUsers ¶
CountUsers returns the total number of (non-deleted) users.
func CountUsersWithRole ¶ added in v0.5.0
CountUsersWithRole counts the users that have the role.
func CreateAPIToken ¶ added in v0.5.0
func CreateAPIToken(in NewAPITokenInput) (*models.APIToken, string, error)
CreateAPIToken stores a new token and returns it with its secret, which is not kept and cannot be shown again.
func CreateAgentRun ¶ added in v0.5.0
CreateAgentRun records the start of a run.
func CreateComponent ¶
CreateComponent stores a new Component definition in the DB, including its attributes.
func CreateItems ¶ added in v0.4.0
func CreateItems(actor Actor, collection models.Collection, inputs []ItemInput) ([]*models.Item, error)
CreateItems validates and creates several items atomically: either all are stored or none. Nested relations created during validation are part of the same transaction, and the stored data is the processed (validated) data. Each item gets its first revision. Events are published only after a successful commit.
func CreateLocale ¶ added in v0.5.0
CreateLocale adds a locale.
func CreateSingleItem ¶
func CreateSingleItem(actor Actor, st *models.Singleton, itemData map[string]any) (*models.SingleItem, error)
CreateSingleItem creates a new SingleItem for a given Singleton and records its first revision. Returns an error if an item already exists for that Singleton (one-to-one).
func CreateUser ¶
func CreateWebhook ¶ added in v0.5.0
CreateWebhook stores a webhook.
func DefaultLocale ¶ added in v0.5.0
DefaultLocale returns the default locale's code.
func DeleteAgent ¶
DeleteAgent deletes an agent from the database by its ID.
func DeleteAgentRuns ¶ added in v0.5.0
DeleteAgentRuns removes all runs of an agent.
func DeleteCollection ¶
DeleteCollection deletes a collection and all associated data by its ID.
func DeleteComponent ¶
DeleteComponent removes a component definition by name. It refuses to delete a component that attributes still use.
func DeleteCustomRole ¶ added in v0.5.0
DeleteCustomRole removes a custom role nobody uses.
func DeleteItem ¶
DeleteItem deletes an item and records a "delete" revision holding the data it had, so the item can be restored. It returns ErrItemNotFound for an unknown item and publishes item:deleted after the commit.
func DeleteLocale ¶ added in v0.5.0
DeleteLocale removes a locale. Entries with content in it are counted and the delete is refused (LocaleInUseError) unless purge is set, which deletes that content too.
func DeleteMedia ¶ added in v0.4.0
DeleteMedia removes a media file and its content. Items that referenced it then show null, like a deleted related item. The record goes first, so a failure to delete the content leaves an orphan object (logged), never a record pointing at nothing.
func DeleteSingleItem ¶
DeleteSingleItem removes the SingleItem for a given single type name and records a "delete" revision holding its data, so it can be restored.
func DeleteSingleton ¶
DeleteSingleton permanently deletes a single type by its ID (including attributes). Note: Strapi typically doesn't expose DELETE for single types, but you can implement it if needed.
func DeleteWebhook ¶ added in v0.5.0
DeleteWebhook removes a webhook and its delivery log.
func EnsureDefaultLocale ¶ added in v0.5.0
EnsureDefaultLocale stores the default locale when no locale is stored yet (first start, or an upgrade from a version without locales).
func FetchNestedRelations ¶
func FetchNestedRelations(collection models.Collection, data models.JSONMap, level uint) (models.JSONMap, error)
FetchNestedRelations replaces relation IDs in data with the related items, down to level levels, including drafts. See PopulateRelations.
func FindAgentsByEventTrigger ¶
FindAgentsByEventTrigger returns the agents subscribed to a collection event. Agents are few, so they are filtered here rather than with dialect-specific JSON SQL (and "trigger" is a reserved word in MySQL).
func FlattenEntry ¶ added in v0.5.0
FlattenEntry merges an entry's data and translations into one map for diffs: translated values are keyed "<attribute>@<locale>".
func GetAPIToken ¶ added in v0.5.0
GetAPIToken returns a token by ID.
func GetAgentByID ¶
GetAgentByID retrieves an agent by its ID.
func GetAgentByName ¶
GetAgentByName retrieves an agent by its name.
func GetAgentRun ¶ added in v0.5.0
GetAgentRun returns one run of an agent with its steps in order.
func GetAllAgents ¶
func GetAllCollections ¶
func GetAllComponents ¶
GetAllComponents returns every component definition with its attributes, ordered by name.
func GetAllRoles ¶
GetAllRoles retrieves all roles from the database.
func GetAllSingletons ¶
GetAllSingletons returns every singleton definition with its attributes, ordered by name.
func GetAllUsers ¶
GetAllUsers retrieves all users from the database.
func GetCollectionByID ¶
func GetCollectionByID(id uint) (*models.Collection, error)
GetCollectionByID retrieves a collection by its ID.
func GetCollectionByName ¶
func GetCollectionByName(name string) (*models.Collection, error)
GetCollectionByName retrieves a collection by its name.
func GetCollectionSchema ¶
GetCollectionSchema retrieves the schema definition of a collection by name.
func GetComponentByName ¶
GetComponentByName retrieves a component definition by its name.
func GetConversationHistory ¶
GetConversationHistory retrieves the messages for an agent.
func GetItemByID ¶
GetItemByID fetches an item by its ID and collection ID.
func GetItemsByOffset ¶
func GetItemsByOffset(ct models.Collection, offset, limit int, status string) ([]models.Item, int, error)
GetItemsByOffset lists items using offset/limit pagination (as GraphQL does). status filters draft-and-publish collections: "" (all), models.StatusPublished or models.StatusDraft.
func GetRevision ¶ added in v0.5.0
GetRevision returns one revision of an entry, with its data.
func GetRoleByID ¶
GetRoleByID retrieves a role by its ID.
func GetRoleByName ¶
GetRoleByName retrieves a role by its name.
func GetSingleItemByType ¶
func GetSingleItemByType(SingletonName string) (*models.SingleItem, error)
GetSingleItemByType retrieves the SingleItem for a given single type name.
func GetSingletonByName ¶
GetSingletonByName retrieves a single type by its name (including associated attributes).
func GetUserByID ¶
GetUserByID retrieves a user by their ID.
func GetUserByUsername ¶
GetUserByUsername retrieves a user by their username.
func GetVisibleItem ¶ added in v0.4.0
GetVisibleItem fetches an item of the collection. With publishedOnly, a draft of a draft-and-publish collection is reported as not found.
func GetWebhook ¶ added in v0.5.0
GetWebhook returns a webhook by ID.
func HashAPIToken ¶ added in v0.5.0
HashAPIToken returns the stored form of a token secret. Tokens carry 256 bits of randomness, so a fast hash is enough (unlike passwords).
func InitAsynqClient ¶
func InitMediaStore ¶ added in v0.4.0
InitMediaStore sets the store used for uploads and media URLs.
func InvalidateComponentCache ¶ added in v0.4.0
func InvalidateComponentCache()
InvalidateComponentCache drops cached component definitions.
func ItemCollectionName ¶ added in v0.5.0
ItemCollectionName returns the name of the collection an item belongs to.
func LatestRevision ¶ added in v0.5.0
LatestRevision returns the newest revision of an entry.
func ListAPITokens ¶ added in v0.5.0
ListAPITokens returns every token, newest first.
func ListAgentRuns ¶ added in v0.5.0
ListAgentRuns returns an agent's runs, newest first (without steps).
func ListAllRuns ¶ added in v0.5.0
ListAllRuns lists the runs of every agent, newest first (without steps).
func ListLocales ¶ added in v0.5.0
ListLocales returns the locales, the default first.
func ListMedia ¶ added in v0.4.0
func ListMedia(q MediaQuery) ([]models.Media, int, error)
ListMedia lists media files, newest first.
func ListRevisions ¶ added in v0.5.0
func ListRevisions(q RevisionQuery) ([]models.Revision, int, error)
ListRevisions lists revisions, newest first, without their data.
func ListWebhookDeliveries ¶ added in v0.5.0
func ListWebhookDeliveries(webhookID uint, limit int) ([]models.WebhookDelivery, error)
ListWebhookDeliveries returns the newest delivery records of a webhook.
func ListWebhooks ¶ added in v0.5.0
ListWebhooks returns every webhook, oldest first.
func LocaleExists ¶ added in v0.5.0
LocaleExists reports whether a locale is configured.
func MediaStore ¶ added in v0.4.0
MediaStore returns the configured store (nil when uploads are disabled).
func NestedWriteTargets ¶ added in v0.5.0
NestedWriteTargets lists the collections that writing data into ct may look up or create items in: relations given as objects without an "id" are matched against, or created in, their target (see models.ValidateItemValues). Raw IDs and {"id": …} only link items.
func NormalizePermissions ¶ added in v0.5.0
func NormalizePermissions(p auth.Permissions) (auth.Permissions, error)
NormalizePermissions validates permissions against the content model and returns them cleaned up: actions sorted and deduplicated, read added to any type with another action.
func PopulateMedia ¶ added in v0.4.0
func PopulateMedia(ctx context.Context, attrs []models.Attribute, data models.JSONMap) models.JSONMap
PopulateMedia replaces media IDs in an item's data (including inside components) with media objects.
func PopulateRelations ¶ added in v0.4.0
func PopulateRelations(collection models.Collection, data models.JSONMap, level uint, publishedOnly bool) (models.JSONMap, error)
PopulateRelations replaces relation IDs in data with the related items (in the API's flat item shape), down to level levels. With publishedOnly, drafts of draft-and-publish target collections are left out, as are related items that no longer exist.
func PopulateRelationsIn ¶ added in v0.5.0
func PopulateRelationsIn(collection models.Collection, data models.JSONMap, level uint, publishedOnly bool, loc ReadLocale) (models.JSONMap, error)
PopulateRelationsIn is PopulateRelations with related entries read in a locale (their localized attributes, and their locale fields).
func PruneAgentRuns ¶ added in v0.5.0
PruneAgentRuns keeps the newest keep runs of an agent (and their steps). Runs still in progress are never pruned.
func QueryItems ¶
QueryItems lists the items of a collection with optional filters and sort. Every field is validated against the collection schema; attribute names and values are always bound as SQL parameters.
func RecordWebhookDelivery ¶ added in v0.5.0
func RecordWebhookDelivery(d *models.WebhookDelivery)
RecordWebhookDelivery logs an attempt, updates the webhook's last status and trims old records.
func RenameLocale ¶ added in v0.5.0
RenameLocale changes a locale's display name.
func ResolveLocale ¶ added in v0.5.0
ResolveLocale checks a requested locale and returns it with the default locale. "" means the default locale.
func ResolveMediaValue ¶ added in v0.4.0
ResolveMediaValue converts one stored media value (an ID, a list of IDs, or URL strings) to API objects; GraphQL uses it.
func RestoreOutcome ¶ added in v0.5.0
func RestoreOutcome(ct models.Collection, itemID, version uint) (undelete, published bool, err error)
RestoreOutcome tells whether restoring a version of an item would bring it back from deletion, and whether it would be published afterwards.
func RevokeAPIToken ¶ added in v0.5.0
RevokeAPIToken makes a token unusable immediately. The record stays, so the audit trail (name, creator, last use) is kept.
func SaveAgent ¶
SaveAgent persists an Agent to the database, handling both new and soft-deleted records.
func SaveAgentRun ¶ added in v0.5.0
SaveAgentRun stores the run's current state (usage, status, output). It only updates: a run deleted meanwhile (agent deleted) is not re-created.
func SaveCollection ¶
func SaveCollection(ct *models.Collection) error
SaveCollection persists a Collection to the database, handling both new and soft-deleted records.
func SaveConversationHistory ¶
SaveConversationHistory replaces the old history with the new one for an agent.
func SaveItem ¶
func SaveItem(actor Actor, collection models.Collection, itemData models.JSONMap) (*models.Item, error)
SaveItem validates and creates a single item, then publishes an 'item:created' event once the transaction has committed.
func SaveItems ¶
func SaveItems(actor Actor, collection models.Collection, batch []models.JSONMap) ([]*models.Item, error)
SaveItems validates and creates several items atomically, as drafts in draft-and-publish collections. See CreateItems.
func SaveMedia ¶ added in v0.4.0
func SaveMedia(ctx context.Context, in UploadFile, policy UploadPolicy) (*models.Media, error)
SaveMedia checks a file against the policy, stores its content and records it. The type is detected from the content, not from the client.
func SaveOrUpdateSingleton ¶
SaveOrUpdateSingleton either creates a new single type or updates/restores a previously soft-deleted record with the same name.
This mimics the "single type" behavior in Strapi (one record per name).
func SaveWebhook ¶ added in v0.5.0
SaveWebhook updates every field of a webhook.
func SetDefaultLocale ¶ added in v0.5.0
SetDefaultLocale makes another locale the default. Entries' main data is in the default locale, so this only relabels it: it is refused while any entry has a translation in the new default (that content would be hidden), and the old default becomes a locale without translations.
func SetItemPublished ¶ added in v0.4.0
func SetItemPublished(actor Actor, collection models.Collection, itemID uint, publish bool) (*models.Item, error)
SetItemPublished publishes or unpublishes an item of a draft-and-publish collection. Publishing an already published item keeps its publishedAt.
func SetItemTranslation ¶ added in v0.5.0
func SetItemTranslation(actor Actor, ct models.Collection, itemID uint, locale string, data map[string]any, publish *bool) (*models.Item, error)
SetItemTranslation replaces an item's values in a locale other than the default. data holds localized attributes only; an empty object removes the translation. publish changes the publication state like an update.
func SetSingletonTranslation ¶ added in v0.5.0
func SetSingletonTranslation(actor Actor, st *models.Singleton, locale string, data map[string]any) (*models.SingleItem, error)
SetSingletonTranslation replaces a singleton's values in a locale other than the default (see SetItemTranslation). The singleton must have content already.
func UpdateAgent ¶
UpdateAgent updates an existing Agent in the database by its ID.
func UpdateCollection ¶
func UpdateCollection(id uint, updated *models.Collection) error
UpdateCollectionByID updates an existing Collection in the database by its ID.
func UpdateComponent ¶
UpdateComponent updates an existing component definition by name.
func UpdateItemContent ¶ added in v0.4.0
func UpdateItemContent(actor Actor, collection models.Collection, itemID uint, data models.JSONMap, publish *bool) (*models.Item, error)
UpdateItemContent validates data (the item's complete new data) and saves it. publish changes the publication state of a draft-and-publish item (nil leaves it unchanged). It returns ErrItemNotFound when the item is not in the collection, an *ItemValidationError for invalid data, and publishes item:updated (plus item:published / item:unpublished on a state change). A change is recorded as a revision; a save that changes nothing is not.
func UpdateMedia ¶ added in v0.4.0
UpdateMedia changes a media file's name, alternative text or caption.
func UpdateRole ¶
UpdateRole updates an existing role by ID.
func UpdateSingleItem ¶
func UpdateSingleItem(actor Actor, SingletonName string, newData map[string]any) (*models.SingleItem, error)
UpdateSingleItem updates the SingleItem for a given single type with new data and records a revision (unless nothing changed). Returns the updated SingleItem or an error if not found or validation fails.
func UpdateUser ¶
UpdateUser updates the details of an existing user by ID.
func WebhooksFor ¶ added in v0.5.0
WebhooksFor returns the enabled webhooks subscribed to event on collection.
Types ¶
type Actor ¶ added in v0.5.0
type Actor struct {
Kind string // models.ActorUser, ActorToken, ActorAgent or ActorSystem
Name string // username, token name or agent name
AgentRunID uint // the agent run, for agents
// contains filtered or unexported fields
}
Actor is who makes a content change. It is recorded on each revision.
type AgentUsage ¶ added in v0.5.0
type AgentUsage struct {
Runs int `json:"runs"` // runs that called the model (limited runs excluded)
InputTokens int `json:"inputTokens"`
OutputTokens int `json:"outputTokens"`
CostUSD float64 `json:"costUsd"`
}
AgentUsage summarizes an agent's runs in a time window.
func AgentUsageBefore ¶ added in v0.5.0
AgentUsageBefore is AgentUsageSince over the runs created before run beforeRun, which orders runs starting at the same time.
func AgentUsageSince ¶ added in v0.5.0
AgentUsageSince sums an agent's runs started after since. Runs skipped by a limit do not count as runs, but tokens and cost spent by runs that a limit stopped midway do. excludeRun (or 0) is left out.
func (AgentUsage) Tokens ¶ added in v0.5.0
func (u AgentUsage) Tokens() int
Tokens is input plus output tokens.
type DBToolCall ¶
type DBToolCall struct {
ID string `json:"id"`
Type string `json:"type"`
FunctionName string `json:"function_name"`
Arguments string `json:"arguments"`
}
DBToolCall represents a simplified tool call for database storage
type DuplicateEntryError ¶
type DuplicateEntryError struct {
Field string
}
Custom error types
func (*DuplicateEntryError) Error ¶
func (e *DuplicateEntryError) Error() string
type FieldChange ¶ added in v0.5.0
type FieldChange struct {
Field string `json:"field"`
Change string `json:"change"` // added, removed or changed
Before any `json:"before"`
After any `json:"after"`
}
FieldChange is one attribute that differs between two versions.
func DiffData ¶ added in v0.5.0
func DiffData(before, after models.JSONMap) []FieldChange
DiffData compares two data maps attribute by attribute, sorted by name.
type GeneralDatabaseError ¶
type GeneralDatabaseError struct {
Message string
}
func (*GeneralDatabaseError) Error ¶
func (e *GeneralDatabaseError) Error() string
type ItemFilter ¶
ItemFilter is one condition on an item attribute (or a built-in column).
type ItemInput ¶ added in v0.4.0
type ItemInput struct {
Data models.JSONMap
// Publish creates the item as published. It is ignored unless the
// collection uses draft and publish (other items are always visible).
Publish bool
}
ItemInput is one item to create.
type ItemQuery ¶
type ItemQuery struct {
Page int
PageSize int
Filters []ItemFilter
Sort []ItemSort
// Status filters draft-and-publish collections: "" (all items),
// models.StatusPublished or models.StatusDraft. Ignored otherwise.
Status string
// Locale makes filters and sorts on localized attributes use that
// locale's values ("" or the default locale: the main data). With
// Fallback, a missing value falls back to the default locale's.
Locale string
Fallback bool
}
ItemQuery describes a filtered, sorted, paginated item listing.
type ItemValidationError ¶
ItemValidationError wraps a validation failure for an item, as opposed to a database error, so callers can answer 400 instead of 500.
func (*ItemValidationError) Error ¶
func (e *ItemValidationError) Error() string
func (*ItemValidationError) Unwrap ¶
func (e *ItemValidationError) Unwrap() error
type LocaleInUseError ¶ added in v0.5.0
LocaleInUseError reports content in a locale that would be lost or mislabelled.
func (*LocaleInUseError) Error ¶ added in v0.5.0
func (e *LocaleInUseError) Error() string
type MediaError ¶ added in v0.4.0
MediaError is an upload refused for a reason the client can fix.
func (*MediaError) Error ¶ added in v0.4.0
func (e *MediaError) Error() string
type MediaQuery ¶ added in v0.4.0
type MediaQuery struct {
Page, PageSize int
MimePrefix string // e.g. "image/" or "application/pdf"
Search string // substring of the file name
}
MediaQuery filters the media library.
type NewAPITokenInput ¶ added in v0.5.0
type NewAPITokenInput struct {
Name string
Description string
Role string
ExpiresAt *time.Time
CreatedBy string
}
NewAPITokenInput describes a token to create.
type Overview ¶ added in v0.5.0
type Overview struct {
Counts struct {
Collections int64 `json:"collections"`
Singletons int64 `json:"singletons"`
Components int64 `json:"components"`
Items int64 `json:"items"`
Media int64 `json:"media"`
MediaBytes int64 `json:"mediaBytes"`
Users int64 `json:"users"`
Agents int64 `json:"agents"`
Webhooks int64 `json:"webhooks"`
APITokens int64 `json:"apiTokens"`
} `json:"counts"`
// Agent runs of the last 24 hours.
Runs struct {
Total int64 `json:"total"`
Succeeded int64 `json:"succeeded"`
Failed int64 `json:"failed"`
Limited int64 `json:"limited"`
Running int64 `json:"running"`
InputTokens int64 `json:"inputTokens"`
OutputTokens int64 `json:"outputTokens"`
CostUSD float64 `json:"costUsd"`
} `json:"runs24h"`
// Webhook deliveries of the last 24 hours.
Deliveries struct {
Total int64 `json:"total"`
Failed int64 `json:"failed"`
} `json:"deliveries24h"`
RecentItems []RecentItem `json:"recentItems"`
RecentRuns []agents.AgentRun `json:"recentRuns"`
RecentDeliveries []models.WebhookDelivery `json:"recentDeliveries"`
}
Overview summarizes an instance for the admin dashboard.
func GetOverview ¶ added in v0.5.0
GetOverview counts the content model, content, users and integrations, and lists recent activity.
type QueryFieldError ¶
type QueryFieldError struct{ Msg string }
QueryFieldError reports a filter or sort the collection cannot satisfy.
func (*QueryFieldError) Error ¶
func (e *QueryFieldError) Error() string
type ReadLocale ¶ added in v0.5.0
type ReadLocale struct {
Locale, Default string
Fallback bool
// CanRead, when set, hides related entries of collections it refuses
// (types the reader's role cannot read).
CanRead func(collection string) bool
// CanSeeDrafts, when set, hides related drafts of collections it
// refuses, even when the request includes drafts.
CanSeeDrafts func(collection string) bool
}
ReadLocale is the locale related entries are read in. The zero value reads the default locale.
type RecentItem ¶ added in v0.5.0
type RecentItem struct {
ID uint `json:"id"`
Collection string `json:"collection"`
Title string `json:"title"` // first text value, for display
UpdatedAt time.Time `json:"updatedAt"`
}
RecentItem is a recently changed item.
type RestoreResult ¶ added in v0.5.0
type RestoreResult struct {
Revision *models.Revision // the new revision
// Dropped lists attributes of the old version the type no longer has.
Dropped []string
// Undeleted is true when the restore brought back a deleted entry.
Undeleted bool
// Unchanged is true when the entry already had that content: no
// revision was recorded, and Revision is the latest one.
Unchanged bool
}
RestoreResult describes a restore.
func RestoreItemRevision ¶ added in v0.5.0
func RestoreItemRevision(actor Actor, ct models.Collection, itemID, version uint) (*models.Item, *RestoreResult, error)
RestoreItemRevision makes a version of an item its current content, as a new revision. A deleted item is brought back with the publication state the restored version had; otherwise the publication state is left as it is. The data is validated against the current schema.
func RestoreSingletonRevision ¶ added in v0.5.0
func RestoreSingletonRevision(actor Actor, st *models.Singleton, version uint) (*models.SingleItem, *RestoreResult, error)
RestoreSingletonRevision makes a version of a singleton's content its current content, as a new revision (re-creating deleted content).
type RevertOutcome ¶ added in v0.5.0
type RevertOutcome struct {
EntityType string `json:"entityType"`
EntityID uint `json:"entityId"`
TypeName string `json:"typeName"`
// Result: reverted (restored the version before the run), deleted
// (the run created the entry), skipped or failed.
Result string `json:"result"`
// Version restored, for "reverted".
Version uint `json:"version,omitempty"`
Reason string `json:"reason,omitempty"`
}
RevertOutcome is what reverting a run did to one entry.
func RevertAgentRun ¶ added in v0.5.0
func RevertAgentRun(actor Actor, runID uint, force bool) ([]RevertOutcome, error)
RevertAgentRun undoes the content changes of an agent run, entry by entry: entries the run created are deleted, the others go back to the version they had before the run. An entry changed by someone else after the run is skipped unless force is set.
type RevisionQuery ¶ added in v0.5.0
type RevisionQuery struct {
EntityType string
EntityID uint
TypeName string
Action string
ActorKind string
ActorName string
AgentRunID uint
Page int
PageSize int
// Scope, when set, limits the list to these types (for roles that can
// edit only some of them).
Scope *RevisionScope
}
RevisionQuery filters a revision list.
type RevisionScope ¶ added in v0.5.0
type RevisionScope struct {
Collections []string // collection names
Singletons []uint // singleton IDs
}
RevisionScope lists the types whose history a role may see.
type RoleInUseError ¶ added in v0.5.0
type RoleInUseError struct {
Users, Tokens int64
}
RoleInUseError is returned when deleting a role that accounts or API tokens still use.
func (*RoleInUseError) Error ¶ added in v0.5.0
func (e *RoleInUseError) Error() string
type RoleView ¶ added in v0.5.0
type RoleView struct {
ID uint `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Builtin bool `json:"builtin"`
Permissions auth.Permissions `json:"permissions"`
}
RoleView is a role with its permissions in API form.
func CreateCustomRole ¶ added in v0.5.0
func CreateCustomRole(name, description string, perms auth.Permissions) (*RoleView, error)
CreateCustomRole adds a role.
func GetRoleView ¶ added in v0.5.0
GetRoleView returns one role.
func ListRoleViews ¶ added in v0.5.0
ListRoleViews lists every role, built-in ones first.
func UpdateCustomRole ¶ added in v0.5.0
func UpdateCustomRole(name, description string, perms auth.Permissions) (*RoleView, error)
UpdateCustomRole replaces a custom role's description and permissions. Its name cannot change (accounts and tokens refer to it).
type UploadFile ¶ added in v0.4.0
type UploadFile struct {
Name string // client file name
Size int64 // bytes
Content io.ReadSeeker // positioned at the start
Alt string
Caption string
User string
}
UploadFile describes one file to upload.
type UploadPolicy ¶ added in v0.4.0
type UploadPolicy struct {
MaxSize int64 // bytes; 0 means no limit
AllowedTypes []string // MIME patterns; empty means media.DefaultAllowedTypes
}
UploadPolicy limits what can be uploaded.