refactor: remove waitForSession functionality from providers and related services

This commit is contained in:
Haileyesus
2026-04-06 23:14:19 +03:00
parent 7cd429697b
commit db9ab26c3c
4 changed files with 8 additions and 53 deletions

View File

@@ -45,14 +45,6 @@ const readPathParam = (value: unknown, name: string): string => {
const normalizeProviderParam = (value: unknown): string =>
readPathParam(value, 'provider').trim().toLowerCase();
/**
* Allows callers to block until a launched/resumed session reaches a final state.
*/
const parseWaitForCompletion = (req: Request): boolean => {
const value = (req.body as Record<string, unknown> | undefined)?.waitForCompletion;
return value === true;
};
/**
* Validates and normalizes rename payload.
*/
@@ -282,22 +274,13 @@ router.post(
asyncHandler(async (req: Request, res: Response) => {
const provider = parseProvider(req.params.provider);
const snapshot = await llmService.startSession(provider, req.body);
const waitForCompletion = parseWaitForCompletion(req);
if (!waitForCompletion) {
const formattedSnapshot = formatSessionSnapshot(provider, snapshot);
res.status(202).json(
createApiSuccessResponse({
provider,
session: formattedSnapshot,
}),
);
return;
}
const completedSnapshot = await llmService.waitForSession(provider, snapshot.sessionId);
const finalSnapshot = completedSnapshot ?? snapshot;
res.json(createApiSuccessResponse({ provider, session: formatSessionSnapshot(provider, finalSnapshot) }));
const formattedSnapshot = formatSessionSnapshot(provider, snapshot);
res.status(202).json(
createApiSuccessResponse({
provider,
session: formattedSnapshot,
}),
);
}),
);
@@ -308,16 +291,7 @@ router.post(
const sessionId = readPathParam(req.params.sessionId, 'sessionId');
const snapshot = await llmService.resumeSession(provider, sessionId, req.body);
const waitForCompletion = parseWaitForCompletion(req);
if (!waitForCompletion) {
res.status(202).json(createApiSuccessResponse({ provider, session: formatSessionSnapshot(provider, snapshot) }));
return;
}
const completedSnapshot = await llmService.waitForSession(provider, sessionId);
const finalSnapshot = completedSnapshot ?? snapshot;
res.json(createApiSuccessResponse({ provider, session: formatSessionSnapshot(provider, finalSnapshot) }));
res.status(202).json(createApiSuccessResponse({ provider, session: formatSessionSnapshot(provider, snapshot) }));
}),
);

View File

@@ -64,19 +64,6 @@ export abstract class AbstractProvider implements IProvider {
return [...this.sessions.values()].map((session) => this.toSnapshot(session));
}
/**
* Waits for a running session to complete and returns the final snapshot.
*/
async waitForSession(sessionId: string): Promise<ProviderSessionSnapshot | null> {
const session = this.sessions.get(sessionId);
if (!session) {
return null;
}
await session.completion;
return this.toSnapshot(session);
}
/**
* Requests a graceful session stop.
*/

View File

@@ -89,7 +89,6 @@ export interface IProvider {
getSession(sessionId: string): ProviderSessionSnapshot | null;
listSessions(): ProviderSessionSnapshot[];
waitForSession(sessionId: string): Promise<ProviderSessionSnapshot | null>;
}
/**

View File

@@ -123,11 +123,6 @@ export const llmService = {
return provider.resumeSession({ ...input, sessionId });
},
async waitForSession(providerName: string, sessionId: string): Promise<ProviderSessionSnapshot | null> {
const provider = llmProviderRegistry.resolveProvider(providerName);
return provider.waitForSession(sessionId);
},
async stopSession(providerName: string, sessionId: string): Promise<boolean> {
const provider = llmProviderRegistry.resolveProvider(providerName);
return provider.stopSession(sessionId);