mirror of
https://github.com/siteboon/claudecodeui.git
synced 2026-06-12 09:02:08 +08:00
feat(chat): unify session gateway with stable IDs and a single WS protocol
The frontend previously juggled placeholder IDs, provider-native IDs, and session_created handoffs, which caused race conditions and provider-specific branching. This introduces app-allocated session IDs, a chat run registry with event replay, delta sidebar updates, and one kind-based websocket contract so the UI can treat every provider the same while JSONL remains the source of truth.
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import express, { type Request, type Response } from 'express';
|
||||
|
||||
import { providerAuthService } from '@/modules/providers/services/provider-auth.service.js';
|
||||
import { providerCapabilitiesService } from '@/modules/providers/services/provider-capabilities.service.js';
|
||||
import { providerMcpService } from '@/modules/providers/services/mcp.service.js';
|
||||
import { providerModelsService } from '@/modules/providers/services/provider-models.service.js';
|
||||
import { providerSkillsService } from '@/modules/providers/services/skills.service.js';
|
||||
@@ -382,7 +383,43 @@ router.post(
|
||||
}),
|
||||
);
|
||||
|
||||
router.get(
|
||||
'/capabilities',
|
||||
asyncHandler(async (_req: Request, res: Response) => {
|
||||
res.json(createApiSuccessResponse({
|
||||
providers: providerCapabilitiesService.listAllProviderCapabilities(),
|
||||
}));
|
||||
}),
|
||||
);
|
||||
|
||||
router.get(
|
||||
'/:provider/capabilities',
|
||||
asyncHandler(async (req: Request, res: Response) => {
|
||||
const provider = parseProvider(req.params.provider);
|
||||
res.json(createApiSuccessResponse(
|
||||
providerCapabilitiesService.getProviderCapabilities(provider),
|
||||
));
|
||||
}),
|
||||
);
|
||||
|
||||
// ----------------- Session routes -----------------
|
||||
/**
|
||||
* Session gateway entry point: allocates the stable app-facing session id for
|
||||
* a brand-new chat. The frontend must call this before the first `chat.send`
|
||||
* so the session id in the URL, the store, and the websocket all agree from
|
||||
* the very first message — there is no client-visible session-id handoff.
|
||||
*/
|
||||
router.post(
|
||||
'/sessions',
|
||||
asyncHandler(async (req: Request, res: Response) => {
|
||||
const body = (req.body ?? {}) as Record<string, unknown>;
|
||||
const provider = parseProvider(body.provider);
|
||||
const projectPath = typeof body.projectPath === 'string' ? body.projectPath : '';
|
||||
const result = sessionsService.createAppSession(provider, projectPath);
|
||||
res.status(201).json(createApiSuccessResponse(result));
|
||||
}),
|
||||
);
|
||||
|
||||
router.get(
|
||||
'/sessions/archived',
|
||||
asyncHandler(async (_req: Request, res: Response) => {
|
||||
@@ -459,7 +496,7 @@ router.get(
|
||||
limit,
|
||||
offset,
|
||||
});
|
||||
res.json(result);
|
||||
res.json(createApiSuccessResponse(result));
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user