feat(orchestrator): add SSE events, queue controls, and mosaic rails sync
This commit is contained in:
@@ -37,6 +37,24 @@ export class AgentLifecycleService {
|
||||
this.logger.log("AgentLifecycleService initialized");
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a newly spawned agent in persistent state and emit spawned event.
|
||||
*/
|
||||
async registerSpawnedAgent(agentId: string, taskId: string): Promise<AgentState> {
|
||||
await this.valkeyService.createAgent(agentId, taskId);
|
||||
const createdState = await this.getAgentState(agentId);
|
||||
|
||||
const event: AgentEvent = {
|
||||
type: "agent.spawned",
|
||||
agentId,
|
||||
taskId,
|
||||
timestamp: new Date().toISOString(),
|
||||
};
|
||||
await this.valkeyService.publishEvent(event);
|
||||
|
||||
return createdState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Acquire a per-agent mutex to serialize state transitions.
|
||||
* Uses promise chaining: each caller chains onto the previous lock,
|
||||
|
||||
@@ -116,6 +116,33 @@ export class AgentSpawnerService implements OnModuleDestroy {
|
||||
return this.sessions.get(agentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find an active session by task ID.
|
||||
*/
|
||||
findAgentSessionByTaskId(taskId: string): AgentSession | undefined {
|
||||
return Array.from(this.sessions.values()).find((session) => session.taskId === taskId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update in-memory session state for visibility in list/status endpoints.
|
||||
*/
|
||||
setSessionState(
|
||||
agentId: string,
|
||||
state: AgentSession["state"],
|
||||
error?: string,
|
||||
completedAt?: Date
|
||||
): void {
|
||||
const session = this.sessions.get(agentId);
|
||||
if (!session) return;
|
||||
|
||||
session.state = state;
|
||||
session.error = error;
|
||||
if (completedAt) {
|
||||
session.completedAt = completedAt;
|
||||
}
|
||||
this.sessions.set(agentId, session);
|
||||
}
|
||||
|
||||
/**
|
||||
* List all agent sessions
|
||||
* @returns Array of all agent sessions
|
||||
|
||||
Reference in New Issue
Block a user