# apps/web/src/utils
dir: apps/web/src/utils

index: apps/web/src/utils/.pi-map.index.md

## role
Provides shared utility functions for error handling, icons, syntax highlighting, session management, and time formatting across the web application.
## files
- errors.ts | Extracts human-readable error messages from API errors, handling Axios-style response structures with string or array detail formats | exp: extractErrorMessage
- icons.ts | Re-exports the IconName type from the icon component for external use. | dep: ../components/icon
- language.ts | Maps file extensions to Prism.js language identifiers and provides utilities for syntax highlighting with dynamic language loading. | exp: detectLanguage, highlightCode, loadLanguage | dep: prismjs
- open-session.ts | Opens a browser tab/window for a given session, reusing existing tabs if available | exp: func:openSession(session: Session) → void, call:tabRefs.get, call:existing.focus, call:session.tool_type_interfaces?.includes, call:window.open, call:tabRefs.set | dep: ../api/sessions, Session type from ../api/sessions
- time.ts | Formats a date string as a human-readable relative time string (e.g., "2h ago", "3d ago") | exp: func:formatRelativeTime(dateStr: string) → string, call:Math.max, call:Math.floor, call:now.getTime, call:date.getTime
## arch
Lightweight functional utilities with no internal dependencies between files, using TypeScript type exports and dynamic imports for code splitting.
## tags
time, language, session, open, call:tab, error, api, errors
## symbols
- openSession
- formatRelativeTime
- extractErrorMessage
- detectLanguage
- highlightCode
- loadLanguage
- call:tabRefs.get
- call:existing.focus
## workflows
- change utils behavior
  read: errors.ts, icons.ts, language.ts
## dirty
-
