decision

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: AGPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package decision holds app-layer decision DTOs and shared waiting primitives. Storage is intentionally still owned by the kind-specific services: toolapproval uses tool_approval_requests, and userinput uses user_input_requests.

Index

Constants

View Source
const (
	KindApproval  = "approval"
	KindUserInput = "user_input"
)
View Source
const DefaultFallbackInterval = 500 * time.Millisecond

Variables

This section is empty.

Functions

func InCreateTransaction

func InCreateTransaction(ctx context.Context, queries dbstore.Queries, botID, sessionID string, create func(dbstore.Queries) error) error

InCreateTransaction serializes per-session decision short IDs before the INSERT statement takes its MVCC snapshot. Non-transactional test stores retain their own local serialization.

func ResumeNativeContinuation added in v0.21.0

func ResumeNativeContinuation(ctx context.Context, queries dbstore.Queries, botID, sessionID, runID, decisionID pgtype.UUID, token pgtype.Int8, kind string) error

ResumeNativeContinuation must run inside the decision response's fenced transaction: either both the answer and running checkpoint commit, or neither.

func WithNativeContinuation added in v0.21.0

func WithNativeContinuation(ctx context.Context) context.Context

WithNativeContinuation is set by the application after runtime classification. Inline waiters must keep their original waiting/last-answer semantics.

func WithResponseIdentity

func WithResponseIdentity(ctx context.Context, identity ResponseIdentity) context.Context

Types

type ContinuationCheckpoint added in v0.21.0

type ContinuationCheckpoint struct {
	Kind  string `json:"kind"`
	Phase string `json:"phase"`
}

ContinuationCheckpoint records accepted native decisions. A tool marked executing may have produced effects even if its result never reached history. Recovery reconstructs context from the decision row; it never replays a tool.

type Request

type Request struct {
	ID                      string         `json:"id"`
	BotID                   string         `json:"bot_id"`
	SessionID               string         `json:"session_id"`
	RouteID                 string         `json:"route_id,omitempty"`
	ChannelIdentityID       string         `json:"channel_identity_id,omitempty"`
	WorkspaceTargetID       string         `json:"workspace_target_id,omitempty"`
	Kind                    string         `json:"kind"`
	ToolCallID              string         `json:"tool_call_id"`
	ToolName                string         `json:"tool_name"`
	ToolInput               map[string]any `json:"tool_input,omitempty"`
	UIPayloadRaw            []byte         `json:"-"`
	Result                  map[string]any `json:"result,omitempty"`
	ProviderMetadata        map[string]any `json:"-"`
	ShortID                 int            `json:"short_id"`
	Status                  string         `json:"status"`
	DecisionReason          string         `json:"decision_reason,omitempty"`
	PromptExternalMessageID string         `json:"prompt_external_message_id,omitempty"`
	SourcePlatform          string         `json:"source_platform,omitempty"`
	ReplyTarget             string         `json:"reply_target,omitempty"`
	ConversationType        string         `json:"conversation_type,omitempty"`
	CreatedAt               time.Time      `json:"created_at"`
	DecidedAt               *time.Time     `json:"decided_at,omitempty"`
	ExpiresAt               *time.Time     `json:"expires_at,omitempty"`
}

Request is the app-layer decision DTO. Storage remains owned by the kind-specific services: toolapproval writes tool_approval_requests, and userinput writes user_input_requests.

type ResponseIdentity

type ResponseIdentity struct {
	ControlID   string
	PayloadHash string
}

ResponseIdentity is the client retry identity attached to one durable decision transition.

func ResponseIdentityFromContext

func ResponseIdentityFromContext(ctx context.Context) (ResponseIdentity, bool)

type Waiter

type Waiter[T any] struct {
	// contains filtered or unexported fields
}

Waiter is the single in-process waiting mechanism: instant in-memory broadcast for the common case, with a DB-fallback poll (the caller's poll func) so decisions recorded by another process or missed broadcasts still resolve. The registry (Register/Has) lets delivery paths distinguish "a live consumer owns this request" from an orphaned row.

func NewWaiter

func NewWaiter[T any]() *Waiter[T]

func (*Waiter[T]) Await

func (w *Waiter[T]) Await(ctx context.Context, id string, fallback time.Duration, poll func(context.Context) (T, bool, error)) (T, error)

Await blocks until the request resolves: instantly via broadcast, or via the fallback poll (poll returns done=true with the terminal value). poll runs once immediately - a decision may already have landed - and then on every fallback interval. On ctx cancellation a last-chance channel drain runs so a decision delivered concurrently with cancellation is not lost.

func (*Waiter[T]) Has

func (w *Waiter[T]) Has(id string) bool

Has reports whether anyone in this process is registered for the request.

func (*Waiter[T]) Notify

func (w *Waiter[T]) Notify(id string, value T)

Notify wakes every subscriber of the request with the resolved value. Buffered, non-blocking sends: a subscriber that already left misses nothing - its fallback poll covers it.

func (*Waiter[T]) Register

func (w *Waiter[T]) Register(id string) func()

Register records that a caller in this process owns the request's resolution. Callers that announce a pending request to users must register BEFORE announcing, or an instant response can be misjudged as orphaned.

func (*Waiter[T]) Subscribe

func (w *Waiter[T]) Subscribe(id string) (<-chan T, func())

Subscribe registers a broadcast channel for the request BEFORE any status check, so a concurrent decision cannot slip between check and wait. The returned unsubscribe must run when the wait ends.

Directories

Path Synopsis
Package-shared MCP form-elicitation core: translates an MCP elicitation requestedSchema into the strict ask_user question payload and maps the submitted answers back into schema-conformant content.
Package-shared MCP form-elicitation core: translates an MCP elicitation requestedSchema into the strict ask_user question payload and maps the submitted answers back into schema-conformant content.

Jump to

Keyboard shortcuts

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