permission

package
v0.1.21 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package permission is the capability boundary for human-in-the-loop decisions routed through the inbound platform (tool approval, ask_user, etc.).

Index

Constants

View Source
const DefaultTimeout = 10 * time.Minute

DefaultTimeout is the wait limit when Request.Timeout and Capability.DefaultTimeout are both unset.

Variables

This section is empty.

Functions

func EffectiveTimeout

func EffectiveTimeout(req Request, cap Capability) time.Duration

EffectiveTimeout resolves the wait limit for an interactive permission request.

func MarshalReply

func MarshalReply(reply Reply) json.RawMessage

func UnrecognizedAllowDenyReason

func UnrecognizedAllowDenyReason(reply Reply) string

UnrecognizedAllowDenyReason formats a reason for an unrecognized allow/deny reply.

Types

type AllowDenyMatch

type AllowDenyMatch struct {
	Allow        bool
	Recognized   bool
	UpdatedInput map[string]any
}

AllowDenyMatch is the parsed allow/deny reply.

func MatchAllowDeny

func MatchAllowDeny(reply Reply) AllowDenyMatch

MatchAllowDeny parses a KindAllowDeny reply. Decision takes precedence; Text is a CLI fallback when Decision is empty.

type AnswerScope

type AnswerScope string
const (
	ScopeAsker  AnswerScope = "asker"
	ScopeAnyone AnswerScope = "anyone"
)

type Broker

type Broker interface {
	Await(context.Context, Request) (Result, error)
}

func BrokerFrom

func BrokerFrom(ctx context.Context) (Broker, bool)

type Capability

type Capability struct {
	Interactive    bool
	MultiSelect    bool
	DefaultTimeout time.Duration
	AnswerScope    AnswerScope
}

Capability describes how a platform renders and collects permission replies.

func CapabilityFrom

func CapabilityFrom(ctx context.Context) Capability

type CapabilityRouter

type CapabilityRouter interface {
	PermissionCapabilityFor(platformID string) Capability
}

CapabilityRouter is implemented by platforms that aggregate multiple leaf platforms.

type Capable

type Capable interface {
	PermissionCapability() Capability
}

Capable is implemented by leaf platforms that can render permission requests.

type Kind

type Kind string
const (
	KindAllowDeny Kind = "allow_deny"
	KindQuestion  Kind = "question"
)

type Option

type Option struct {
	Label       string `json:"label"`
	Description string `json:"description,omitempty"`
}

type Outcome

type Outcome string
const (
	OutcomeResolved   Outcome = "resolved"
	OutcomeTimeout    Outcome = "timeout"
	OutcomeNoHuman    Outcome = "no_human"
	OutcomeCancelled  Outcome = "cancelled"
	OutcomeSuperseded Outcome = "superseded"
)

type Question

type Question struct {
	Prompt      string   `json:"prompt"`
	Header      string   `json:"header,omitempty"`
	Options     []Option `json:"options,omitempty"`
	Default     string   `json:"default,omitempty"`
	MultiSelect bool     `json:"multiSelect,omitempty"`
}

type QuestionResult

type QuestionResult struct {
	Text     string `json:"text,omitempty"`
	Selected []int  `json:"selected,omitempty"`
}

func MatchReply

func MatchReply(reply Reply, q Question) QuestionResult

MatchReply resolves a KindQuestion reply against a question. Uses Selected and Text only; Decision is ignored.

type Reply

type Reply struct {
	RequestID string `json:"requestId"`
	UserID    string `json:"userId,omitempty"`
	// Decision is for KindAllowDeny only ("allow"/"deny", or y/n/yes/no).
	Decision     string         `json:"decision,omitempty"`
	Selected     []int          `json:"selected,omitempty"`
	Text         string         `json:"text,omitempty"`
	UpdatedInput map[string]any `json:"updatedInput,omitempty"`
	Cancelled    bool           `json:"cancelled,omitempty"`
}

Reply is the inbound answer to a permission/request.

Field usage by request Kind:

  • KindAllowDeny: Decision ("allow"/"deny", or y/n/yes/no); Text is a CLI fallback when Decision is empty. UpdatedInput carries human-edited tool arguments. Cancelled means the user explicitly declined.
  • KindQuestion: Text and/or Selected only; do not set Decision.

func DecodeReply

func DecodeReply(raw json.RawMessage) (Reply, error)

type Request

type Request struct {
	ID       string             `json:"id"`
	Kind     Kind               `json:"kind"`
	Reason   string             `json:"reason,omitempty"`
	ToolCall *agentkit.ToolCall `json:"toolCall,omitempty"`
	Question *Question          `json:"question,omitempty"`
	Timeout  time.Duration      `json:"timeout,omitempty"`
	AskedBy  string             `json:"askedBy,omitempty"`
}

type RequestPayload

type RequestPayload struct {
	Request
}

RequestPayload is emitted on permission/request.

type Result

type Result struct {
	ID           string          `json:"id,omitempty"`
	Outcome      Outcome         `json:"outcome"`
	Allow        bool            `json:"allow,omitempty"`
	Answer       *QuestionResult `json:"answer,omitempty"`
	UpdatedInput map[string]any  `json:"updatedInput,omitempty"`
	Reason       string          `json:"reason,omitempty"`
	Guidance     string          `json:"guidance,omitempty"`
}

Result is the outcome of Broker.Await. ID is set on permission/resolved events.

func Cancelled

func Cancelled(req Request, reason string) Result

func NoHuman

func NoHuman(req Request, reason string) Result

func Superseded

func Superseded(req Request, reason string) Result

func TimedOut

func TimedOut(req Request) Result

func (Result) Resolved

func (r Result) Resolved() bool

Jump to

Keyboard shortcuts

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