Skip to content

unaiverse.uai.constants

This module holds the numbers and the closed vocabularies of the interactive-message protocol. Each value is a term of the contract shared with the JavaScript SDK and with every GUI. A value changes first in the contract, then in the JavaScript SDK and only then here. A world reads these names to compare what it receives (event.via == VIA_LABELED, "above_max" in event.issues.values()) and never assigns them new values. Import them from unaiverse.uai. The names of the table below that unaiverse.uai does not re-export are reachable only from this module. The protocol is described in the package page and in Interactive messages.

Group Names
Wire format FENCE_TAG, PROTOCOL_VERSION
Vocabularies BLOCK_TYPES, FIELD_TYPES, CHART_KINDS, TEXT_FORMATS, SELECT_UI (not re-exported)
Rungs of the reply interpreter VIA_BLOCK, VIA_LABELED, VIA_BARE, VIA_CSV, VIA_FREETEXT
Issue codes ISSUE_TYPE, ISSUE_BELOW_MIN, ISSUE_ABOVE_MAX, ISSUE_TOO_LONG, ISSUE_FORMAT, ISSUE_UNKNOWN_OPTION
Protocol limits MAX_BLOCK_BYTES, MAX_ALT_CHARS and the limits that are not re-exported: MAX_FIELDS_PER_FORM, MAX_FIELD_ITEMS, MAX_OPTIONS_PER_SELECT, MAX_LABEL_CHARS, MAX_NAME_CHARS, MAX_HELP_CHARS, MAX_UNIT_CHARS, MAX_SERIES_PER_CHART, MAX_POINTS_PER_SERIES
Languages LANGS, DEFAULT_LANG
Python-side limits MAX_BLOCKS_MODEL_VIEW, MAX_MODEL_VIEW_BYTES, MAX_OUTPUT_BYTES, MAX_INBOX_PEERS

Character limits count Python code points (len(s)). The JavaScript SDK counts UTF-16 units. The two counts differ only for characters outside the Basic Multilingual Plane that sit exactly on a limit.

FENCE_TAG module-attribute

FENCE_TAG = 'uai'

The info string ("uai") of the fenced code block that carries a block. A block opens with a line of three or more backticks followed by uai and closes with a line of at least as many backticks (see fence). A fence of tildes is never a block.

PROTOCOL_VERSION module-attribute

PROTOCOL_VERSION = 1

The version of the protocol that this package implements (1). Every block carries it as "v": 1. A block that declares a higher version is invalid for this package and the receiver shows its alt (error code v_unsupported of validate_block).

BLOCK_TYPES module-attribute

BLOCK_TYPES = ('media', 'data', 'form')

The tuple ("media", "data", "form") of the content block types. A media block shows a picture, a video, an audio file or a PDF. A data block draws a chart. A form block asks for values. The answer to a form is not a content block because it carries "kind": "reply" in place of type. A type that starts with x- is an experiment that every receiver shows as its alt.

FIELD_TYPES module-attribute

FIELD_TYPES = ('text', 'textarea', 'number', 'integer', 'bool', 'date', 'select')

The tuple ("text", "textarea", "number", "integer", "bool", "date", "select") of the interactive field types of version 1.

Type A person sees Canonical value in an answer
text A one-line input, with format email, url or tel when declared. str
textarea A multi-line input. str
number A numeric input with optional unit, min and max. JSON number
integer The same input restricted to integers. JSON integer
bool A yes or no choice. true or false
date A date picker with optional ISO bounds. "YYYY-MM-DD"
select Options shown as a list or as buttons (ui: "buttons"). The option value when max is 1 and a list of values when max is greater.

The validator turns a field of any other type into a text field that keeps only the common keys. A form row {"type": "section", "label": ...} is a heading and not a field type.

CHART_KINDS module-attribute

CHART_KINDS = ('bar', 'line', 'pie')

The tuple ("bar", "line", "pie") of the chart kinds of a data block. Any other value of chart makes the block invalid (error code chart_invalid).

TEXT_FORMATS module-attribute

TEXT_FORMATS = ('email', 'url', 'tel')

The closed list ("email", "url", "tel") of the format values of a text field. The protocol never carries a regular expression. The checks behind each format are in check_constraints (email needs x@y.z, url needs http:// or https:// and a host, tel needs digits, spaces, +, -, ( and ) with at least five digits).

SELECT_UI module-attribute

SELECT_UI = ('buttons',)

The tuple ("buttons",) of the presentation hints of a select field that the protocol knows. No code of the package reads this tuple. The validator keeps any string ui on a field of a known type and the renderers ignore the hints they do not know.

VIA_BLOCK module-attribute

VIA_BLOCK = 'block'

"block": the value of ReplyEvent.via when the answer was a canonical reply block. This is the first rung of interpret_reply and the form that the webapp widget and encode_reply produce.

VIA_LABELED module-attribute

VIA_LABELED = 'labeled'

"labeled": the answer was read from key: value pairs where each key is the name or the label of a field (height: 180 cm).

VIA_BARE module-attribute

VIA_BARE = 'bare'

"bare": the answer was a bare value for a form with a single interactive field (42).

VIA_CSV module-attribute

VIA_CSV = 'csv'

"csv": the answer was one line of comma-separated values in the order of the fields (180, omni).

VIA_FREETEXT module-attribute

VIA_FREETEXT = 'freetext'

"freetext": no rung matched. The event carries the text in raw with empty values and to equal to None. The interpreter never drops a message.

ISSUE_TYPE module-attribute

ISSUE_TYPE = 'type'

"type": the value could not be converted to the type of the field. Examples are forty for a number, 42.5 for an integer, maybe for a bool and the string "180" inside a reply block for a number field.

ISSUE_BELOW_MIN module-attribute

ISSUE_BELOW_MIN = 'below_min'

"below_min": a number, integer or date value is under min. A multi-select with fewer than min options gets the same code.

ISSUE_ABOVE_MAX module-attribute

ISSUE_ABOVE_MAX = 'above_max'

"above_max": a number, integer or date value is over max. A multi-select with more than max options gets the same code.

ISSUE_TOO_LONG module-attribute

ISSUE_TOO_LONG = 'too_long'

"too_long": a text or textarea value is longer than maxLength characters.

ISSUE_FORMAT module-attribute

ISSUE_FORMAT = 'format'

"format": a text value does not satisfy its declared format.

ISSUE_UNKNOWN_OPTION module-attribute

ISSUE_UNKNOWN_OPTION = 'unknown_option'

"unknown_option": an item of a select answer matches no option by value or by label.

MAX_BLOCK_BYTES module-attribute

MAX_BLOCK_BYTES = 8192

The maximum size of the body of one block: 8192 bytes in UTF-8. The parser measures the body before parsing any JSON. A larger body is never parsed and comes back as text cut to this size (error too_large). The composer raises UaiError with reason block_too_large instead of producing it.

MAX_FIELDS_PER_FORM module-attribute

MAX_FIELDS_PER_FORM = 20

The maximum number of interactive fields of a form: 20 (error too_many_fields).

MAX_FIELD_ITEMS module-attribute

MAX_FIELD_ITEMS = 40

The maximum length of the fields list including section rows: 40 (error fields_invalid).

MAX_OPTIONS_PER_SELECT module-attribute

MAX_OPTIONS_PER_SELECT = 50

The maximum number of options of a select field: 50 (error options_invalid:<name>).

MAX_LABEL_CHARS module-attribute

MAX_LABEL_CHARS = 120

The maximum length in characters of a field label, an option label, a section label, the name of a form and the title of a media block: 120.

MAX_NAME_CHARS module-attribute

MAX_NAME_CHARS = 64

The maximum length of a field name: 64. The validator enforces it through its name pattern [A-Za-z_][A-Za-z0-9_]{0,63} and never reads this constant.

MAX_HELP_CHARS module-attribute

MAX_HELP_CHARS = 240

The maximum length of a help text of a field or an option and of a placeholder: 240.

MAX_ALT_CHARS module-attribute

MAX_ALT_CHARS = 2000

The maximum length of alt and of aiHint: 2000 characters. A content block with a longer alt is invalid. The alt of a reply block is its readable projection. encode_reply cuts a longer projection to this length with no marker and validate_block drops a longer one without refusing the block.

MAX_UNIT_CHARS module-attribute

MAX_UNIT_CHARS = 16

The maximum length of the unit of a number or integer field: 16.

MAX_SERIES_PER_CHART module-attribute

MAX_SERIES_PER_CHART = 10

The maximum number of series of a data block: 10.

MAX_POINTS_PER_SERIES module-attribute

MAX_POINTS_PER_SERIES = 500

The maximum number of points of one series: 500.

LANGS module-attribute

LANGS = ('it', 'en')

The languages with their own wording: ("it", "en"). The tables themselves live in TEMPLATES and template_for resolves a tag against them. No code reads this tuple.

DEFAULT_LANG module-attribute

DEFAULT_LANG = 'en'

The fallback language: "en". A form without lang or with a language outside LANGS uses the English wording. template_for writes the fallback "en" directly and does not read this constant.

MAX_BLOCKS_MODEL_VIEW module-attribute

MAX_BLOCKS_MODEL_VIEW = 16

The maximum number of blocks of one message that to_model_text renders (16). The blocks beyond it are replaced by one line [... N more blocks omitted]. This limit is a Python addition and is not part of the protocol. The contract bounds one block and not a whole message. Without this cap a peer could make a model read an unbounded amount of text.

MAX_MODEL_VIEW_BYTES module-attribute

MAX_MODEL_VIEW_BYTES = 65536

The maximum size of the text that to_model_text returns: 65536 bytes in UTF-8. A longer rendering is cut on a character boundary and gains the line [... truncated]. This limit is a Python addition.

MAX_OUTPUT_BYTES module-attribute

MAX_OUTPUT_BYTES = 16384

The maximum size in UTF-8 bytes of the reply block that the agent sends on behalf of its processor (16384). When the encoded answer of a model is larger, AgentBasics.uai_postprocess sends the original text of the model instead of the block. This limit is a Python addition.

MAX_INBOX_PEERS module-attribute

MAX_INBOX_PEERS = 32

The maximum number of peers whose last form an agent remembers (32). AgentBasics.uai_remember_form keeps one form per peer and evicts the oldest peer beyond this number. This limit is a Python addition.