input

package
v0.0.72 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	APIFieldTypeCheckboxes  = openapi.FieldTypeCheckboxes
	APIFieldTypeLinearScale = openapi.FieldTypeLinearScale
	APIFieldTypeBoolean     = openapi.FieldTypeBoolean
)

Variables

View Source
var (
	ErrValidation          = errors.New("invalid input")
	ErrStaleRequest        = errors.New("request_id does not match the pending input")
	ErrDocumentNotFound    = errors.New("document is not part of the review")
	ErrArtifactUnavailable = errors.New("artifact bytes are unavailable")
	ErrStorage             = errors.New("input storage operation failed")
)
View Source
var ErrInputNotPending = errors.New("input is not pending for job")

Functions

func GetAlternateOp added in v0.0.56

func GetAlternateOp() ops.RegisterableOp

GetAlternateOp registers the internal worker implementing pending input collection.

func GetAutoFillOp

func GetAutoFillOp() ops.RegisterableOp

GetAutoFillOp registers the op that echoes a pre-filled input response.

func GetOp

func GetOp() ops.RegisterableOp

func NormalizeOutputMap added in v0.0.11

func NormalizeOutputMap(opInput map[string]interface{}, opOutput map[string]interface{}) (map[string]interface{}, error)

Types

type APIFieldType

type APIFieldType = openapi.FieldType

APIFieldType is the generated transport enum for form fields.

type APIFormField

type APIFormField = openapi.FormField

APIFormField is the generated transport shape used by user-input clients.

type APIOption

type APIOption = openapi.Option

APIOption is the generated transport shape for select options.

type Actor added in v0.0.56

type Actor struct {
	ID   string `json:"id"`
	Kind string `json:"kind"`
}

Actor is supplied by the embedding application, not taken from response data. The application is responsible for authenticating this identity.

type Artifact

type Artifact struct {
	Path string `json:"path" validate:"required" jsonschema:"required,description=Path to artifact file"`
}

Artifact represents a static artifact reference

type Config

type Config struct {
	Kind      string         `json:"kind,omitempty" jsonschema:"enum=review,description=Optional review marker"`
	Documents map[string]any `json:"documents,omitempty"`
	// Structured mode. Schemas and request are frozen in the generate_form outcome.
	Request        any            `json:"request,omitempty"`
	RequestSchema  map[string]any `json:"request_schema,omitempty"`
	ResponseSchema map[string]any `json:"response_schema,omitempty"`
	Presentation   map[string]any `json:"presentation,omitempty"`

	// Single question format
	Question string       `json:"question,omitempty" jsonschema:"description=Question to ask the user"`
	Type     FieldType    `` /* 285-byte string literal not displayed */
	Options  []Option     `json:"options,omitempty" validate:"omitempty,min=1,dive" jsonschema:"description=Options for choice fields"`
	Scale    *LinearScale `` /* 126-byte string literal not displayed */
	Default  interface{}  `json:"default,omitempty" jsonschema:"description=Default value used when the response is omitted"`

	// Multi-field format
	Title   string      `json:"title,omitempty" jsonschema:"description=Form title"`
	Fields  []FormField `json:"fields,omitempty" validate:"omitempty,min=1,dive" jsonschema:"description=Form fields"`
	Context FormContext `json:"context,omitempty" jsonschema:"description=Form context and artifacts"`

	// Optional auto-fill response
	Output *Output `json:"autofill,omitempty" jsonschema:"description=Optional auto-fill output response"`
}

Config represents the configuration for the input activity

func (Config) MarshalJSON added in v0.0.56

func (c Config) MarshalJSON() ([]byte, error)

func (Config) ValidateOpInput added in v0.0.6

func (c Config) ValidateOpInput() error

type FallbackAnswers added in v0.0.56

type FallbackAnswers struct {
	Response     any                      `json:"response,omitempty"`
	Fields       map[string]any           `json:"fields,omitempty"`
	ArtifactRefs map[string]artifacts.Ref `json:"artifact_refs,omitempty"`
}

FallbackAnswers is frozen in the prepared form for both implementations.

type FieldType

type FieldType string

FieldType represents the type of form field

const (
	FieldTypeShortAnswer        FieldType = "short_answer"
	FieldTypeParagraphText      FieldType = "paragraph_text"
	FieldTypeMultipleChoice     FieldType = "multiple_choice"
	FieldTypeCheckboxes         FieldType = "checkboxes"
	FieldTypeDropdown           FieldType = "dropdown"
	FieldTypeLinearScale        FieldType = "linear_scale"
	FieldTypeBoolean            FieldType = "boolean"
	FieldTypeMultipleChoiceGrid FieldType = "multiple_choice_grid"
	FieldTypeCheckboxGrid       FieldType = "checkbox_grid"
	FieldTypeDate               FieldType = "date"
	FieldTypeTime               FieldType = "time"
	FieldTypeFileUpload         FieldType = "file_upload"
)

type FieldValidation

type FieldValidation struct {
	MinLength int    `json:"min_length,omitempty" jsonschema:"minimum=0,description=Minimum length for text fields"`
	MaxLength int    `json:"max_length,omitempty" jsonschema:"minimum=1,description=Maximum length for text fields"`
	Pattern   string `json:"pattern,omitempty" jsonschema:"description=Regex pattern for validation"`
	Min       int    `json:"min,omitempty" jsonschema:"description=Minimum value for numeric fields"`
	Max       int    `json:"max,omitempty" jsonschema:"description=Maximum value for numeric fields"`
}

FieldValidation represents validation rules for a form field

type FormContext

type FormContext struct {
	Artifacts           []Artifact    `json:"artifacts,omitempty" jsonschema:"description=Static artifact references"`
	ArtifactsFromOutput string        `json:"artifacts_from_output,omitempty" jsonschema:"description=Reference to artifacts from previous activity output"`
	ArtifactsGlob       []GlobPattern `json:"artifacts_glob,omitempty" jsonschema:"description=Glob patterns for artifact discovery"`
}

FormContext represents context information for the form

type FormField

type FormField struct {
	ID          string          `json:"id" validate:"required" jsonschema:"required,description=Unique field identifier"`
	Type        FieldType       `` /* 371-byte string literal not displayed */
	Question    string          `json:"question" validate:"required" jsonschema:"required,description=Field question or label"`
	Required    bool            `json:"required,omitempty" jsonschema:"description=Whether field is required"`
	Default     interface{}     `json:"default,omitempty" jsonschema:"description=Default value used when the field is omitted"`
	Placeholder string          `json:"placeholder,omitempty" jsonschema:"description=Placeholder text"`
	Options     []Option        `json:"options,omitempty" validate:"omitempty,min=1,dive" jsonschema:"description=Options for choice fields"`
	Scale       *LinearScale    `` /* 126-byte string literal not displayed */
	Validation  FieldValidation `json:"validation,omitempty" jsonschema:"description=Field validation rules"`
}

FormField represents a single field in a multi-field form

type FormResponse

type FormResponse = openapi.FormResponse

FormResponse represents the user's response to a form (OpenAPI-generated type).

type FormSubmission added in v0.0.56

type FormSubmission struct {
	RequestID    string                   `json:"request_id"`
	SubmissionID string                   `json:"submission_id"`
	Response     any                      `json:"response,omitempty"`
	Fields       map[string]any           `json:"fields,omitempty"`
	ArtifactRefs map[string]artifacts.Ref `json:"artifact_refs,omitempty"`
}

FormSubmission answers a review using ordinary form fields and attachments. File-upload fields may contain stored refs or jobdb.Artifact values. Additional documents may be supplied as named, already-stored ArtifactRefs.

type GlobPattern

type GlobPattern struct {
	Pattern string `json:"pattern" validate:"required" jsonschema:"required,description=Glob pattern for matching files"`
}

GlobPattern represents a glob pattern for artifact discovery

type Input

type Input struct {
	IfUnanswered *UnansweredPolicy `json:"if_unanswered,omitempty"`
	Form         Config            `json:"form,omitempty" validate:"required" jsonschema:"description=Form formuration"`
}

Input represents the inputs passed to the input activity

func (Input) ValidateOpInput added in v0.0.6

func (in Input) ValidateOpInput() error

type InputCancelSignal

type InputCancelSignal struct {
	ActivityID string `json:"activity_id"`
	ResponseID string `json:"response_id"`
	Reason     string `json:"reason"`
}

InputCancelSignal represents a signal to cancel a pending input request

type InputForm

type InputForm struct {
	FallbackAt string           `json:"fallback_at,omitempty"`
	Fallback   *FallbackAnswers `json:"fallback,omitempty"`
	// RequestedAt is recorded when the form is prepared, not when its job starts.
	RequestedAt    string                         `json:"requested_at,omitempty"`
	Kind           string                         `json:"kind,omitempty"`
	Documents      map[string]recipeartifacts.Ref `json:"documents,omitempty"`
	RequestID      string                         `json:"request_id,omitempty"`
	Request        any                            `json:"request,omitempty"`
	RequestSchema  map[string]any                 `json:"request_schema,omitempty"`
	ResponseSchema map[string]any                 `json:"response_schema"`
	Presentation   map[string]any                 `json:"presentation,omitempty"`
	// Single question fields
	Question string       `json:"question,omitempty" jsonschema:"description=Single question text"`
	Type     FieldType    `` /* 177-byte string literal not displayed */
	Options  []Option     `json:"options,omitempty" jsonschema:"description=Options for single choice field"`
	Scale    *LinearScale `json:"scale,omitempty" jsonschema:"description=Configuration for linear scale fields"`
	Default  interface{}  `json:"default,omitempty" jsonschema:"description=Default value used when the response is omitted"`

	// Multi-field form
	Title  string      `json:"title,omitempty" jsonschema:"description=Form title"`
	Fields []FormField `json:"fields,omitempty" jsonschema:"description=Form fields for multi-field form"`

	// Common fields
	Context FormContext   `json:"context,omitempty" jsonschema:"description=Form context and artifacts"`
	Output  *Output       `json:"output,omitempty" jsonschema:"description=Optional auto-fill output response"`
	Timeout time.Duration `json:"timeout,omitempty" jsonschema:"default=300,description=Timeout in seconds"`
}

InputForm represents the complete form structure

func (InputForm) MarshalJSON added in v0.0.56

func (f InputForm) MarshalJSON() ([]byte, error)

Preserve an explicitly empty schema (accept any JSON) across task persistence.

type InputRequestSignal

type InputRequestSignal struct {
	ActivityID string        `json:"activity_id"`
	WorkflowID string        `json:"workflow_id"`
	Form       InputForm     `json:"form"`
	Timeout    time.Duration `json:"timeout"`
}

InputRequestSignal represents a signal sent by the activity to request user input

type InputResponseSignal

type InputResponseSignal struct {
	ActivityID   string       `json:"activity_id"`
	ResponseID   string       `json:"response_id"`
	FormResponse FormResponse `json:"form_response"`
	UserID       string       `json:"user_id"`
	RespondedAt  time.Time    `json:"responded_at"`
}

InputResponseSignal represents a signal sent when user submits form

type InputTimeoutSignal

type InputTimeoutSignal struct {
	ActivityID string    `json:"activity_id"`
	ResponseID string    `json:"response_id"`
	TimedOutAt time.Time `json:"timed_out_at"`
}

InputTimeoutSignal represents a signal sent when input request times out

type InputWorkflowParams

type InputWorkflowParams struct {
	ID         string        `json:"id"`
	Form       InputForm     `json:"form"`
	Timeout    time.Duration `json:"timeout"`
	BoxID      string        `json:"box_id"`
	ActivityID string        `json:"activity_id"`
}

InputWorkflowParams represents parameters for the input collection workflow

type InputWorkflowResult

type InputWorkflowResult struct {
	FormResponse map[string]interface{} `json:"form_response"`
	UserID       string                 `json:"user_id"`
	Metadata     map[string]interface{} `json:"metadata"`
}

InputWorkflowResult represents the result of the input collection workflow

type LinearScale

type LinearScale struct {
	Min      int    `json:"min" validate:"required,gte=0,lte=10" jsonschema:"required,minimum=0,maximum=10,description=Minimum scale value"`
	Max      int    `json:"max" validate:"required,gte=1,lte=10" jsonschema:"required,minimum=1,maximum=10,description=Maximum scale value"`
	MinLabel string `json:"min_label,omitempty" jsonschema:"description=Label for minimum value"`
	MaxLabel string `json:"max_label,omitempty" jsonschema:"description=Label for maximum value"`
}

LinearScale represents configuration for linear scale fields

type Option

type Option struct {
	Value string `json:"value" validate:"required" jsonschema:"required,description=Option value"`
	Label string `json:"label,omitempty" jsonschema:"description=Optional display label"`
}

Option represents a choice option for fields like multiple choice, dropdown, etc.

type Output

type Output struct {
	ArtifactRefs map[string]recipeartifacts.Ref `json:"artifact_refs"`
	Receipt      *Receipt                       `json:"receipt,omitempty"`
	Response     interface{}                    `json:"response" jsonschema:"description=User response for an ordinary or structured input"`
	Fields       map[string]interface{}         `json:"fields,omitempty" jsonschema:"description=User responses for multi-field form"`
	UserID       string                         `json:"user_id,omitempty" jsonschema:"description=ID of user who responded"`
	Metadata     map[string]interface{}         `json:"metadata,omitempty" jsonschema:"description=Additional metadata"`
}

Output represents the output from the input activity

func NormalizeOutput added in v0.0.11

func NormalizeOutput(form Config, out Output) (Output, error)

NormalizeOutput stabilizes successful input outputs against the rendered form schema. Required fields without submitted values or explicit defaults fail instead of receiving invented values.

type PendingInput

type PendingInput = openapi.PendingInput

PendingInput represents a pending input request (OpenAPI-generated type).

type PendingInputOccurrence added in v0.0.57

type PendingInputOccurrence struct {
	JobID       string `json:"job_id"`
	TaskOrdinal int64  `json:"task_ordinal"`
	RequestID   string `json:"request_id,omitempty"`
	RequestedAt string `json:"requested_at,omitempty"`
}

PendingInputOccurrence contains identity and timing only. Fetch GetForm for questions, kind, title, or documents. RequestID/RequestedAt may be absent on legacy ordinary forms; JobID + TaskOrdinal still identifies their occurrence.

type PendingInputOptions added in v0.0.57

type PendingInputOptions struct {
	PageSize  int    `json:"page_size,omitempty"`
	PageToken string `json:"page_token,omitempty"`
}

type PendingInputPage added in v0.0.57

type PendingInputPage struct {
	Inputs        []PendingInputOccurrence `json:"inputs"`
	NextPageToken string                   `json:"next_page_token,omitempty"`
}

type Receipt added in v0.0.56

type Receipt struct {
	RequestID    string    `json:"request_id"`
	SubmissionID string    `json:"submission_id"`
	SubmittedAt  time.Time `json:"submitted_at"`
	Actor        Actor     `json:"actor"`
}

type ReviewDocument added in v0.0.57

type ReviewDocument struct {
	ID        string
	Ref       artifacts.Ref
	Name      string
	SizeBytes int64
	io.ReadCloser
}

ReviewDocument is an opened, immutable stored document. Close it after use. Ref retains its original producer identity. Completion of the review does not revoke an already opened stream.

type Runtime

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

func NewRuntime

func NewRuntime(ctl workflowctl.WorkflowControl, sse ops.SSEManager) (*Runtime, error)

func NewRuntimeFromDeps

func NewRuntimeFromDeps(deps ops.ServiceDependencies2) (*Runtime, error)

func (*Runtime) Cancel

func (r *Runtime) Cancel(ctx context.Context, projectID string, jobID string, reason string) error

func (*Runtime) GetDetails

func (r *Runtime) GetDetails(ctx context.Context, projectID string, jobID string) (*UserInputDetails, error)

func (*Runtime) GetForm added in v0.0.56

func (r *Runtime) GetForm(ctx context.Context, projectID, jobID string) (InputForm, error)

GetForm returns the frozen form independently of any presentation transport.

func (*Runtime) ListPendingInputs

func (r *Runtime) ListPendingInputs(ctx context.Context, projectID string) ([]PendingInput, error)

func (*Runtime) ListPendingInputsPage added in v0.0.57

func (r *Runtime) ListPendingInputsPage(ctx context.Context, tenantID string, options PendingInputOptions) (PendingInputPage, error)

ListPendingInputsPage lists a live page, not a snapshot. Occurrences completed or replaced during reading are skipped. An empty page with a continuation token is not the end of the list. Form data is read only within this page; document bytes are never loaded for discovery.

func (*Runtime) OpenReviewDocument added in v0.0.57

func (r *Runtime) OpenReviewDocument(ctx context.Context, tenantID, jobID, requestID, documentID string) (*ReviewDocument, error)

OpenReviewDocument resolves only document IDs belonging to the exact pending review occurrence in the current tenant. It accepts no external paths or URLs.

func (*Runtime) SSEManager

func (r *Runtime) SSEManager() ops.SSEManager

func (*Runtime) SubmitFormResponse added in v0.0.56

func (r *Runtime) SubmitFormResponse(ctx context.Context, tenantID, jobID string, submission FormSubmission, actor Actor) (Output, error)

SubmitFormResponse validates and completes the exact pending review. The embedding application supplies the authenticated actor separately.

func (*Runtime) SubmitResponse

func (r *Runtime) SubmitResponse(ctx context.Context, projectID string, jobID string, output FormResponse) error

func (*Runtime) SubmitStructuredResponse added in v0.0.56

func (r *Runtime) SubmitStructuredResponse(ctx context.Context, projectID, jobID string, submission StructuredSubmission, actor Actor) (Output, error)

SubmitStructuredResponse validates against the recorded request before finishing the exact waiting task. Successful return is the same output recorded for the op. Recovery of ambiguous completion failures remains JobDB's responsibility.

type RuntimeError added in v0.0.57

type RuntimeError struct {
	Kind       error
	Operation  string
	Field      string
	FieldID    string
	DocumentID string
	Cause      error
}

RuntimeError classifies a runtime failure without choosing a transport status. Cause remains available through errors.Is/As. A completion storage failure can have an ambiguous outcome and does not imply a retry is safe.

func (*RuntimeError) Error added in v0.0.57

func (e *RuntimeError) Error() string

func (*RuntimeError) Is added in v0.0.57

func (e *RuntimeError) Is(target error) bool

func (*RuntimeError) Unwrap added in v0.0.57

func (e *RuntimeError) Unwrap() error

type SSEEvent

type SSEEvent = recipeops.SSEEvent

SSEEvent is a local alias for the core ops SSEEvent used by tests.

type SimpleSSEManager

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

SimpleSSEManager is a basic implementation of SSEManager

func NewSimpleSSEManager

func NewSimpleSSEManager() *SimpleSSEManager

NewSimpleSSEManager creates a new SSE manager

func (*SimpleSSEManager) Broadcast

func (m *SimpleSSEManager) Broadcast(event ops.SSEEvent)

Broadcast sends an event to all connected clients

func (*SimpleSSEManager) ClearBuffer

func (m *SimpleSSEManager) ClearBuffer()

ClearBuffer clears the event buffer

func (*SimpleSSEManager) GetClients

func (m *SimpleSSEManager) GetClients() int

GetClients returns the number of connected clients

func (*SimpleSSEManager) Subscribe

func (m *SimpleSSEManager) Subscribe(clientID string) <-chan ops.SSEEvent

Subscribe adds a client and returns their event channel

func (*SimpleSSEManager) Unsubscribe

func (m *SimpleSSEManager) Unsubscribe(clientID string)

Unsubscribe removes a client

type StructuredSubmission added in v0.0.56

type StructuredSubmission struct {
	RequestID    string                         `json:"request_id"`
	SubmissionID string                         `json:"submission_id"`
	Response     any                            `json:"response"`
	ArtifactRefs map[string]recipeartifacts.Ref `json:"artifact_refs,omitempty"`
}

StructuredSubmission accepts ordinary JSON values and stored artifact refs. Go callers can also place jobdb.Artifact values in Response: these are attached to the outcome and replaced by stored refs before schema validation. Their contents never become inline JSON. ArtifactRefs provides explicit named bindings.

type UnansweredPolicy added in v0.0.56

type UnansweredPolicy struct {
	After        string                   `json:"after"`
	Response     any                      `json:"response,omitempty"`
	Fields       map[string]any           `json:"fields,omitempty"`
	ArtifactRefs map[string]artifacts.Ref `json:"artifact_refs,omitempty"`
}

UnansweredPolicy supplies ordinary answers if a worker acquires the alternate after the delay. It does not impose a deadline on human responses.

type UserInputDetails

type UserInputDetails = openapi.UserInputDetails

UserInputDetails describes a pending input request in a transport-agnostic shape.

type UserResponseSignal

type UserResponseSignal struct {
	Fields      map[string]interface{} `json:"fields"`
	UserID      string                 `json:"user_id"`
	RespondedAt time.Time              `json:"responded_at"`
	Metadata    map[string]interface{} `json:"metadata"`
}

UserResponseSignal represents the signal sent when a user responds

type ValidationError added in v0.0.6

type ValidationError struct {
	Field    string
	FieldID  string
	Cause    error
	Message  string
	Required bool
}

ValidationError reports input-op invariants that cannot be expressed safely with field tags.

func (ValidationError) Error added in v0.0.6

func (e ValidationError) Error() string

func (ValidationError) Is added in v0.0.57

func (e ValidationError) Is(target error) bool

func (ValidationError) RequiredValidationError added in v0.0.6

func (e ValidationError) RequiredValidationError() bool

func (ValidationError) Unwrap added in v0.0.57

func (e ValidationError) Unwrap() error

Directories

Path Synopsis
Package openapi provides primitives to interact with the openapi HTTP API.
Package openapi provides primitives to interact with the openapi HTTP API.

Jump to

Keyboard shortcuts

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