Add openai_gateway/apps.py as the single list of internal gateway apps and send X-OpenRouter-Title (plus legacy X-Title and HTTP-Referer) per app to every upstream. Label the Devii agent, bots, modifier, quiz grading, SEO metadata, community and sync callers. Shorten two app references that exceeded the 30 character limit and were recorded as default. Also includes the pending Muse Code, route health and Responses work. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
78 lines
2.7 KiB
Python
78 lines
2.7 KiB
Python
# retoor <retoor@molodetz.nl>
|
|
|
|
import re
|
|
from dataclasses import dataclass
|
|
|
|
from devplacepy import config as devplace_config
|
|
|
|
PLATFORM_TITLE = "DevPlace"
|
|
TITLE_HEADER = "X-OpenRouter-Title"
|
|
LEGACY_TITLE_HEADER = "X-Title"
|
|
REFERER_HEADER = "HTTP-Referer"
|
|
APP_REFERENCE_HEADER = "X-App-Reference"
|
|
APP_REFERENCE_PATTERN = re.compile(r"^[a-zA-Z0-9_.-]{1,30}$")
|
|
DEFAULT_APP_REFERENCE = "default"
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class GatewayApp:
|
|
reference: str
|
|
name: str
|
|
|
|
@property
|
|
def title(self) -> str:
|
|
return f"{PLATFORM_TITLE} {self.name}"
|
|
|
|
|
|
GATEWAY_APPS: tuple[GatewayApp, ...] = (
|
|
GatewayApp("devplace-devii-v-1-0-0", "Devii"),
|
|
GatewayApp("devplace-news-v-1-0-0", "News"),
|
|
GatewayApp("devplace-bots-v-1-0-0", "Bots"),
|
|
GatewayApp("devplace-correction-v-1-0-0", "AI Correction"),
|
|
GatewayApp("devplace-modifier-v-1-0-0", "AI Modifier"),
|
|
GatewayApp("devplace-quiz-grading-v-1-0-0", "Quiz Grading"),
|
|
GatewayApp("devplace-seo-meta-v-1-0-0", "SEO Metadata"),
|
|
GatewayApp("devplace-deepsearch-v-1-0-0", "DeepSearch"),
|
|
GatewayApp("devplace-isslop-v-1-0-0", "AI Usage Analyzer"),
|
|
GatewayApp("devplace-gitea-enhance-v-1-0-0", "Issue Enhance"),
|
|
GatewayApp("devplace-gitea-plan-v-1-0-0", "Issue Planning"),
|
|
GatewayApp("devplace-dbapi-v-1-0-0", "DB API"),
|
|
GatewayApp("devplace-awards-v-1-0-0", "Awards"),
|
|
GatewayApp("devplace-image-gen-v-1-0-0", "Image Generation"),
|
|
GatewayApp("devplace-devii-rsearch-v-1-0-0", "Devii Research"),
|
|
GatewayApp("devplace-community-v-1-0-0", "Community Discovery"),
|
|
GatewayApp("devplace-sync-v-1-0-0", "Community Sync"),
|
|
)
|
|
|
|
_APPS_BY_REFERENCE = {app.reference: app for app in GATEWAY_APPS}
|
|
|
|
APP_REFERENCE_DEVII = "devplace-devii-v-1-0-0"
|
|
APP_REFERENCE_NEWS = "devplace-news-v-1-0-0"
|
|
APP_REFERENCE_BOTS = "devplace-bots-v-1-0-0"
|
|
APP_REFERENCE_CORRECTION = "devplace-correction-v-1-0-0"
|
|
APP_REFERENCE_MODIFIER = "devplace-modifier-v-1-0-0"
|
|
APP_REFERENCE_QUIZ_GRADING = "devplace-quiz-grading-v-1-0-0"
|
|
APP_REFERENCE_SEO_META = "devplace-seo-meta-v-1-0-0"
|
|
APP_REFERENCE_COMMUNITY = "devplace-community-v-1-0-0"
|
|
APP_REFERENCE_SYNC = "devplace-sync-v-1-0-0"
|
|
|
|
|
|
def validate_app_reference(value: str) -> str:
|
|
stripped = (value or "").strip()
|
|
if not stripped or not APP_REFERENCE_PATTERN.match(stripped):
|
|
return DEFAULT_APP_REFERENCE
|
|
return stripped
|
|
|
|
|
|
def app_title(app_reference: str) -> str:
|
|
app = _APPS_BY_REFERENCE.get(app_reference or "")
|
|
return app.title if app else PLATFORM_TITLE
|
|
|
|
|
|
def attribution_headers(app_reference: str = DEFAULT_APP_REFERENCE) -> dict:
|
|
title = app_title(app_reference)
|
|
headers = {TITLE_HEADER: title, LEGACY_TITLE_HEADER: title}
|
|
if devplace_config.SITE_URL:
|
|
headers[REFERER_HEADER] = devplace_config.SITE_URL
|
|
return headers
|