(options: RuntimeNodeOpenADEOptions = {})
| 262 | } |
| 263 | |
| 264 | export function createRuntimeNodeOpenADEAdapters(options: RuntimeNodeOpenADEOptions = {}): OpenADEModuleAdapters { |
| 265 | const storage = createOpenADENodeYjsStorage(options.dataDir ?? defaultDataDir()) |
| 266 | const projection = createOpenADEYjsProjection({ |
| 267 | ...storage, |
| 268 | hostName: () => options.hostName, |
| 269 | }) |
| 270 | const writer = createOpenADEYjsWriter({ |
| 271 | ...storage, |
| 272 | hostName: () => options.hostName, |
| 273 | }) |
| 274 | const server = options.server |
| 275 | const agentExecutor = options.agentExecutor ?? createRuntimeNodeHarnessAgentExecutor() |
| 276 | const activeTaskExecutions = new Map<string, ActiveTaskExecution>() |
| 277 | if (server) { |
| 278 | server.registerRuntimeStopHandler((runtime) => |
| 279 | stopActiveOpenADERuntime({ |
| 280 | server, |
| 281 | writer, |
| 282 | agentExecutor, |
| 283 | activeTaskExecutions, |
| 284 | runtime, |
| 285 | }) |
| 286 | ) |
| 287 | void reconcileCheckpointedOpenADEActionEvents({ server, writer }) |
| 288 | } |
| 289 | |
| 290 | async function startTurn(params: OpenADETurnStartRequest, context?: { runtimeId?: string }): Promise<{ taskId: string; eventId: string }> { |
| 291 | let taskId = params.inTaskId || "" |
| 292 | if (!taskId) { |
| 293 | const createdAt = now() |
| 294 | const request: OpenADETaskCreateRequest = { |
| 295 | repoId: params.repoId, |
| 296 | input: params.input, |
| 297 | createdBy: { id: "headless-runtime", email: "headless@openade.local" }, |
| 298 | deviceId: "headless-runtime", |
| 299 | title: params.title ?? fallbackTitle(params.input), |
| 300 | taskId: taskIdForClientRequest(params.repoId, params.clientRequestId), |
| 301 | createdAt, |
| 302 | isolationStrategy: params.isolationStrategy, |
| 303 | enabledMcpServerIds: params.enabledMcpServerIds, |
| 304 | } |
| 305 | const result = await writer.createTask(request) |
| 306 | taskId = result.taskId |
| 307 | } |
| 308 | |
| 309 | const task = await projection.readTask(params.repoId, taskId) |
| 310 | const project = (await projection.readProjects()).find((candidate) => candidate.id === params.repoId) |
| 311 | if (!project) throw new Error(`Repository ${params.repoId} not found`) |
| 312 | |
| 313 | if (params.type === "hyperplan") { |
| 314 | const strategy = params.hyperplanStrategy |
| 315 | if (!strategy) { |
| 316 | return startTurn({ ...params, type: "plan", label: params.label ?? "HyperPlan", inTaskId: taskId }, context) |
| 317 | } |
| 318 | if (isStandardOpenADEHyperPlanStrategy(strategy)) { |
| 319 | const step = strategy.steps[0] |
| 320 | return startTurn( |
| 321 | { |
no test coverage detected