chat: rename the pi chat transport + model list to chat (Stage 4b/1)
Pure rename, no behavior change. Moves the misnamed "pi" chat harness into the
chat namespace:
- api/pi/{websocket,session-manager,types,logger,list-models} → api/chat/
- merge api/pi/rest.ts into api/chat/chat.ts (/pi/models → /chat/models,
/pi/stt → /chat/stt); drop the piRestRouter mount
- PiEvent → ChatEvent, piWebsocket → chatWebsocket, listPiModels → listChatModels
- WS route /api/pi/chat/ws → /api/chat/ws, provider tag 'pi' → 'chat'
- frontend: useChat/useAudioRecording URLs, usePiModels→useModels /
useVisiblePiModels→useVisibleModels / useEnabledPiModels→useEnabledModels,
'PI_MODELS' query key → 'CHAT_MODELS', attachments provider 'pi-mono' → 'chat'
The /pi-mono provider/harness settings router is renamed separately (next commit).
Note: the WS route change requires the mobile app to point at /api/chat/ws.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Structured logging utility for Pi harness
|
||||
*/
|
||||
|
||||
export type LogLevel = 'DEBUG' | 'INFO' | 'WARN' | 'ERROR';
|
||||
|
||||
type LogContext = {
|
||||
sessionId?: string;
|
||||
email?: string;
|
||||
model?: string;
|
||||
requestId?: string;
|
||||
[key: string]: unknown;
|
||||
};
|
||||
|
||||
const LOG_COLORS = {
|
||||
DEBUG: '\x1b[36m', // Cyan
|
||||
INFO: '\x1b[32m', // Green
|
||||
WARN: '\x1b[33m', // Yellow
|
||||
ERROR: '\x1b[31m', // Red
|
||||
RESET: '\x1b[0m',
|
||||
};
|
||||
|
||||
function formatTimestamp(): string {
|
||||
return new Date().toISOString();
|
||||
}
|
||||
|
||||
function formatContext(context?: LogContext): string {
|
||||
if (!context || Object.keys(context).length === 0) return '';
|
||||
|
||||
const lines = Object.entries(context)
|
||||
.map(([key, value]) => ` ${key}=${value}`)
|
||||
.join('\n');
|
||||
|
||||
return '\n' + lines;
|
||||
}
|
||||
|
||||
function log(level: LogLevel, message: string, context?: LogContext) {
|
||||
const timestamp = formatTimestamp();
|
||||
const color = LOG_COLORS[level];
|
||||
const reset = LOG_COLORS.RESET;
|
||||
const contextStr = formatContext(context);
|
||||
|
||||
console.log(`${color}[${timestamp}] [Pi] [${level}]${reset} ${message}${contextStr}`);
|
||||
}
|
||||
|
||||
export const logger = {
|
||||
debug(message: string, context?: LogContext) {
|
||||
log('DEBUG', message, context);
|
||||
},
|
||||
|
||||
info(message: string, context?: LogContext) {
|
||||
log('INFO', message, context);
|
||||
},
|
||||
|
||||
warn(message: string, context?: LogContext) {
|
||||
log('WARN', message, context);
|
||||
},
|
||||
|
||||
error(message: string, context?: LogContext) {
|
||||
log('ERROR', message, context);
|
||||
},
|
||||
};
|
||||
Reference in New Issue
Block a user