Class ChatRequestBody
ChatHandler and
ChatStreamHandler.
The v2 body shape uses snake_case keys: session_id, message,
extra_queries. Label filters are passed as a nested object:
"fields": {"label": "value"} (string or array). The legacy dotted-key
"fields.label" is also accepted for backward compatibility during
transition. Session clearing has been moved to the dedicated DELETE endpoint
/api/v2/chat/sessions/{session_id}; the clear flag is no
longer accepted here.
Length is enforced inside ChatApiHelper.parseRequestBody(Map, int)
so the caller does not need
a separate guard. Label and extra_queries validation uses the same allowlist
helpers v1 calls — LabelTypeHelper for labels and ViewHelper
for facet queries — to prevent query injection, delegated to the
chatApiHelper component (obtained via ComponentUtil.getChatApiHelper()).
MJ-29: Filter values that fail validation (fields.label,
extra_queries) are dropped silently from the resolved request. Rejected
values are tracked in the warnings map (see getWarnings())
for diagnostics only and are not emitted on the wire by ChatHandler
or ChatStreamHandler.
MJ-30 i18n note: error.message is developer-facing English. Clients MUST use error.code (the V2ErrorCode token) for user-facing i18n.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBase for chat request body validation errors that map to HTTP 400.static classThrown when session_id exceeds the maximum length or contains invalid characters.static classThrown when the requestmessageexceedsrag.chat.message.max.length.static classThrown when an array parameter (extra_queries, fields.label) exceeds the count or per-element length limit. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionString[]Returns the validatedextra_queriesarray supplied by the caller.fields()Returns the validated label-filter map (fields.labelentries).MJ-29: Returns a map of field names to rejected values.message()Returns the trimmedmessagevalue supplied by the caller.Returns the trimmedsession_idvalue supplied by the caller.
-
Constructor Details
-
ChatRequestBody
public ChatRequestBody(String message, String sessionId, Map<String, String[]> fields, String[] extraQueries, Map<String, List<String>> warnings) Creates a parsed chat request body. Instances are normally produced byChatApiHelper.parseRequestBody(Map, int)after the raw body has been validated, so callers rarely invoke this constructor directly.- Parameters:
message- the trimmedmessagevalue, ornullwhen omitted or blanksessionId- the trimmedsession_idvalue, ornullfor a fresh sessionfields- the validated label-filter map; nevernullextraQueries- the validatedextra_queriesarray; nevernullwarnings- the map of rejected field values tracked for diagnostics; nevernull
-
-
Method Details
-
message
Returns the trimmedmessagevalue supplied by the caller.- Returns:
- the chat message, or
nullif the caller omitted it or sent only whitespace
-
sessionId
Returns the trimmedsession_idvalue supplied by the caller.- Returns:
- the chat session id, or
nullwhen the caller is starting a fresh session
-
fields
Returns the validated label-filter map (fields.labelentries).- Returns:
- map of label field name to allowlisted value arrays; never
null
-
extraQueries
Returns the validatedextra_queriesarray supplied by the caller.- Returns:
- allowlisted facet queries, or an empty array when none were supplied
-
getWarnings
MJ-29: Returns a map of field names to rejected values. The map is empty (never null) when no values were dropped. Keys are the request field names:"fields.label"and"extra_queries".Diagnostics-only: handlers (
ChatHandler,ChatStreamHandler) do not surface this map on the wire today. Exposing rejected filter values to clients is a planned follow-up.- Returns:
- unmodifiable map of rejected field→value-list pairs; empty if nothing was dropped
-