|
| 1 | +/** Doctor repair for stale plugin-owned routing state persisted in session entries. */ |
1 | 2 | import { normalizeOptionalString as normalizeString } from "@openclaw/normalization-core/string-coerce"; |
2 | 3 | import { normalizeStringEntriesLower } from "@openclaw/normalization-core/string-normalization"; |
3 | 4 | import { note } from "../../packages/terminal-core/src/note.js"; |
@@ -58,6 +59,7 @@ function resolveSessionAgentId(cfg: OpenClawConfig, sessionKey: string): string |
58 | 59 | return parseAgentSessionKey(sessionKey)?.agentId ?? resolveDefaultAgentId(cfg); |
59 | 60 | } |
60 | 61 |
|
| 62 | +/** Resolves the currently configured provider/model/runtime route for a session key. */ |
61 | 63 | export function resolveConfiguredDoctorSessionStateRoute(params: { |
62 | 64 | cfg: OpenClawConfig; |
63 | 65 | sessionKey: string; |
@@ -121,6 +123,7 @@ function entryMayContainPluginSessionRouteState(entry: SessionEntry): boolean { |
121 | 123 | ); |
122 | 124 | } |
123 | 125 |
|
| 126 | +/** Fast prefilter for session stores that might contain plugin-owned routing state. */ |
124 | 127 | export function storeMayContainPluginSessionRouteState( |
125 | 128 | store: Record<string, SessionEntry>, |
126 | 129 | ): boolean { |
@@ -328,6 +331,7 @@ function scanEntryForOwner(params: { |
328 | 331 | }; |
329 | 332 | } |
330 | 333 |
|
| 334 | +/** Scans session entries for state owned by plugins that no longer match the configured route. */ |
331 | 335 | export function scanSessionRouteStateOwners(params: { |
332 | 336 | owners: readonly DoctorSessionRouteStateOwner[]; |
333 | 337 | store: Record<string, Record<string, unknown>>; |
@@ -386,6 +390,7 @@ function clearRecordKeys( |
386 | 390 | return true; |
387 | 391 | } |
388 | 392 |
|
| 393 | +/** Clears stale plugin-owned routing fields from a session entry and refreshes updatedAt. */ |
389 | 394 | export function applySessionRouteStateRepair(params: { |
390 | 395 | entry: Record<string, unknown>; |
391 | 396 | repair: DoctorSessionRouteStateRepair; |
@@ -443,6 +448,7 @@ function groupRepairsByOwner( |
443 | 448 | return grouped; |
444 | 449 | } |
445 | 450 |
|
| 451 | +/** Prompts for and applies plugin-owned session route state repairs to the session store. */ |
446 | 452 | export async function runPluginSessionStateDoctorRepairs(params: { |
447 | 453 | cfg: OpenClawConfig; |
448 | 454 | store: Record<string, SessionEntry>; |
|
0 commit comments