Muse now forwards business context alongside each per-user token request, so new-api needs to ingest those tags for relay selection, billing audit, and log correlation without breaking its own internal request-id semantics. This adds a dedicated Muse request-context middleware, carries Muse tags into RelayInfo, and appends them into consume/error log payloads. Muse request ids are stored as separate business metadata instead of overwriting the internal request id used for pre-consume idempotency. Constraint: The relay layer must keep working for both /v1 and /v1beta request paths Constraint: Client-supplied Muse request ids cannot replace the internal request id used by new-api billing/idempotency logic Rejected: Overwriting common.RequestIdKey with X-Request-Id | mixes external business ids with internal idempotency ids Rejected: Adding new log table columns in phase 1 | this task only needs relay/log propagation, so other JSON is the minimal compatible path Confidence: medium Scope-risk: moderate Reversibility: clean Directive: Keep Muse business identifiers in dedicated context keys and log other fields; do not reuse internal request-id slots for external correlation ids Tested: go test ./middleware ./relay/common ./controller -run MuseRequestContext -count=1 Tested: go test ./middleware ./relay/common ./controller -count=1 Not-tested: Live relay call from Muse into a running new-api instance
75 lines
3.5 KiB
Go
75 lines
3.5 KiB
Go
package constant
|
|
|
|
type ContextKey string
|
|
|
|
const (
|
|
ContextKeyTokenCountMeta ContextKey = "token_count_meta"
|
|
ContextKeyPromptTokens ContextKey = "prompt_tokens"
|
|
ContextKeyEstimatedTokens ContextKey = "estimated_tokens"
|
|
|
|
ContextKeyOriginalModel ContextKey = "original_model"
|
|
ContextKeyRequestStartTime ContextKey = "request_start_time"
|
|
|
|
/* token related keys */
|
|
ContextKeyTokenUnlimited ContextKey = "token_unlimited_quota"
|
|
ContextKeyTokenKey ContextKey = "token_key"
|
|
ContextKeyTokenId ContextKey = "token_id"
|
|
ContextKeyTokenGroup ContextKey = "token_group"
|
|
ContextKeyTokenSpecificChannelId ContextKey = "specific_channel_id"
|
|
ContextKeyTokenModelLimitEnabled ContextKey = "token_model_limit_enabled"
|
|
ContextKeyTokenModelLimit ContextKey = "token_model_limit"
|
|
ContextKeyTokenCrossGroupRetry ContextKey = "token_cross_group_retry"
|
|
|
|
/* channel related keys */
|
|
ContextKeyChannelId ContextKey = "channel_id"
|
|
ContextKeyChannelName ContextKey = "channel_name"
|
|
ContextKeyChannelCreateTime ContextKey = "channel_create_time"
|
|
ContextKeyChannelBaseUrl ContextKey = "base_url"
|
|
ContextKeyChannelType ContextKey = "channel_type"
|
|
ContextKeyChannelSetting ContextKey = "channel_setting"
|
|
ContextKeyChannelOtherSetting ContextKey = "channel_other_setting"
|
|
ContextKeyChannelParamOverride ContextKey = "param_override"
|
|
ContextKeyChannelHeaderOverride ContextKey = "header_override"
|
|
ContextKeyChannelOrganization ContextKey = "channel_organization"
|
|
ContextKeyChannelAutoBan ContextKey = "auto_ban"
|
|
ContextKeyChannelModelMapping ContextKey = "model_mapping"
|
|
ContextKeyChannelStatusCodeMapping ContextKey = "status_code_mapping"
|
|
ContextKeyChannelIsMultiKey ContextKey = "channel_is_multi_key"
|
|
ContextKeyChannelMultiKeyIndex ContextKey = "channel_multi_key_index"
|
|
ContextKeyChannelKey ContextKey = "channel_key"
|
|
|
|
ContextKeyAutoGroup ContextKey = "auto_group"
|
|
ContextKeyAutoGroupIndex ContextKey = "auto_group_index"
|
|
ContextKeyAutoGroupRetryIndex ContextKey = "auto_group_retry_index"
|
|
|
|
/* user related keys */
|
|
ContextKeyUserId ContextKey = "id"
|
|
ContextKeyUserSetting ContextKey = "user_setting"
|
|
ContextKeyUserQuota ContextKey = "user_quota"
|
|
ContextKeyUserStatus ContextKey = "user_status"
|
|
ContextKeyUserEmail ContextKey = "user_email"
|
|
ContextKeyUserGroup ContextKey = "user_group"
|
|
ContextKeyUsingGroup ContextKey = "group"
|
|
ContextKeyUserName ContextKey = "username"
|
|
|
|
ContextKeyLocalCountTokens ContextKey = "local_count_tokens"
|
|
|
|
ContextKeySystemPromptOverride ContextKey = "system_prompt_override"
|
|
|
|
ContextKeyMuseUserID ContextKey = "muse_user_id"
|
|
ContextKeyMuseWorkID ContextKey = "muse_work_id"
|
|
ContextKeyMuseRequestID ContextKey = "muse_request_id"
|
|
ContextKeyMuseScene ContextKey = "muse_scene"
|
|
ContextKeyMuseTraceID ContextKey = "muse_trace_id"
|
|
|
|
// ContextKeyFileSourcesToCleanup stores file sources that need cleanup when request ends
|
|
ContextKeyFileSourcesToCleanup ContextKey = "file_sources_to_cleanup"
|
|
|
|
// ContextKeyAdminRejectReason stores an admin-only reject/block reason extracted from upstream responses.
|
|
// It is not returned to end users, but can be persisted into consume/error logs for debugging.
|
|
ContextKeyAdminRejectReason ContextKey = "admin_reject_reason"
|
|
|
|
// ContextKeyLanguage stores the user's language preference for i18n
|
|
ContextKeyLanguage ContextKey = "language"
|
|
)
|