diff --git a/page_api.py b/page_api.py index 6cdc421..d753960 100644 --- a/page_api.py +++ b/page_api.py @@ -131,6 +131,48 @@ class PrivateCompanionPageApi(PrivateCompanionPageApiQzoneMixin, PrivateCompanio self.plugin = plugin self._schema_key_index_cache: dict[str, Any] | None = None + @staticmethod + def _relationship_intimacy_projection(value: int) -> dict[str, Any]: + """Return the admin-facing phase for the legacy companion baseline only.""" + score = max(-1200, min(1200, int(value))) + if score <= -801: + phase_key, phase_label = "deeply_distant", "极度疏离" + elif score <= -401: + phase_key, phase_label = "strongly_distant", "强烈疏离" + elif score < 0: + phase_key, phase_label = "distant", "疏离" + elif score <= 199: + phase_key, phase_label = "acquaintance", "初识" + elif score <= 599: + phase_key, phase_label = "familiar", "熟悉" + elif score <= 899: + phase_key, phase_label = "close", "亲近" + elif score < 1200: + phase_key, phase_label = "intimate", "亲密" + else: + phase_key, phase_label = "deeply_bonded", "深度联结" + return { + "value": score, + "band": phase_label, + "phase": {"key": phase_key, "label": phase_label}, + "min": -1200, + "max": 1200, + "trend": "unknown", + } + + @staticmethod + def _p4_page_status_projection() -> dict[str, Any]: + """Return a fixed page-safe P4 status without resolving any person.""" + return { + "schema_version": "chat.p4.page_status.v1", + "scope": "chat_event_only", + "reply_gate": "host_verified_event_only", + "warmth": "host_verified_event_only", + "confinement": "not_exposed_to_page", + "manual_review": "not_migrated", + "action_available": False, + } + def _relationship_panel( self, user_id: str, @@ -153,8 +195,7 @@ class PrivateCompanionPageApi(PrivateCompanionPageApiQzoneMixin, PrivateCompanio else: reply_band = "low" - score = self._int(user.get("relationship_score")) - basis = "close" if score >= 55 else "familiar" if score >= 3 else "initial" + relationship_intimacy = self._relationship_intimacy_projection(self._int(user.get("relationship_score"))) memory_phase = {"status": "unavailable", "phase": "unknown", "momentum_band": "unknown"} getter = getattr(self.plugin, "_memory_companion_peek_relationship_phase", None) session_id = self._single_line(user.get("umo"), 200) @@ -177,8 +218,12 @@ class PrivateCompanionPageApi(PrivateCompanionPageApiQzoneMixin, PrivateCompanio "pending_observation_count": max(0, self._int(worldbook_member.get("pending_observation_count"))) if isinstance(worldbook_member, dict) else 0, } return { - "relationship_basis": {"band": basis}, + "relationship_basis": { + "value": relationship_intimacy["value"], + "band": relationship_intimacy["phase"]["label"], + }, "relationship_stage": self._single_line(relationship_stage, 24) or "unclassified", + "relationship_intimacy": relationship_intimacy, "interaction": {"inbound_count": inbound, "reply_count": replies, "reply_band": reply_band}, "memory_phase": memory_phase, "network": network, @@ -283,6 +328,7 @@ class PrivateCompanionPageApi(PrivateCompanionPageApiQzoneMixin, PrivateCompanio register = self.plugin.context.register_web_api routes = [ ("/overview", self.get_overview, ["GET"], "Private Companion Page overview"), + ("/ops/status", self.get_ops_status, ["GET"], "Private Companion Page safe P4 status"), ("/expression-library", self.get_expression_library, ["GET"], "Private Companion Page expression library"), ("/expression-library/update", self.update_expression_library, ["POST"], "Private Companion Page update expression library"), ("/users", self.list_users, ["GET"], "Private Companion Page users"), @@ -398,6 +444,10 @@ class PrivateCompanionPageApi(PrivateCompanionPageApiQzoneMixin, PrivateCompanio for path, handler, methods, desc in routes: register(f"{PAGE_API_PREFIX}{path}", handler, methods, desc) + async def get_ops_status(self) -> dict[str, Any]: + """Expose only the page-safe P4 status; no identity or ledger lookup.""" + return self._ok({"p4_runtime": self._p4_page_status_projection()}) + async def get_overview(self) -> dict[str, Any]: start = time.perf_counter() try: @@ -9824,6 +9874,7 @@ class PrivateCompanionPageApi(PrivateCompanionPageApiQzoneMixin, PrivateCompanio relationship_state = self._emotion_relationship_state_summary(rel_state) pending_emotion_judgement = self._emotion_pending_judgement_summary(user.get("pending_emotion_judgement")) last_emotion_judgement_error = self._single_line(user.get("last_emotion_judgement_error"), 160) + relationship_intimacy = self._relationship_intimacy_projection(self._int(user.get("relationship_score"))) return { "user_id": user_id_text, "display_name": display_name, @@ -9894,6 +9945,11 @@ class PrivateCompanionPageApi(PrivateCompanionPageApiQzoneMixin, PrivateCompanio "reply_count": user.get("reply_count", 0), "proactive_sent_count": user.get("proactive_sent_count", 0), "relationship_score": user.get("relationship_score", 0), + "relationship_basis": { + "value": relationship_intimacy["value"], + "band": relationship_intimacy["phase"]["label"], + }, + "relationship_intimacy": relationship_intimacy, "relationship_stage": relationship_stage, "relationship_state": relationship_state, "pending_emotion_judgement": pending_emotion_judgement, diff --git a/page_api_users_groups.py b/page_api_users_groups.py index 6972190..baa6e3c 100644 --- a/page_api_users_groups.py +++ b/page_api_users_groups.py @@ -14,6 +14,21 @@ from .helpers import _safe_int class PrivateCompanionPageApiUsersGroupsMixin: + @staticmethod + def _relationship_score_input(value: Any) -> int: + """Parse the dedicated manual companion intimacy baseline field.""" + if isinstance(value, bool): + raise ValueError("relationship_score must be an integer") + if isinstance(value, int): + score = value + elif isinstance(value, str) and re.fullmatch(r"[+-]?\d+", value.strip()): + score = int(value.strip()) + else: + raise ValueError("relationship_score must be an integer") + if not -1200 <= score <= 1200: + raise ValueError("relationship_score must be between -1200 and 1200") + return score + async def list_users(self) -> dict[str, Any]: start = time.perf_counter() try: @@ -49,6 +64,7 @@ class PrivateCompanionPageApiUsersGroupsMixin: relationship_stage=str(detail.get("relationship_stage") or ""), worldbook_member=worldbook_member, ) + detail["p4_runtime"] = self._p4_page_status_projection() route_status_getter = getattr(self.plugin, "_private_delivery_route_status", None) delivery_route = route_status_getter(user_id, user) if callable(route_status_getter) else {} detail.update( @@ -81,6 +97,15 @@ class PrivateCompanionPageApiUsersGroupsMixin: user_id = str(payload.get("user_id", "")).strip() if not user_id: return self._error("缺少 user_id") + relationship_score = None + intimacy_keys = [key for key in ("companion_intimacy", "relationship_score") if key in payload] + if len(intimacy_keys) > 1: + return self._error("陪伴亲密度字段不能重复提交") + if intimacy_keys: + try: + relationship_score = self._relationship_score_input(payload.get(intimacy_keys[0])) + except ValueError as exc: + return self._error(str(exc)) try: action_message = "" async with self.plugin._data_lock: @@ -105,6 +130,8 @@ class PrivateCompanionPageApiUsersGroupsMixin: if role: user["relationship_role"] = role expression_voice_needs_refresh = role != previous_role + if relationship_score is not None: + user["relationship_score"] = relationship_score if "proactive_daily_limit" in payload: user["proactive_daily_limit"] = _safe_int(payload.get("proactive_daily_limit"), -1, -1, 30) for key in ( diff --git a/pages/陪伴面板/app.css b/pages/陪伴面板/app.css index fa580b2..5b0f9c7 100644 --- a/pages/陪伴面板/app.css +++ b/pages/陪伴面板/app.css @@ -2089,6 +2089,59 @@ input[type="search"] { grid-template-columns: repeat(4, minmax(0, 1fr)) auto; } +.companion-intimacy-card { + display: grid; + gap: 10px; + margin: 0 0 14px; + padding: 14px; + border: 1px solid rgba(49, 128, 111, 0.28); + border-radius: 8px; + background: #f7fbf8; + box-shadow: var(--shadow-soft); +} + +.companion-intimacy-head, +.companion-intimacy-meta { + display: flex; + align-items: center; + justify-content: space-between; + gap: 12px; +} + +.companion-intimacy-head h3 { + margin: 2px 0 0; +} + +.companion-intimacy-value { + color: var(--accent-strong); + font-size: 28px; + line-height: 1; +} + +.companion-intimacy-form { + grid-template-columns: minmax(180px, 260px) auto; + align-items: end; + margin: 0; +} + +.companion-intimacy-phase { + display: inline-flex; + align-items: baseline; + gap: 6px; + color: var(--text-muted); + font-size: 12px; +} + +.companion-intimacy-phase strong { + color: var(--accent-strong); + font-size: 15px; +} + +.companion-intimacy-note { + grid-column: 1 / -1; + font-size: 12px; +} + .stack-form { display: grid; gap: 10px; diff --git a/pages/陪伴面板/app.js b/pages/陪伴面板/app.js index 1996296..7f9e834 100644 --- a/pages/陪伴面板/app.js +++ b/pages/陪伴面板/app.js @@ -12313,7 +12313,7 @@ function renderUsers() { ? rows.map((user) => `