agent

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Agent

type Agent struct {
	ID          string                 `json:"id"`
	OrgID       *string                `json:"org_id,omitempty"`
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	Type        string                 `json:"type"`
	OwnerID     *string                `json:"owner_id,omitempty"`
	Status      string                 `json:"status"`
	Metadata    map[string]interface{} `json:"metadata"`
	CreatedAt   time.Time              `json:"created_at"`
	UpdatedAt   time.Time              `json:"updated_at"`
}

type AgentToken

type AgentToken struct {
	ID          string                 `json:"id"`
	AgentID     string                 `json:"agent_id"`
	Name        string                 `json:"name"`
	Scopes      []string               `json:"scopes"`
	Permissions map[string]interface{} `json:"permissions"`
	ExpiresAt   *time.Time             `json:"expires_at,omitempty"`
	LastUsedAt  *time.Time             `json:"last_used_at,omitempty"`
	CreatedAt   time.Time              `json:"created_at"`
}

type CreateAgentRequest

type CreateAgentRequest struct {
	OrgID       *string                `json:"org_id"`
	Name        string                 `json:"name" validate:"required"`
	Description string                 `json:"description"`
	Type        string                 `json:"type" validate:"required"` // service, ai_agent, mcp_server
	OwnerID     *string                `json:"owner_id"`
	Metadata    map[string]interface{} `json:"metadata"`
}

type CreateAgentTokenRequest

type CreateAgentTokenRequest struct {
	Name        string                 `json:"name" validate:"required"`
	Scopes      []string               `json:"scopes"`
	Permissions map[string]interface{} `json:"permissions"`
	ExpiresAt   *time.Time             `json:"expires_at"`
}

type CreateAgentTokenResponse

type CreateAgentTokenResponse struct {
	AgentToken
	PlainToken string `json:"token"` // returned only once at creation
}

type CreateDelegationRequest

type CreateDelegationRequest struct {
	DelegateeAgentID string                 `json:"delegatee_agent_id" validate:"required"`
	Scopes           []string               `json:"scopes" validate:"required"`
	Constraints      map[string]interface{} `json:"constraints"`
	ExpiresAt        *time.Time             `json:"expires_at"`
}

type Delegation

type Delegation struct {
	ID               string                 `json:"id"`
	DelegatorID      string                 `json:"delegator_id"`
	DelegateeAgentID string                 `json:"delegatee_agent_id"`
	Scopes           []string               `json:"scopes"`
	Constraints      map[string]interface{} `json:"constraints"`
	Active           bool                   `json:"active"`
	CreatedAt        time.Time              `json:"created_at"`
	ExpiresAt        *time.Time             `json:"expires_at,omitempty"`
}

type DelegationRevoker

type DelegationRevoker interface {
	RevokeByDelegation(ctx context.Context, delegationID string) (int64, error)
}

DelegationRevoker cascades a delegation revocation to the live tokens minted from it. Satisfied by the revocation store; an interface keeps the agent package decoupled from it.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(service *Service, revoker DelegationRevoker) *Handler

func (*Handler) Create

func (h *Handler) Create(w http.ResponseWriter, r *http.Request)

func (*Handler) CreateDelegation

func (h *Handler) CreateDelegation(w http.ResponseWriter, r *http.Request)

func (*Handler) CreateToken

func (h *Handler) CreateToken(w http.ResponseWriter, r *http.Request)

func (*Handler) Get

func (h *Handler) Get(w http.ResponseWriter, r *http.Request)

func (*Handler) List

func (h *Handler) List(w http.ResponseWriter, r *http.Request)

func (*Handler) ListDelegations

func (h *Handler) ListDelegations(w http.ResponseWriter, r *http.Request)

func (*Handler) ListTokens

func (h *Handler) ListTokens(w http.ResponseWriter, r *http.Request)

func (*Handler) Revoke

func (h *Handler) Revoke(w http.ResponseWriter, r *http.Request)

func (*Handler) RevokeDelegation

func (h *Handler) RevokeDelegation(w http.ResponseWriter, r *http.Request)

func (*Handler) RevokeToken

func (h *Handler) RevokeToken(w http.ResponseWriter, r *http.Request)

func (*Handler) Routes

func (h *Handler) Routes() chi.Router

func (*Handler) Update

func (h *Handler) Update(w http.ResponseWriter, r *http.Request)

type Service

type Service struct {
	// contains filtered or unexported fields
}

func NewService

func NewService(pool *pgxpool.Pool) *Service

func (*Service) Create

func (s *Service) Create(ctx context.Context, req CreateAgentRequest) (*Agent, error)

func (*Service) CreateDelegation

func (s *Service) CreateDelegation(ctx context.Context, delegatorID, orgID string, req CreateDelegationRequest) (*Delegation, error)

CreateDelegation records a user's delegation to an agent. orgID is the delegatee agent's organization (resolved and authorized by the caller); it is stored so the delegation can be governed and audited per tenant.

func (*Service) CreateToken

func (s *Service) CreateToken(ctx context.Context, agentID string, req CreateAgentTokenRequest) (*CreateAgentTokenResponse, error)

func (*Service) GetByID

func (s *Service) GetByID(ctx context.Context, id string) (*Agent, error)

func (*Service) List

func (s *Service) List(ctx context.Context, orgIDs []string, includeAll bool, limit, offset int) ([]Agent, int64, error)

List returns agents visible to the caller. When includeAll is false (a non-superadmin), results are restricted to agents in the given organizations; org-less (global) agents are visible only to superadmins.

func (*Service) ListDelegationsByAgent

func (s *Service) ListDelegationsByAgent(ctx context.Context, agentID string) ([]Delegation, error)

func (*Service) ListTokens

func (s *Service) ListTokens(ctx context.Context, agentID string) ([]AgentToken, error)

func (*Service) Revoke

func (s *Service) Revoke(ctx context.Context, id string) error

func (*Service) RevokeDelegation

func (s *Service) RevokeDelegation(ctx context.Context, id, delegatorFilter string) (int64, error)

RevokeDelegation deactivates a delegation. When delegatorFilter is non-empty (a user revoking their own), the update is scoped to that delegator so one tenant cannot revoke another's delegation by guessing ids. Returns the number of rows affected so the caller can distinguish "not found / not yours" (0).

func (*Service) RevokeToken

func (s *Service) RevokeToken(ctx context.Context, agentID, tokenID string) error

RevokeToken deletes a token, binding it to its agent so a caller authorized for one agent cannot delete another agent's token by id.

func (*Service) Update

func (s *Service) Update(ctx context.Context, id string, req UpdateAgentRequest) (*Agent, error)

func (*Service) ValidateToken

func (s *Service) ValidateToken(ctx context.Context, plainToken string) (*Agent, *AgentToken, error)

ValidateToken validates an agent token and returns the agent. Used by the agent auth middleware.

type UpdateAgentRequest

type UpdateAgentRequest struct {
	Name        *string                `json:"name"`
	Description *string                `json:"description"`
	Metadata    map[string]interface{} `json:"metadata"`
}

Jump to

Keyboard shortcuts

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