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.
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.
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).
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
¶
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.
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).
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).
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.
"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.
"labeled": the answer was read from key: value pairs where each key is the name or the label of a field (height: 180 cm).
"bare": the answer was a bare value for a form with a single interactive field (42).
"csv": the answer was one line of comma-separated values in the order of the fields (180, omni).
"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.
"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.
"below_min": a number, integer or date value is under min. A multi-select with fewer than min options gets the same code.
"above_max": a number, integer or date value is over max. A multi-select with more than max options gets the same code.
"too_long": a text or textarea value is longer than maxLength characters.
"format": a text value does not satisfy its declared format.
"unknown_option": an item of a select answer matches no option by value or by label.
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.
The maximum number of interactive fields of a form: 20 (error too_many_fields).
The maximum length of the fields list including section rows: 40 (error fields_invalid).
The maximum number of options of a select field: 50 (error options_invalid:<name>).
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.
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.
The maximum length of a help text of a field or an option and of a placeholder: 240.
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.
The maximum length of the unit of a number or integer field: 16.
The maximum number of series of a data block: 10.
The maximum number of points of one series: 500.
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.
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.
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.
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.
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.
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.