Skip to content

API Reference parrot_formdesigner.services.rest_field_resolver

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot_formdesigner.services.rest_field_resolver

View source

RestFieldResolver service for FieldType.REST form fields.

Implements the three REST dispatch modes (remote / internal / callback), JSONPath response extraction, Jinja2 display-template rendering, and informational response-schema validation. Never raises — all errors flow into RestFieldResult.

Mirrors — does NOT subclass — RemoteResponseResolver (FEAT-167).

See spec §2 Architectural Design, §7 Patterns to Follow, and §8 Q2/Q3/Q5 for detailed design decisions and resolution order rules.

Class AdditionalArg

Extra argument forwarded alongside the uploaded content.

Visibility controls who supplies the value at submission time:

  • "public": provided by the end user via the rendered form. The value field, if set, acts as a default. required=True enforces a non-empty submission.
  • "private": provided by the form designer; value MUST be set and is injected by the backend before forwarding to the target API. Frontend-supplied values for private args are ignored.

Fields:

Field Type Default Description
name str Argument name as expected by the target API.
visibility AdditionalArgVisibility "public" or "private".
value Any | None None Default (public) or fixed (private) value.
data_type AdditionalArgDataType 'string' How to coerce a user-supplied string value.
required bool False Whether a public arg must be supplied by the user.
label str | None None Optional human-readable label (i18n strings live on the field).
description str | None None Optional help text.

Attribute AdditionalArgDataType

Attribute AdditionalArgVisibility

Alias AuthContext

Re-exported from parrot_formdesigner.services.auth_context.AuthContext.

Class CallbackRestFieldSpec

Spec for mode='callback': invokes a pre-registered Python coroutine.

Attributes:

Attribute Type Description
mode Literal['callback'] Literal discriminator — always "callback".
callback_ref str Key in the callback registry (see callback_registry).

Class ConfigurationError

Raised when resolver cannot determine the internal base URL.

This exception surfaces on the first internal-mode invocation when no internal_base_url constructor arg, PARROT_INTERNAL_BASE_URL env var, or request-host fallback is available.

Class InternalRestFieldSpec

Spec for mode='internal': calls a relative path on the running server.

The endpoint must start with "/"; the resolver prepends internal_base_url (see resolution order in RestFieldResolver).

Attributes:

Attribute Type Description
mode Literal['internal'] Literal discriminator — always "internal".
endpoint str Relative path starting with "/" (e.g. "/api/v1/networkninja/photo-analyze").
http_method Literal['GET', 'POST', 'PUT', 'PATCH'] HTTP verb to use. Defaults to "POST".

Class RemoteRestFieldSpec

Spec for mode='remote': calls an absolute external URL.

Attributes:

Attribute Type Description
mode Literal['remote'] Literal discriminator — always "remote".
endpoint str Absolute URL (must start with http:// or https://).
http_method Literal['GET', 'POST', 'PUT', 'PATCH'] HTTP verb to use. Defaults to "POST".
auth_ref str | None Optional auth reference passed to AuthContext.resolve_for.

Class RestCallbackInput

Payload delivered to a registered callback coroutine.

Fields:

Field Type Default Description
form_id str ID of the parent form.
field_uid uuid.UUID Immutable UUID of the field triggering the upload (FEAT-393). Passthrough payload attribute — the resolver never reads it directly.
field_id str ID of the field triggering the upload.
session_id str | None User session ID (may be None).
user_id str | None Authenticated user ID (may be None).
tenant str | None Tenant slug (may be None).
content_type str MIME type of the uploaded content.
content Any Uploaded payload — bytes for binary, str for text, dict for JSON.
extra_fields dict[str, Any] Additional form fields forwarded for context.

Class RestCallbackOutput

Return value from a registered callback coroutine.

Fields:

Field Type Default Description
success bool Whether the callback completed successfully.
value Any | None None Extracted or computed answer value.
status_code int | None None Optional synthetic HTTP status code for logging.
error str | None None Human-readable error message on failure.

Attribute RestFieldMode

Class RestFieldResolver

Dispatch FieldType.REST field uploads by mode.

Supports three modes:

  • remote: POST/GET to an absolute external URL.
  • internal: POST/GET to a relative path on the running server.
  • callback: Invoke a pre-registered Python coroutine.

Mirrors the RemoteResponseResolver aiohttp pattern. Never raises from resolve() — all errors flow into RestFieldResult.

Parameter Type Default Description
timeout int DEFAULT_TIMEOUT Default HTTP timeout in seconds. Defaults to 30.
internal_base_url str | None None Explicit base URL for internal mode (e.g. "http://localhost:8080"). Takes priority over the PARROT_INTERNAL_BASE_URL env var and request-host fallback.

Attributes:

Attribute Type Description
DEFAULT_TIMEOUT int

Method RestFieldResolver.resolve

Dispatch by spec.mode and return the result.

Never raises. All errors are captured in the returned RestFieldResult.

resolve(spec: RemoteRestFieldSpec | InternalRestFieldSpec | CallbackRestFieldSpec, payload: RestCallbackInput, *, auth_context: AuthContext | None = None, tenant: str | None = None, request_host: str | None = None) -> RestFieldResult

Parameter Type Default Description
spec RemoteRestFieldSpec | InternalRestFieldSpec | CallbackRestFieldSpec The validated RestFieldSpec for this field.
payload RestCallbackInput Callback input carrying content, IDs, and metadata.
auth_context AuthContext | None None Optional inbound auth context for header injection.
tenant str | None None Tenant slug for callback registry lookup.
request_host str | None None Host string from the inbound request (e.g. "localhost:8080"). Used as the last-resort fallback for internal mode base-URL resolution when neither internal_base_url nor PARROT_INTERNAL_BASE_URL is configured.

Returns: RestFieldResult — RestFieldResult — always; never raises.

Class RestFieldResult

Output of RestFieldResolver.resolve().

Never raises — all errors are captured here.

Warnings use the convention "<code>: <detail>" e.g. "jsonpath_miss: $.compliance_score" or "response_schema_mismatch: missing 'violations'".

Fields:

Field Type Default Description
success bool True when the resolver obtained a usable response.
raw_value Any | None None Raw API / callback response before JSONPath extraction.
answer Any | None None Value after JSONPath extraction (or raw_value if no path).
blob_ref str | None None Set by the upload handler after blob persistence.
display str | None None Rendered Jinja2 display_template string.
status_code int | None None HTTP status code (remote / internal modes only).
warnings list[str] [] Informational warning strings (NOT RenderWarning).
error str | None None Human-readable error message on failure.

Attribute RestFieldSpec

Alias get_form_callback

Re-exported from parrot_formdesigner.services.callback_registry.get_form_callback.

Attribute logger

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally