mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-04-21 21:11:30 +00:00
Move provider-specific normalizeMessage and fetchHistory logic out of the legacy server/providers adapters and into the refactored provider classes so callers can depend on the main provider contract instead of parallel adapter plumbing. Add a providers service to resolve concrete providers through the registry and delegate message normalization/history loading from realtime handlers and the unified messages route. Add shared TypeScript message/history types and normalized message helpers so provider implementations and callers use the same contract. Remove the old adapter registry/files now that Claude, Codex, Cursor, and Gemini implement the required behavior directly.
62 lines
2.0 KiB
JavaScript
62 lines
2.0 KiB
JavaScript
/**
|
|
* Unified messages endpoint.
|
|
*
|
|
* GET /api/sessions/:sessionId/messages?provider=claude&projectName=foo&limit=50&offset=0
|
|
*
|
|
* Replaces the four provider-specific session message endpoints with a single route
|
|
* that delegates to the appropriate adapter via the provider registry.
|
|
*
|
|
* @module routes/messages
|
|
*/
|
|
|
|
import express from 'express';
|
|
import { providersService } from '../modules/providers/services/providers.service.js';
|
|
|
|
const router = express.Router();
|
|
|
|
/**
|
|
* GET /api/sessions/:sessionId/messages
|
|
*
|
|
* Auth: authenticateToken applied at mount level in index.js
|
|
*
|
|
* Query params:
|
|
* provider - 'claude' | 'cursor' | 'codex' | 'gemini' (default: 'claude')
|
|
* projectName - required for claude provider
|
|
* projectPath - required for cursor provider (absolute path used for cwdId hash)
|
|
* limit - page size (omit or null for all)
|
|
* offset - pagination offset (default: 0)
|
|
*/
|
|
router.get('/:sessionId/messages', async (req, res) => {
|
|
try {
|
|
const { sessionId } = req.params;
|
|
const provider = String(req.query.provider || 'claude').trim().toLowerCase();
|
|
const projectName = req.query.projectName || '';
|
|
const projectPath = req.query.projectPath || '';
|
|
const limitParam = req.query.limit;
|
|
const limit = limitParam !== undefined && limitParam !== null && limitParam !== ''
|
|
? parseInt(limitParam, 10)
|
|
: null;
|
|
const offset = parseInt(req.query.offset || '0', 10);
|
|
|
|
const availableProviders = providersService.listProviderIds();
|
|
if (!availableProviders.includes(provider)) {
|
|
const available = availableProviders.join(', ');
|
|
return res.status(400).json({ error: `Unknown provider: ${provider}. Available: ${available}` });
|
|
}
|
|
|
|
const result = await providersService.fetchHistory(provider, sessionId, {
|
|
projectName,
|
|
projectPath,
|
|
limit,
|
|
offset,
|
|
});
|
|
|
|
return res.json(result);
|
|
} catch (error) {
|
|
console.error('Error fetching unified messages:', error);
|
|
return res.status(500).json({ error: 'Failed to fetch messages' });
|
|
}
|
|
});
|
|
|
|
export default router;
|