Documentation
¶
Overview ¶
internal/api/handlers/component.go
Index ¶
- Constants
- Variables
- func APIDocs(public bool) gin.HandlerFunc
- func AgentFunctionCatalog(c *gin.Context)
- func ApproveProposal(c *gin.Context)
- func CreateAPIToken(c *gin.Context)
- func CreateAgent(c *gin.Context)
- func CreateCollection(c *gin.Context)
- func CreateComponent(c *gin.Context)
- func CreateConnection(c *gin.Context)
- func CreateLocale(c *gin.Context)
- func CreateOrUpdateSingleton(c *gin.Context)
- func CreateOrUpdateSingletonItem(c *gin.Context)
- func CreateRole(c *gin.Context)
- func CreateUser(c *gin.Context)
- func CreateWebhook(c *gin.Context)
- func DeleteAgent(c *gin.Context)
- func DeleteCollection(c *gin.Context)
- func DeleteComponent(c *gin.Context)
- func DeleteConnection(c *gin.Context)
- func DeleteItem(ct models.Collection) gin.HandlerFunc
- func DeleteLocale(c *gin.Context)
- func DeleteMedia(c *gin.Context)
- func DeleteRole(c *gin.Context)
- func DeleteSingleton(c *gin.Context)
- func DeleteUser(c *gin.Context)
- func DeleteWebhook(c *gin.Context)
- func DynamicCollectionHandler(c *gin.Context)
- func GetAPIToken(c *gin.Context)
- func GetAgent(c *gin.Context)
- func GetAgentRun(c *gin.Context)
- func GetAgentUsage(c *gin.Context)
- func GetAgents(c *gin.Context)
- func GetAllUsers(c *gin.Context)
- func GetCollection(c *gin.Context)
- func GetCollections(c *gin.Context)
- func GetComponent(c *gin.Context)
- func GetComponents(c *gin.Context)
- func GetConnection(c *gin.Context)
- func GetItemByID(ct models.Collection, id uint, rc readContext) gin.HandlerFunc
- func GetItems(collection models.Collection, rc readContext) gin.HandlerFunc
- func GetMedia(c *gin.Context)
- func GetOverview(c *gin.Context)
- func GetProposal(c *gin.Context)
- func GetRole(c *gin.Context)
- func GetSingleItem(c *gin.Context)
- func GetSingleton(c *gin.Context)
- func GetSingletons(c *gin.Context)
- func GetUser(c *gin.Context)
- func GetWebhook(c *gin.Context)
- func GraphQLHandler(c *gin.Context)
- func HandleWebhook(c *gin.Context)
- func InitQueue(client queue.Client)
- func ListAPITokens(c *gin.Context)
- func ListAgentRuns(c *gin.Context)
- func ListAgentTemplates(c *gin.Context)
- func ListAllAgentRuns(c *gin.Context)
- func ListConnectionPresets(c *gin.Context)
- func ListConnections(c *gin.Context)
- func ListLocales(c *gin.Context)
- func ListMedia(c *gin.Context)
- func ListProposals(c *gin.Context)
- func ListRevisions(c *gin.Context)
- func ListRoles(c *gin.Context)
- func ListWebhookDeliveries(c *gin.Context)
- func ListWebhooks(c *gin.Context)
- func Login(c *gin.Context)
- func Me(c *gin.Context)
- func OpenAPISpec(c *gin.Context)
- func PublishItem(publish bool) gin.HandlerFunc
- func RefreshConnection(c *gin.Context)
- func Register(c *gin.Context)
- func RejectProposal(c *gin.Context)
- func RenderAgentTemplate(c *gin.Context)
- func RevertAgentRun(c *gin.Context)
- func RevokeAPIToken(c *gin.Context)
- func RunAgentNow(c *gin.Context)
- func ServeLocalMedia(store *media.Local) gin.HandlerFunc
- func TestAgent(c *gin.Context)
- func TestWebhook(c *gin.Context)
- func UpdateAgent(c *gin.Context)
- func UpdateCollection(c *gin.Context)
- func UpdateComponent(c *gin.Context)
- func UpdateConnection(c *gin.Context)
- func UpdateItem(collection models.Collection) gin.HandlerFunc
- func UpdateLocale(c *gin.Context)
- func UpdateMedia(c *gin.Context)
- func UpdateRole(c *gin.Context)
- func UpdateUser(c *gin.Context)
- func UpdateWebhook(c *gin.Context)
- func UploadMedia(c *gin.Context)
- type LoginAttemptGuard
Constants ¶
const ( // RegistrationDisabled refuses self-registration: accounts are created // by an admin (POST /admin/users), the configuration (admin.*) or the // `gohead admin create` command. RegistrationDisabled = "disabled" // RegistrationOpen lets anyone create an account with the // DefaultRegistrationRole. RegistrationOpen = "open" )
Registration modes for POST /auth/register.
const DefaultRegistrationRole = "viewer"
DefaultRegistrationRole is the role given to self-registered accounts.
Variables ¶
var ( ListItemRevisions = listHistory(itemTarget) GetItemRevision = getHistoryRevision(itemTarget) RestoreItemRevision = restoreHistoryRevision(itemTarget) ListSingletonRevisions = listHistory(singletonTarget) GetSingletonRevision = getHistoryRevision(singletonTarget) RestoreSingletonRevision = restoreHistoryRevision(singletonTarget) )
Item and singleton history routes.
var APIVersion = "dev"
APIVersion is reported in the OpenAPI document (set at startup).
var MediaPolicy = storage.UploadPolicy{MaxSize: 50 << 20}
MediaPolicy limits uploads; set at startup from the media configuration.
var Registration = RegistrationDisabled
Registration is the current registration mode, set at startup from auth.registration.
var SchemaNotifier interface { Notify(ctx context.Context) error }
SchemaNotifier tells other API replicas that the schema changed. It is set at startup (see cmd/start.go); nil means single-replica mode.
Functions ¶
func APIDocs ¶ added in v0.5.0
func APIDocs(public bool) gin.HandlerFunc
APIDocs serves Swagger UI for /api/openapi.json. When the spec needs a token, the page asks for one and keeps it for the browser session only.
func AgentFunctionCatalog ¶ added in v0.5.0
AgentFunctionCatalog lists the built-in functions agents can use.
func ApproveProposal ¶ added in v0.6.0
ApproveProposal applies a proposal. Body (optional): {"data": {…}} to apply edited values instead of the agent's, {"force": true} to apply it although the item changed since. The change needs the caller's own permissions (publish to change a published item, create in the collections a relation object would create items in).
func CreateAPIToken ¶ added in v0.5.0
CreateAPIToken creates a token and returns its secret once: {"name": "website", "role": "viewer", "expires_in_days": 90}.
func CreateCollection ¶
CreateCollection handles creating a new collection.
func CreateComponent ¶
CreateComponentHandler creates a new component definition.
func CreateConnection ¶ added in v0.7.0
CreateConnection adds a connection and lists its tools.
func CreateLocale ¶ added in v0.5.0
CreateLocale adds a locale (admin).
func CreateOrUpdateSingleton ¶
CreateOrUpdateSingleton handles the creation or updating of a single type.
func CreateOrUpdateSingletonItem ¶
CreateOrUpdateSingletonItem creates or replaces a singleton's content. Requires the update permission.
func CreateRole ¶ added in v0.5.0
CreateRole adds a custom role (admin).
func CreateUser ¶
CreateUser lets an admin create an account with any existing role.
func CreateWebhook ¶ added in v0.5.0
CreateWebhook registers a webhook. The signing secret is returned once.
func DeleteAgent ¶
DeleteAgent handles deleting an agent by its name.
func DeleteCollection ¶
DeleteCollectionByIDHandler handles deleting a collection by its ID.
func DeleteComponent ¶
DeleteComponentHandler deletes a component by name.
func DeleteConnection ¶ added in v0.7.0
DeleteConnection removes a connection. Agents that use its tools get an error when they call them.
func DeleteItem ¶
func DeleteItem(ct models.Collection) gin.HandlerFunc
func DeleteLocale ¶ added in v0.5.0
DeleteLocale removes a locale (admin). Content in it is deleted with ?purge=true; without it the request fails with 409 when there is some.
func DeleteMedia ¶ added in v0.4.0
DeleteMedia removes a file and its content. Requires the delete permission.
func DeleteRole ¶ added in v0.5.0
DeleteRole removes a custom role no account or token uses (admin).
func DeleteSingleton ¶
DeleteSingleton handles deleting a single type by its name (optional).
func DeleteWebhook ¶ added in v0.5.0
DeleteWebhook removes a webhook and its delivery log.
func DynamicCollectionHandler ¶
DynamicCollectionHandler handles CRUD operations for dynamic collections.
func GetAgentRun ¶ added in v0.5.0
GetAgentRun returns one run with its steps.
func GetAgentUsage ¶ added in v0.5.0
GetAgentUsage reports an agent's usage over the last hour and day next to its limits.
func GetCollection ¶
func GetCollections ¶
GetCollections retrieves a list of collections with optional filtering, sorting, and pagination.
func GetComponent ¶
GetComponentHandler retrieves a component by name.
func GetComponents ¶
GetComponents lists all component definitions.
func GetConnection ¶ added in v0.7.0
GetConnection returns a connection with its tools.
func GetItemByID ¶
func GetItemByID(ct models.Collection, id uint, rc readContext) gin.HandlerFunc
GetItemByID retrieves a single item by ID.
func GetItems ¶
func GetItems(collection models.Collection, rc readContext) gin.HandlerFunc
GetItems lists a collection's items with pagination, filtering and sorting.
Query parameters:
page, pageSize pagination (pageSize max 100) filters[<field>][<op>]=<value> op: $eq $ne $lt $lte $gt $gte $contains filters[<field>]=<value> shorthand for $eq sort=<field>[:asc|:desc],... multiple keys allowed status=published|draft|all draft-and-publish collections (default published)
<field> is a collection attribute or one of id, createdAt, updatedAt, publishedAt (snake_case also accepted).
func GetMedia ¶ added in v0.4.0
GetMedia returns one media file. Requires the media read permission, like ListMedia.
func GetOverview ¶ added in v0.5.0
GetOverview returns counts and recent activity for the admin dashboard.
func GetProposal ¶ added in v0.6.0
GetProposal returns a proposal with the item as it is now, the values approving it would write ("proposed": for a stale update, the item now with the agent's changes) and the changes between the two.
func GetSingleItem ¶
GetSingleItem returns a singleton's content in the flat item shape, with relations populated down to "level" (default 1).
func GetSingleton ¶
GetSingleton retrieves a single type by its name.
func GetSingletons ¶
GetSingletons lists all singleton definitions.
func GraphQLHandler ¶
GraphQLHandler executes a GraphQL request. The caller's role is passed to resolvers through the context so that queries and mutations enforce the same permissions as the REST API.
func HandleWebhook ¶
HandleWebhook is the Gin handler for incoming agent webhook requests.
func ListAPITokens ¶ added in v0.5.0
ListAPITokens lists tokens (never their secrets).
func ListAgentRuns ¶ added in v0.5.0
ListAgentRuns lists an agent's runs, newest first: page, pageSize (≤ 100) and status (running, succeeded, failed, limited).
func ListAgentTemplates ¶ added in v0.6.0
ListAgentTemplates lists the ready-made agents and their parameters.
func ListAllAgentRuns ¶ added in v0.5.0
ListAllAgentRuns lists the runs of every agent, newest first: page, pageSize (≤ 100) and status.
func ListConnectionPresets ¶ added in v0.7.0
ListConnectionPresets lists the services the admin UI offers to connect.
func ListConnections ¶ added in v0.7.0
ListConnections lists the connections.
func ListLocales ¶ added in v0.5.0
ListLocales lists the content locales, the default first. Any signed-in user can read them.
func ListMedia ¶ added in v0.4.0
ListMedia lists the media library: page, pageSize, mime (type prefix such as "image/") and search (file name). Browsing the library needs the media read permission (not given to viewers): it includes files only drafts use, so readers only reach files through the content that references them.
func ListProposals ¶ added in v0.6.0
ListProposals lists proposals, newest first: status (pending by default; approved, rejected, failed or all), collection, agent, agentRun, page, pageSize. Only collections the caller may change are listed.
func ListRevisions ¶ added in v0.5.0
ListRevisions is the change feed across entries, newest first. Filters: collection, singleton, action, actorKind, actor, agentRun.
func ListWebhookDeliveries ¶ added in v0.5.0
ListWebhookDeliveries returns the newest delivery attempts (limit ≤ 100).
func OpenAPISpec ¶ added in v0.5.0
OpenAPISpec serves the OpenAPI 3.1 description of the current content model. It is written directly (not wrapped in {"data": …}), as tools expect.
func PublishItem ¶ added in v0.4.0
func PublishItem(publish bool) gin.HandlerFunc
PublishItem publishes (publish=true) or unpublishes an item of a draft-and-publish collection: POST /api/collections/:collection/:id/publish and /unpublish. Requires the update permission.
func RefreshConnection ¶ added in v0.7.0
RefreshConnection lists a connection's tools again.
func Register ¶
Register creates a new account through the public endpoint, when registration is open. The caller never chooses its role: accounts get the least-privileged DefaultRegistrationRole, and admins promote users through PUT /admin/users/:id. No account is ever made admin here.
func RejectProposal ¶ added in v0.6.0
RejectProposal discards a proposal. Body (optional): {"note": "…"}.
func RenderAgentTemplate ¶ added in v0.6.0
RenderAgentTemplate builds an agent definition from a template. Body: {"params": {…}}. The definition is not saved: review it, then create it with POST /admin/agents.
func RevertAgentRun ¶ added in v0.5.0
RevertAgentRun undoes the content changes of one of an agent's runs. Entries changed by someone else since are skipped unless ?force=true.
func RevokeAPIToken ¶ added in v0.5.0
RevokeAPIToken revokes a token immediately.
func RunAgentNow ¶ added in v0.5.0
RunAgentNow queues a manual run of an agent, with an optional "input" message. The run appears in the agent's run history.
func ServeLocalMedia ¶ added in v0.4.0
func ServeLocalMedia(store *media.Local) gin.HandlerFunc
ServeLocalMedia serves files of the local driver under /uploads/<key>. Only files recorded in the media library are served, with their detected type, and with headers that stop browsers from running anything in them.
func TestAgent ¶ added in v0.6.0
TestAgent queues a test run (dry run): the agent runs for real (model calls, reads), but content functions only validate and report the changes they would make. Body: {"input": "…"} for a manual message, or {"item_id": 42, "event": "item:created"} to simulate the agent's collection event on an existing item.
func TestWebhook ¶ added in v0.5.0
TestWebhook sends a "webhook:test" event right away and reports the outcome, so the URL, headers and signature can be checked from the admin.
func UpdateCollection ¶
UpdateCollection handles updating an existing collection.
func UpdateComponent ¶
UpdateComponentHandler updates an existing component definition.
func UpdateConnection ¶ added in v0.7.0
UpdateConnection changes a connection and lists its tools again.
func UpdateItem ¶
func UpdateItem(collection models.Collection) gin.HandlerFunc
UpdateItem replaces an item's data. The body's optional "status" publishes or unpublishes it in draft-and-publish collections.
func UpdateLocale ¶ added in v0.5.0
UpdateLocale renames a locale, and makes it the default with {"isDefault": true} (admin).
func UpdateMedia ¶ added in v0.4.0
UpdateMedia changes a file's name, alt text or caption: {"data": {"alt": "…"}}. Requires the update permission.
func UpdateRole ¶ added in v0.5.0
UpdateRole replaces a custom role's description and permissions (admin).
func UpdateUser ¶
UpdateUser lets an admin change a user's username, email, password or role. Unknown fields are rejected so that arbitrary columns cannot be written.
func UpdateWebhook ¶ added in v0.5.0
UpdateWebhook changes a webhook; "rotate_secret": true issues a new secret.
func UploadMedia ¶ added in v0.4.0
UploadMedia stores the files of a multipart/form-data request (fields "files" or "file"; optional "alt" and "caption"). Requires the create permission. All files are stored, or none.
Types ¶
type LoginAttemptGuard ¶
LoginAttemptGuard limits failed logins per (username, client IP) within a window. Keying on both stops password guessing against an account without letting anyone lock a user out from another address.
var LoginGuard *LoginAttemptGuard
LoginGuard is set at startup; nil disables the check.