singularity-forge/packages/pi-coding-agent/src/utils/error.ts
frizynn 3090f968f4 refactor: extract retry handler and compaction orchestrator from agent-session
Extract two self-contained subsystems from agent-session.ts (3,367 -> 2,737 lines):

- RetryHandler: auto-retry with exponential backoff, credential rotation,
  and cross-provider fallback logic
- CompactionOrchestrator: manual/auto compaction, overflow recovery, and
  extension integration for custom compaction providers

Also add shared getErrorMessage() utility to replace repeated
`err instanceof Error ? err.message : String(err)` patterns.

The extracted modules receive AgentSession state via dependency injection
interfaces, avoiding state duplication. AgentSession remains the coordinator
that delegates to these modules.
2026-03-19 16:46:14 -03:00

6 lines
190 B
TypeScript

/**
* Extract a human-readable message from an unknown caught value.
*/
export function getErrorMessage(err: unknown): string {
return err instanceof Error ? err.message : String(err);
}