{"version":3,"sources":["/Users/shyun/comcom/ain-enterprise/ain-adk/dist/cjs/chunk-IIKB3JRC.cjs","../../src/controllers/api/user-workflow.api.controller.ts"],"names":[],"mappings":"AAAA;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B;AACA;ACTA,oDAA4B;AAWrB,IAAM,0BAAA,YAAN,MAAgC;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAER,WAAA,CACC,mBAAA,EACA,8BAAA,EACA,wBAAA,EACA,YAAA,EACC;AACD,IAAA,IAAA,CAAK,oBAAA,EAAsB,mBAAA;AAC3B,IAAA,IAAA,CAAK,+BAAA,EAAiC,8BAAA;AACtC,IAAA,IAAA,CAAK,yBAAA,EAA2B,wBAAA;AAChC,IAAA,IAAA,CAAK,aAAA,EAAe,YAAA;AAAA,EACrB;AAAA,EAEA,MAAc,qBAAA,CACb,MAAA,EACA,UAAA,EACwB;AACxB,IAAA,MAAM,SAAA,EAAW,MAAM,IAAA,CAAK,mBAAA,CAAoB,WAAA,CAAY,UAAU,CAAA;AACtE,IAAA,GAAA,CAAI,CAAC,SAAA,GAAY,QAAA,CAAS,OAAA,IAAW,MAAA,EAAQ;AAC5C,MAAA,MAAM,IAAI,mCAAA,CAAa,4BAAA,CAAY,SAAA,EAAW,oBAAoB,CAAA;AAAA,IACnE;AACA,IAAA,OAAO,QAAA;AAAA,EACR;AAAA,iBAEO,sBAAA,EAAwB,MAAA,CAC9B,GAAA,EACA,GAAA,EACA,IAAA,EAAA,GACI;AACJ,IAAA,IAAI;AACH,MAAA,MAAM,OAAA,EAAS,GAAA,CAAI,MAAA,CAAO,OAAA,GAAU,EAAA;AACpC,MAAA,MAAM,YAAA,EAAc,gDAAA;AAAA,QACnB,GAAA,CAAI;AAAA,MACL,CAAA;AACA,MAAA,GAAA,CAAI,CAAC,WAAA,EAAa;AACjB,QAAA,GAAA,CAAI,IAAA,CAAK,MAAM,IA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,EAAU,iBAAA;AAAA,MACV,MAAA;AAAA,MACA,UAAA,EAAY,EAAE,UAAA,EAAY,GAAG,CAAA;AAAA,MAC7B,KAAA,EAAO,MAAA,CAAO,MAAA,EAAA,GAAW;AACxB,QAAA,MAAM,IAAA,CAAK,qBAAA,CAAsB,MAAA,EAAQ,EAAE,CAAA;AAC3C,QAAA,MAAM,EAAE,mBAAmB,EAAA,EAAI,GAAA,CAAI,IAAA;AAGnC,QAAA,OAAO,IAAA,CAAK,wBAAA,CAAyB,qBAAA;AAAA,UACpC,EAAA;AAAA,UACA,kBAAA;AAAA,UACA;AAAA,QACD,CAAA;AAAA,MACD,CAAA;AAAA,MACA,iBAAA,EAAmB,MAAA,CAAO,eAAA,EAAiB,IAAA,EAAA,GAAS;AACnD,QAAA,MAAM,UAAA,EACL,MAAM,IAAA,CAAK,YAAA,CAAa,4BAAA,CAA6B,IAAI,CAAA;AAC1D,QAAA,MAAM,IAAA,CAAK,YAAA,CAAa,cAAA;AAAA,UACvB,MAAA;AAAA,UACA,eAAA;AAAA,UAAA,mBAAA;AAAA,UAEA,SAAA,CAAU,KAAA;AAAA,UACV;AAAA,YACC,UAAA,EAAY,IAAA;AAAA,YACZ;AAAA,UACD;AAAA,QACD,CAAA;AAAA,MACD;AAAA,IACD,CAAC,CAAA;AAAA,EACF,EAAA;AACD,UAAA;ADzDA;AACA;AACE;AACF,8DAAC","file":"/Users/shyun/comcom/ain-enterprise/ain-adk/dist/cjs/chunk-IIKB3JRC.cjs","sourcesContent":[null,"import type { NextFunction, Request, Response } from \"express\";\nimport { StatusCodes } from \"http-status-codes\";\nimport type { QueryService } from \"@/services/query.service.js\";\nimport type { UserWorkflowService } from \"@/services/user-workflow.service.js\";\nimport type { UserWorkflowCoordinatorService } from \"@/services/user-workflow-coordinator.service.js\";\nimport type { WorkflowExecutionService } from \"@/services/workflow-execution.service.js\";\nimport { AinHttpError } from \"@/types/agent.js\";\nimport type { PaginatedResult } from \"@/types/list.js\";\nimport { MessageRole, type UserWorkflow } from \"@/types/memory.js\";\nimport { parseListOptions } from \"@/utils/parse-list-options.js\";\nimport { streamEventsToSSE } from \"@/utils/sse-stream.js\";\n\nexport class UserWorkflowApiController {\n\tprivate userWorkflowService: UserWorkflowService;\n\tprivate userWorkflowCoordinatorService: UserWorkflowCoordinatorService;\n\tprivate workflowExecutionService: WorkflowExecutionService;\n\tprivate queryService: QueryService;\n\n\tconstructor(\n\t\tuserWorkflowService: UserWorkflowService,\n\t\tuserWorkflowCoordinatorService: UserWorkflowCoordinatorService,\n\t\tworkflowExecutionService: WorkflowExecutionService,\n\t\tqueryService: QueryService,\n\t) {\n\t\tthis.userWorkflowService = userWorkflowService;\n\t\tthis.userWorkflowCoordinatorService = userWorkflowCoordinatorService;\n\t\tthis.workflowExecutionService = workflowExecutionService;\n\t\tthis.queryService = queryService;\n\t}\n\n\tprivate async getAuthorizedWorkflow(\n\t\tuserId: string,\n\t\tworkflowId: string,\n\t): Promise<UserWorkflow> {\n\t\tconst workflow = await this.userWorkflowService.getWorkflow(workflowId);\n\t\tif (!workflow || workflow.userId !== userId) {\n\t\t\tthrow new AinHttpError(StatusCodes.NOT_FOUND, \"Workflow not found\");\n\t\t}\n\t\treturn workflow;\n\t}\n\n\tpublic handleGetAllWorkflows = async (\n\t\treq: Request,\n\t\tres: Response,\n\t\tnext: NextFunction,\n\t) => {\n\t\ttry {\n\t\t\tconst userId = res.locals.userId || \"\";\n\t\t\tconst listOptions = parseListOptions(\n\t\t\t\treq.query as Record<string, unknown>,\n\t\t\t);\n\t\t\tif (!listOptions) {\n\t\t\t\tres.json(await this.userWorkflowService.listWorkflows(userId));\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst [fetched, count] = await Promise.all([\n\t\t\t\tthis.userWorkflowService.listWorkflows(userId, listOptions),\n\t\t\t\tthis.userWorkflowService.countWorkflows(userId),\n\t\t\t]);\n\t\t\tlet items = fetched;\n\t\t\tlet total = count;\n\t\t\tif (total === undefined) {\n\t\t\t\t// Legacy provider ignored the options and returned everything —\n\t\t\t\t// emulate the same sort/slice contract here.\n\t\t\t\tconst updatedAtMs = (w: UserWorkflow): number => {\n\t\t\t\t\tif (!w.updatedAt) return 0;\n\t\t\t\t\tconst t = new Date(w.updatedAt).getTime();\n\t\t\t\t\treturn Number.isNaN(t) ? 0 : t;\n\t\t\t\t};\n\t\t\t\tconst sorted = [...fetched].sort(\n\t\t\t\t\t(a, b) =>\n\t\t\t\t\t\tupdatedAtMs(b) - updatedAtMs(a) ||\n\t\t\t\t\t\tb.workflowId.localeCompare(a.workflowId),\n\t\t\t\t);\n\t\t\t\ttotal = sorted.length;\n\t\t\t\titems = sorted.slice(\n\t\t\t\t\tlistOptions.offset,\n\t\t\t\t\tlistOptions.offset + listOptions.limit,\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst body: PaginatedResult<UserWorkflow> = {\n\t\t\t\titems,\n\t\t\t\ttotal,\n\t\t\t\tlimit: listOptions.limit,\n\t\t\t\toffset: listOptions.offset,\n\t\t\t};\n\t\t\tres.json(body);\n\t\t} catch (error) {\n\t\t\tnext(error);\n\t\t}\n\t};\n\n\tpublic handleGetWorkflow = async (\n\t\treq: Request,\n\t\tres: Response,\n\t\tnext: NextFunction,\n\t) => {\n\t\ttry {\n\t\t\tconst userId = res.locals.userId || \"\";\n\t\t\tconst { id } = req.params as { id: string };\n\t\t\tconst workflow = await this.getAuthorizedWorkflow(userId, id);\n\t\t\tres.json(workflow);\n\t\t} catch (error) {\n\t\t\tnext(error);\n\t\t}\n\t};\n\n\tpublic handleCreateWorkflow = async (\n\t\treq: Request,\n\t\tres: Response,\n\t\tnext: NextFunction,\n\t) => {\n\t\ttry {\n\t\t\tconst userId = res.locals.userId || \"\";\n\t\t\tconst workflowData = req.body as UserWorkflow;\n\t\t\tif (!workflowData.definition) {\n\t\t\t\tthrow new AinHttpError(\n\t\t\t\t\tStatusCodes.BAD_REQUEST,\n\t\t\t\t\t\"definition is required\",\n\t\t\t\t);\n\t\t\t}\n\t\t\tconst created = await this.userWorkflowCoordinatorService.createWorkflow({\n\t\t\t\t...workflowData,\n\t\t\t\tuserId,\n\t\t\t});\n\n\t\t\tres.status(StatusCodes.CREATED).json(created);\n\t\t} catch (error) {\n\t\t\tnext(error);\n\t\t}\n\t};\n\n\tpublic handleUpdateWorkflow = async (\n\t\treq: Request,\n\t\tres: Response,\n\t\tnext: NextFunction,\n\t) => {\n\t\ttry {\n\t\t\tconst userId = res.locals.userId || \"\";\n\t\t\tconst { id } = req.params as { id: string };\n\t\t\tawait this.getAuthorizedWorkflow(userId, id);\n\t\t\tconst updates = req.body as Partial<UserWorkflow>;\n\t\t\tconst updated = await this.userWorkflowCoordinatorService.updateWorkflow(\n\t\t\t\tid,\n\t\t\t\t{\n\t\t\t\t\t...updates,\n\t\t\t\t\tuserId,\n\t\t\t\t},\n\t\t\t);\n\n\t\t\t// 갱신된 워크플로우(재스케줄 후 nextRunAt 포함)를 돌려줘야 클라이언트가\n\t\t\t// 재조회 없이 예약 상태를 갱신할 수 있다. (기존: 빈 200 응답)\n\t\t\tres.status(StatusCodes.OK).json(updated ?? null);\n\t\t} catch (error) {\n\t\t\tnext(error);\n\t\t}\n\t};\n\n\tpublic handleDeleteWorkflow = async (\n\t\treq: Request,\n\t\tres: Response,\n\t\tnext: NextFunction,\n\t) => {\n\t\ttry {\n\t\t\tconst userId = res.locals.userId || \"\";\n\t\t\tconst { id } = req.params as { id: string };\n\t\t\tawait this.getAuthorizedWorkflow(userId, id);\n\n\t\t\tawait this.userWorkflowCoordinatorService.deleteWorkflow(id, userId);\n\t\t\tres.status(StatusCodes.OK).send();\n\t\t} catch (error) {\n\t\t\tnext(error);\n\t\t}\n\t};\n\n\tpublic handleExecuteWorkflow = async (\n\t\treq: Request,\n\t\tres: Response,\n\t\tnext: NextFunction,\n\t) => {\n\t\ttry {\n\t\t\tconst userId = res.locals.userId || \"\";\n\t\t\tconst { id } = req.params as { id: string };\n\t\t\tawait this.getAuthorizedWorkflow(userId, id);\n\n\t\t\tconst { executionVariables } = req.body as {\n\t\t\t\texecutionVariables?: Record<string, string>;\n\t\t\t};\n\t\t\tconst result = await this.workflowExecutionService.executeWorkflow(\n\t\t\t\tid,\n\t\t\t\texecutionVariables,\n\t\t\t);\n\n\t\t\tres.status(StatusCodes.OK).json(result);\n\t\t} catch (error) {\n\t\t\tnext(error);\n\t\t}\n\t};\n\n\tpublic handleExecuteWorkflowStream = async (req: Request, res: Response) => {\n\t\tconst userId = res.locals.userId || \"\";\n\t\tconst { id } = req.params as { id: string };\n\n\t\tawait streamEventsToSSE(req, res, {\n\t\t\tlogLabel: \"Workflow stream\",\n\t\t\tuserId,\n\t\t\tlogContext: { workflowId: id },\n\t\t\tsetup: async (signal) => {\n\t\t\t\tawait this.getAuthorizedWorkflow(userId, id);\n\t\t\t\tconst { executionVariables } = req.body as {\n\t\t\t\t\texecutionVariables?: Record<string, string>;\n\t\t\t\t};\n\t\t\t\treturn this.workflowExecutionService.executeWorkflowStream(\n\t\t\t\t\tid,\n\t\t\t\t\texecutionVariables,\n\t\t\t\t\tsignal,\n\t\t\t\t);\n\t\t\t},\n\t\t\tonThinkingProcess: async (currentThreadId, data) => {\n\t\t\t\tconst thinkData =\n\t\t\t\t\tawait this.queryService.filterThinkingDataForStorage(data);\n\t\t\t\tawait this.queryService.addTextMessage(\n\t\t\t\t\tuserId,\n\t\t\t\t\tcurrentThreadId,\n\t\t\t\t\tMessageRole.MODEL,\n\t\t\t\t\tthinkData.title,\n\t\t\t\t\t{\n\t\t\t\t\t\tisThinking: true,\n\t\t\t\t\t\tthinkData,\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t},\n\t\t});\n\t};\n}\n"]}