Function API
Common Types
type JSONValue = json.RawMessage
type JSONSchema = json.RawMessage
type FormPresentationSpec = json.RawMessage
type OpenAPIOperation = json.RawMessageNotes:
JSONValueonly represents the business payload or a function return value; its structure must be constrained by the function'sinputSchema/outputSchema.JSONSchemaonly represents a JSON Schema / OpenAPI Schema.FormPresentationSpecrepresents the controlled presentation configuration of a JSON Schema form; it must not carry page layout, menus, or arbitrary component props.OpenAPIOperationis for contract viewing only; it is not used to generate runtime console pages directly.json.RawMessageis only the JSON carrier type at the HTTP boundary; the server must complete structural validation before saving or executing.
1. "List functions"
- route definition
- Url: /api/v1/functions
- Method: GET
- Request:
FunctionsListRequest - Response:
FunctionsListResponse
- request definition
type FunctionsListRequest struct {
Page int `form:"page,optional,default=1"`
PageSize int `form:"pageSize,optional,default=20"`
GameId string `form:"gameId,optional"`
Resource string `form:"resource,optional"`
Status int `form:"status,optional"`
}- response definition
type FunctionsListResponse struct {
Items []Function `json:"items"`
Total int64 `json:"total"`
Page int `json:"page"`
Size int `json:"pageSize"`
}2. "Get function details"
- route definition
- Url: /api/v1/functions/:id
- Method: GET
- Request:
FunctionDetailRequest - Response:
FunctionDetailResponse
- request definition
type FunctionDetailRequest struct {
ID string `path:"id"`
}- response definition
type FunctionDetailResponse struct {
Id string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Resource string `json:"resource"`
GameId string `json:"gameId"`
Status int `json:"status"`
Version string `json:"version"`
Instances int `json:"instances"`
SpecFormat string `json:"specFormat"`
Tags []string `json:"tags,omitempty"`
Summary map[string]string `json:"summary,omitempty"`
OpenAPISpec json.RawMessage `json:"openapiSpec,omitempty"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
Descriptor FunctionDescriptor `json:"descriptor"`
}
type Function struct {
Id string `json:"id"`
Name string `json:"name"`
Description string `json:"description"`
Resource string `json:"resource"`
GameId string `json:"gameId"`
Status int `json:"status"`
Version string `json:"version"`
Instances int `json:"instances"`
SpecFormat string `json:"specFormat"`
Tags []string `json:"tags,omitempty"`
Summary map[string]string `json:"summary,omitempty"`
OpenAPISpec json.RawMessage `json:"openapiSpec,omitempty"`
CreatedAt string `json:"createdAt"`
UpdatedAt string `json:"updatedAt"`
}
type FunctionDescriptor struct {
Input JSONSchema `json:"input"`
Output JSONSchema `json:"output"`
Schema JSONSchema `json:"schema"`
}3. "Delete a function"
- route definition
- Url: /api/v1/functions/:id
- Method: DELETE
- Request:
FunctionActionRequest - Response:
-
- request definition
type FunctionActionRequest struct {
ID string `path:"id"`
}- response definition
4. "Copy a function"
- route definition
- Url: /api/v1/functions/:id/copy
- Method: POST
- Request:
FunctionCopyRequest - Response:
FunctionCopyResponse
- request definition
type FunctionCopyRequest struct {
ID string `path:"id"`
}- response definition
type FunctionCopyResponse struct {
FunctionId string `json:"functionId"`
NewId string `json:"newId"`
}5. "Disable a function"
- route definition
- Url: /api/v1/functions/:id/disable
- Method: POST
- Request:
FunctionActionRequest - Response:
-
- request definition
type FunctionActionRequest struct {
ID string `path:"id"`
}- response definition
6. "Enable a function"
- route definition
- Url: /api/v1/functions/:id/enable
- Method: POST
- Request:
FunctionActionRequest - Response:
-
- request definition
type FunctionActionRequest struct {
ID string `path:"id"`
}- response definition
7. "Get function instances"
- route definition
- Url: /api/v1/functions/:id/instances
- Method: GET
- Request:
FunctionInstancesRequest - Response:
FunctionInstancesResponse
- request definition
type FunctionInstancesRequest struct {
ID string `path:"id"`
}- response definition
type FunctionInstancesResponse struct {
Items []FunctionInstance `json:"items"`
}Cross-instance aggregation (cluster mode): this endpoint and GET /api/v1/functions/instances both treat the shared ownership table (cluster_agent_owners) as the online universe — agents held by peer server instances count too, with details read from the shared agent_sessions snapshot table. Entries owned by a peer instance carry an ownerInstance field (covering two cases: those absent from the local registry and recovered via the snapshot table, and those present locally but owned by a peer in the DB snapshot — the latter backfilled by the 30s-periodic refreshRemoteSnapshots, not directly connected to this instance); the field is absent for agents this instance owns or connects to directly. When the ownership table is unreachable, it silently falls back to this instance's view (everything rendered as local). Single-instance deployments (cluster.enabled=false) behave unchanged (purely local).
8. "Invoke a function"
- route definition
- Url: /api/v1/functions/:id/invoke
- Method: POST
- Request:
FunctionInvokeRequest - Response:
FunctionInvokeResponse
- request definition
type FunctionInvokeRequest struct {
ID string `path:"id"`
Params JSONValue `json:"params,optional"`
Payload JSONValue `json:"payload,optional"`
GameID string `json:"gameId,optional"` // compatibility field; the effective scope is the X-Game-ID/X-Env headers
Env string `json:"env,optional"` // compatibility field; the effective scope is the X-Game-ID/X-Env headers
Mode string `json:"mode,optional"`
Route string `json:"route,optional"`
TargetServiceID string `json:"targetServiceId,optional"`
HashKey string `json:"hashKey,optional"`
TimeoutMs int `json:"timeoutMs,omitempty"` // sync-only timeout budget in ms ([1000,60000], clamped)
}- response definition
type FunctionInvokeResponse struct {
TaskId string `json:"taskId"`
Result JSONValue `json:"result,omitempty"`
ApprovalID string `json:"approvalId,omitempty"` // approval request ID (returned when approval is required)
ApprovalRequired bool `json:"approvalRequired,omitempty"` // whether approval is required
ApprovalWorkflow string `json:"approvalWorkflow,omitempty"` // approval workflow type (single_admin/two_person)
TraceID string `json:"traceId,omitempty"` // OTel trace ID for Jaeger/Grafana jump
Broadcast *BroadcastResult `json:"broadcast,omitempty"` // per-agent outcomes when route=broadcast
}Notes:
- When the function policy requires approval (
RequireApproval=true), the invocation creates an approval request and returnsApprovalID - An invocation requiring approval does not execute immediately; it waits until the approval passes
ApprovalWorkflowindicates the approval workflow type:single_admin: a single administrator's approval sufficestwo_person: two-person approval required
Route parameter validation (behavior change 2026-09-11): the following cases return 400 validation_failed directly before the policy check, no longer silently falling back to the default route:
route: "targeted"withouttargetServiceIdroute: "hash"withouthashKeyroute: "broadcast"combined withmode: "async"(broadcast has no async semantics)- an invalid
routevalue (valid:lb(default)/targeted/hash/broadcast)
Error semantics:
503 service_unavailable: no available agent (no candidates in either the local or the shared ownership table) or failover exhausted all candidates (same semantics for synchronous andmode: async; lb routing retries up to 3 candidate switches, targeted/hash designate a unique target and do not retry) — retryable (self-heals after agents re-register or the ownership table TTL expires); in multi-instance deployments, when a remote candidate is chosen, the call forwards over the mesh to the owner instance, transparent to the caller400 validation_failed: missing/conflicting route parameters (see above), withdetailscarrying the specific fields
9. "Get function permissions"
- route definition
- Url: /api/v1/functions/:id/permissions
- Method: GET
- Request:
FunctionPermissionsRequest - Response:
FunctionPermissionsResponse
- request definition
type FunctionPermissionsRequest struct {
ID string `path:"id"`
}- response definition
type FunctionPermissionsResponse struct {
Items []FunctionPermission `json:"items"`
}10. "Update function permissions"
- route definition
- Url: /api/v1/functions/:id/permissions
- Method: PUT
- Request:
FunctionPermissionsUpdateRequest - Response:
FunctionPermissionsResponse
- request definition
type FunctionPermissionsUpdateRequest struct {
ID string `path:"id"`
Permissions []FunctionPermission `json:"permissions"`
}- response definition
type FunctionPermissionsResponse struct {
Items []FunctionPermission `json:"items"`
}11. "Publish a function"
- route definition
- Url: /api/v1/functions/:id/publish
- Method: POST
- Request:
FunctionPublishRequest - Response:
FunctionPublishResponse
- request definition
type FunctionPublishRequest struct {
ID string `path:"id"`
}- response definition
type FunctionPublishResponse struct {
ApprovalId string `json:"approvalId,omitempty"` // when approval is required
Published bool `json:"published"`
}12. "Batch copy functions"
- route definition
- Url: /api/v1/functions/batch-copy
- Method: POST
- Request:
BatchCopyFunctionsRequest - Response:
BatchCopyFunctionsResponse
- request definition
type BatchCopyFunctionsRequest struct {
Functions []FunctionCopyRequest `json:"functions"`
}- response definition
type BatchCopyFunctionsResponse struct {
Results []FunctionCopyResponse `json:"results"`
}17. "Batch delete functions"
- route definition
- Url: /api/v1/functions/batch-delete
- Method: POST
- Request:
BatchDeleteFunctionsRequest - Response:
BatchDeleteFunctionsResponse
- request definition
type BatchDeleteFunctionsRequest struct {
FunctionIds []string `json:"functionIds"`
}- response definition
type BatchDeleteFunctionsResponse struct {
Deleted []string `json:"deleted"`
Failed []string `json:"failed"`
}18. "Batch update function status"
- route definition
- Url: /api/v1/functions/batch-update
- Method: POST
- Request:
BatchUpdateFunctionsRequest - Response:
BatchUpdateFunctionsResponse
- request definition
type BatchUpdateFunctionsRequest struct {
FunctionIds []string `json:"functionIds"`
Enabled bool `json:"enabled"`
}- response definition
type BatchUpdateFunctionsResponse struct {
Updated int `json:"updated"`
Failed []string `json:"failed"`
}19. "List function descriptors"
- route definition
- Url: /api/v1/functions/descriptors
- Method: GET
- Request:
DescriptorsRequest - Response:
DescriptorsResponse
- request definition
type DescriptorsRequest struct {
Type string `form:"type,optional"`
GameId string `form:"gameId,optional"`
}- response definition
type DescriptorsResponse struct {
Items []Descriptor `json:"items"`
}20. "List pending functions"
- route definition
- Url: /api/v1/functions/pending
- Method: GET
- Request:
FunctionsPendingRequest - Response:
FunctionsPendingResponse
- request definition
type FunctionsPendingRequest struct {
}- response definition
type FunctionsPendingResponse struct {
Items []PendingFunction `json:"items"`
}21. "Batch fetch function OpenAPI"
- route definition
- Url: /api/v1/functions/_openapi-batch
- Method: POST
- Request:
BatchGetSpecRequest - Response:
map[string]OpenAPIOperation
- request definition
type BatchGetSpecRequest struct {
FunctionIDs []string `json:"function_ids"`
}- response definition
// key is the function id, value the corresponding OpenAPI Operation; returns null when not found
map[string]OpenAPIOperationNotes
- This endpoint lets the Dashboard batch-read function OpenAPI instead of requesting one by one.
- The current return value passes through the OpenAPI operation objects stored in the registry verbatim.
22. "Get function contract change history"
- route definition
- Url: /api/v1/functions/:id/versions
- Method: GET
- Request: query
page/pageSize - Response:
ContractVersionsResult
- response definition
type ContractVersionDiffEntry struct {
Field string `json:"field"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
Change string `json:"change,omitempty"` // e.g. schema_replaced
Findings []schemadiff.Finding `json:"findings,omitempty"`
}
type ContractVersionItem struct {
Seq int64 `json:"seq"`
Version string `json:"version,omitempty"`
Source string `json:"source,omitempty"`
SourceDigest string `json:"sourceDigest,omitempty"`
ChangeType string `json:"changeType"` // created|updated|removed
Breaking bool `json:"breaking"`
Actor string `json:"actor,omitempty"`
CreatedAt string `json:"createdAt"`
Diff []ContractVersionDiffEntry `json:"diff,omitempty"`
}
type ContractVersionsResult struct {
Items []ContractVersionItem `json:"items"`
Total int64 `json:"total"`
Page int `json:"page"`
Size int `json:"size"`
}23. "Get a function contract version snapshot"
- route definition
- Url: /api/v1/functions/:id/versions/:seq
- Method: GET
- Response:
ContractVersionDetailResult(ContractVersionItem+snapshot; snapshot is the post-change FunctionSpec projection; 404 when absent)
24. "Diff two function contract versions"
- route definition
- Url: /api/v1/functions/:id/versions/diff
- Method: GET
- Request: query
from/to(version seq) - Response:
ContractVersionDiffResult
type ContractVersionDiffResult struct {
FromSeq int64 `json:"fromSeq"`
ToSeq int64 `json:"toSeq"`
Breaking bool `json:"breaking"`
Changes []ContractVersionDiffEntry `json:"changes"`
}Notes (version history)
- The criterion is exactly
UpsertContract's "skip write when content is unchanged" (the samecontractSemanticallyEqual): re-registering identical content produces no history. - Per-function retention cap
FunctionContractVersionRetention(currently 50); the oldest entries are evicted beyond it. - History write failures degrade to a warning and do not block registration (derived audit data; the table's existence is guaranteed by goose 0029 + startup
MinimumRequiredVersion=29). seqhas no unique index (concurrent registrations across instances may tie; reads sort stably byseq DESC, id DESC).
25. "Get all function version floors"
- route definition
- Url: /api/v1/functions/version-floors
- Method: GET
- Response: all configured floors under the current game/env (functions without one are absent from the response)
type versionFloorsListResponse struct {
Floors map[string]string `json:"floors"` // functionId -> minVersion
}26. "Batch set/clear function version floors"
- route definition
- Url: /api/v1/functions/version-floor/batch
- Method: POST
- Permission:
functions:manage(same as the single-function PUT/DELETE) - Request:
type versionFloorBatchRequest struct {
FunctionIds []string `json:"functionIds" binding:"required"` // empty after trim + dedup returns 400
MinVersion string `json:"minVersion"` // empty string = batch clear (equivalent to per-function DELETE)
}- Response: partial-success semantics (per-function Set/Delete loop, each idempotent and retryable, no transaction)
type versionFloorBatchResponse struct {
Updated int `json:"updated"`
Failed []string `json:"failed"`
MinVersion string `json:"minVersion,omitempty"` // echoes the value set this time
}27. "Get the function version history index"
- route definition
- Url: /api/v1/functions/version-history
- Method: GET
- Response: every contract version each function has historically appeared under, for the current game/env (feeds the version-floor dropdown, OPEN-ISSUES #26; functions with no history are absent from the response)
type functionVersionIndexResponse struct {
Items []struct {
FunctionID string `json:"functionId"` // lexicographic order
Versions []string `json:"versions"` // semver descending numerically, unparseable versions last
} `json:"items"`
}The data source is a distinct aggregation over function_contract_versions (30s TTL in-memory cache, no write invalidation — optional data with a bounded staleness window, following the resource-category aggregation precedent).
Notes (version floors)
- A function-level version floor is "the minimum function version configurable per function in the UI" (compared against the function descriptor's own version, unrelated to the SDK version); the decision semantics are in
docs/architecture/data-flow.md§ "Function-level minimum version (per-function UI configuration)". - Single-function endpoints:
GET/PUT/DELETE /api/v1/functions/:id/version-floor(PUT body{minVersion}, writes needfunctions:manage; DELETE physically removes the row). - For a non-empty batch minVersion, the server first validates the whole batch as parseable (
sdkversion.Parseable); on invalid input it returns 400 with zero writes. - Version floors persist in the game database's
function_version_floorstable (numbered migration 0030); the in-memory registry (no DB) degrades to a process-local map.
Function Policy API (not wired)
The function policy (GET/PUT/DELETE /api/v1/functions/:function_id/policy) and system policy (/api/v1/policies/*) endpoints are currently not registered in the effective routes (internal/handler/routes.go; the parallel registration file mentioned by earlier docs was removed when routes were consolidated) and are not served. Policy behavior is carried by the function contract's risk/approval fields and the execution chain's governance; this section's historical documentation has been deleted and will be restored once the endpoints are wired.
Supplementary Endpoints
The following registered endpoints are part of the function domain's canonical set:
GET /api/v1/functions/{id}/analytics # function invocation analytics
GET /api/v1/functions/{id}/history # function change history (paginated, newest-first)
GET /api/v1/functions/{id}/version-floor # single-function version floor (GET/PUT/DELETE)
GET /api/v1/functions/instances # all function instances
GET /api/v1/functions/warnings # registration warning list
GET /api/v1/functions/warnings/filter-options # warning filter dropdown options (#34)
DELETE /api/v1/functions/warnings/{key} # dismiss one warning
POST /api/v1/functions/warnings/read/{key} # mark one warning read
POST /api/v1/functions/warnings/read-all # mark all warnings read
DELETE /api/v1/functions/warnings # clear all warnings
GET /api/v1/functions/version-floors # all function version floors
GET /api/v1/functions/version-history # function version history index (floor dropdown options, #26)
GET /api/v1/functions/:id/openapi # function OpenAPI spec (public)
POST /api/v1/functions/_openapi-batch # batch-fetch OpenAPI specs (public)
GET /api/v1/openapi/spec # global OpenAPI document (public)