Files
AgentCompany/src/main/orchestration/index.ts
T
ZacharyZhang-NY a69fbb053b Codemod db pass-through calls: messages + runs + approvals + company (C1 part 2/3)
Rewrite ~376 call sites for messages, runs, approvalsMod, and company
domains and delete the corresponding pass-through methods on
AppDatabase / AppDatabaseBase. Structural type references
(ReturnType<HandlerDeps["db"]["getRun"]>) and SweepStaleReviewsDeps-style
mocks are updated to route through the owning sub-module.
2026-04-20 13:20:15 -04:00

47 lines
1.5 KiB
TypeScript

import type { OrchestrationDependencies } from "./types";
import { createRunDispatch } from "./run-dispatch";
import { createHeartbeat } from "./heartbeat";
import { createScheduler } from "./scheduler";
import { createTaskRunner } from "./task-runner";
export function createOrchestrationService(deps: OrchestrationDependencies) {
const { db } = deps;
function hasActiveRun(filter: { taskId?: string; agentId?: string; companyId: string }) {
return db.runs.hasActiveRun(filter);
}
const runDispatch = createRunDispatch(deps);
const heartbeat = createHeartbeat(
deps,
runDispatch.resolveWorkspace,
runDispatch.getRunEligibilityFailure,
runDispatch.dispatchRunToWorker,
hasActiveRun,
);
const scheduler = createScheduler(
deps,
hasActiveRun,
heartbeat.startAgentHeartbeatRun,
heartbeat.wakeAgentIfPossible,
);
const taskRunner = createTaskRunner(
deps,
runDispatch.resolveWorkspace,
runDispatch.getRunEligibilityFailure,
runDispatch.dispatchRunToWorker,
hasActiveRun,
);
return {
resolveWorkspace: runDispatch.resolveWorkspace,
wakeAgentIfPossible: heartbeat.wakeAgentIfPossible,
dispatchRunToWorker: runDispatch.dispatchRunToWorker,
queueTaskRun: taskRunner.queueTaskRun,
resumeQueuedRuns: taskRunner.resumeQueuedRuns,
startAgentHeartbeatRun: heartbeat.startAgentHeartbeatRun,
startAllSchedulers: scheduler.startAllSchedulers,
stopAllSchedulers: scheduler.stopAllSchedulers,
};
}