Bỏ qua để đến nội dung

01: Input Normalization

Nội dung này hiện chưa có sẵn bằng ngôn ngữ của bạn.

Input normalization prepares the typed invocation record for the chat pipeline. It converts optional fields on TomoriChatInput into a strict ChatIncoming record with guaranteed defaults.

The coordinator tomoriChat() receives TomoriChatInput from several sources: Discord messageCreate events, slash commands, empty-response retries, reminder executions, and cross-channel boomerang follow-ups.

normalizeChatInvocation() in src/utils/chat/admission.ts maps this payload to ChatIncoming:

FieldDefaultPurpose
retryCount0Tracks empty-response retry iterations across recursive invocations.
skipLockfalseSignals whether the call reuses an existing outer channel lock.
isPersonaJobfalseDistinguishes autonomous persona jobs from human messages.
isUserImpersonationfalseMarks command-driven user impersonation turns.
textQuotaSource"user"Specifies whether server text quota charges the user or a system lease.

Other fields pass through without alteration:

  • systemTriggerIdentity: carries authoritative server and user snowflakes from scheduled reminder rows, preventing ambiguous DM channel key lookups; empty-response retries preserve this identity.
  • carriedExpressionDelivery: forwards expression delivery state to empty-response retries so visible expressions are not re-sent.
  • onGenerationResult and onQueueDiscard: callback handlers allowing command callers to observe completion or rejection.
  • Single boundary enforcement: defaults are applied once at entry. Downstream stages rely on populated values without defensive null-coalescing checks.
  • Pure transformation: normalization performs in-memory property mapping without network calls, database queries, or cache mutations.
  • Payload preservation: fields intended for downstream stages (such as streaming overrides or forced mentions) remain intact so later stages receive the caller’s intended configuration.
  • src/utils/chat/admission.ts: normalizeChatInvocation() implementation.
  • src/utils/chat/types.ts: TomoriChatInput and ChatIncoming type definitions.
  • src/events/messageCreate/tomoriChat.ts: coordinator entry invoking normalization.