{"version":3,"sources":["/Users/shyun/comcom/ain-enterprise/ain-adk/dist/cjs/chunk-KSUPRATS.cjs","../../src/services/user-workflow-coordinator.service.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACA;ACJA,oDAA4B;AAC5B,yFAAiB;AAMV,IAAM,+BAAA,EAAN,MAAqC;AAAA,EACnC;AAAA,EACA;AAAA,EAER,WAAA,CACC,mBAAA,EACA,gBAAA,EACC;AACD,IAAA,IAAA,CAAK,oBAAA,EAAsB,mBAAA;AAC3B,IAAA,IAAA,CAAK,iBAAA,EAAmB,gBAAA;AAAA,EACzB;AAAA,EAEQ,mBAAA,CAAoB,QAAA,EAAoC;AAC/D,IAAA,GAAA,CAAI,SAAA,GAAY,CAAC,kBAAA,CAAK,QAAA,CAAS,QAAQ,CAAA,EAAG;AACzC,MAAA,MAAM,IAAI,mCAAA;AAAA,QACT,4BAAA,CAAY,WAAA;AAAA,QACZ,CAAA,yBAAA,EAA4B,QAAQ,CAAA;AAAA,MAAA;AACrC,IAAA;AACD,EAAA;AACD,EAAA;AAGC,IAAA;AACA,IAAA;AACA,IAAA;AACC,MAAA;AAAoD,IAAA;AAErD,IAAA;AAAO,EAAA;AACR,EAAA;AAMC,IAAA;AACA,IAAA;AACA,IAAA;AAEA,IAAA;AACC,MAAA;AAAO,IAAA;AAER,IAAA;AAGA,IAAA;AAEC,EAAA;AAEF,EAAA;AAGC,IAAA;AACA,IAAA;AAAyD,EAAA;AAE3D;ADhBA;AACA;AACA;AACA","file":"/Users/shyun/comcom/ain-enterprise/ain-adk/dist/cjs/chunk-KSUPRATS.cjs","sourcesContent":[null,"import { StatusCodes } from \"http-status-codes\";\nimport cron from \"node-cron\";\nimport { AinHttpError } from \"@/types/agent.js\";\nimport type { UserWorkflow } from \"@/types/memory.js\";\nimport type { SchedulerService } from \"./scheduler.service.js\";\nimport type { UserWorkflowService } from \"./user-workflow.service.js\";\n\nexport class UserWorkflowCoordinatorService {\n\tprivate userWorkflowService: UserWorkflowService;\n\tprivate schedulerService: SchedulerService;\n\n\tconstructor(\n\t\tuserWorkflowService: UserWorkflowService,\n\t\tschedulerService: SchedulerService,\n\t) {\n\t\tthis.userWorkflowService = userWorkflowService;\n\t\tthis.schedulerService = schedulerService;\n\t}\n\n\tprivate assertValidSchedule(schedule: string | undefined): void {\n\t\tif (schedule && !cron.validate(schedule)) {\n\t\t\tthrow new AinHttpError(\n\t\t\t\tStatusCodes.BAD_REQUEST,\n\t\t\t\t`Invalid cron expression: ${schedule}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tasync createWorkflow(workflow: UserWorkflow): Promise<UserWorkflow> {\n\t\tthis.assertValidSchedule(workflow.schedule);\n\t\tconst created = await this.userWorkflowService.createWorkflow(workflow);\n\t\tif (created.active && created.schedule) {\n\t\t\tawait this.schedulerService.scheduleWorkflow(created);\n\t\t}\n\t\treturn created;\n\t}\n\n\tasync updateWorkflow(\n\t\tworkflowId: string,\n\t\tupdates: Partial<UserWorkflow>,\n\t): Promise<UserWorkflow | undefined> {\n\t\tthis.assertValidSchedule(updates.schedule);\n\t\tawait this.userWorkflowService.updateWorkflow(workflowId, updates);\n\t\tconst updatedWorkflow =\n\t\t\tawait this.userWorkflowService.getWorkflow(workflowId);\n\t\tif (!updatedWorkflow) {\n\t\t\treturn undefined;\n\t\t}\n\t\tawait this.schedulerService.rescheduleWorkflow(updatedWorkflow);\n\t\t// rescheduleWorkflow가 nextRunAt을 다시 계산해 저장하므로, 호출자(API 응답)가\n\t\t// 최신 스케줄 상태를 받도록 재조회해서 돌려준다.\n\t\treturn (\n\t\t\t(await this.userWorkflowService.getWorkflow(workflowId)) ??\n\t\t\tupdatedWorkflow\n\t\t);\n\t}\n\n\tasync deleteWorkflow(workflowId: string, userId: string): Promise<void> {\n\t\tawait this.userWorkflowService.deleteWorkflow(workflowId, userId);\n\t\tawait this.schedulerService.unscheduleWorkflow(workflowId);\n\t}\n}\n"]}