UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

1 lines 2.49 kB
{"version":3,"file":"store-pending-generation.mjs","names":[],"sources":["../../../../src/services/ai/storage/store-pending-generation.ts"],"sourcesContent":["import { AiGenerationsRepository } from \"../../../libs/repositories/index.js\";\nimport type { ServiceFn } from \"../../../utils/services/types.js\";\n\nconst storePendingGeneration: ServiceFn<\n\t[\n\t\t{\n\t\t\tuserId: number;\n\t\t\trequestId: string;\n\t\t\tfeature: {\n\t\t\t\tkey: string;\n\t\t\t\tversion: string;\n\t\t\t};\n\t\t\ttargetType: string;\n\t\t\ttarget: Record<string, unknown>;\n\t\t},\n\t],\n\tundefined\n> = async (context, props) => {\n\tconst AiGenerations = new AiGenerationsRepository(\n\t\tcontext.db.client,\n\t\tcontext.config.db,\n\t);\n\n\tconst existingRes = await AiGenerations.selectSingleByRequestId({\n\t\trequestId: props.requestId,\n\t\tselect: [\"id\"],\n\t\ttenantKey: context.request.tenantKey,\n\t});\n\tif (existingRes.error) return existingRes;\n\n\tif (existingRes.data) {\n\t\treturn {\n\t\t\terror: undefined,\n\t\t\tdata: undefined,\n\t\t};\n\t}\n\n\tconst createRes = await AiGenerations.createSingle({\n\t\tdata: {\n\t\t\trequest_id: props.requestId,\n\t\t\tprovider_request_id: null,\n\t\t\tfeature_key: props.feature.key,\n\t\t\tfeature_version: props.feature.version,\n\t\t\ttenant_key: context.request.tenantKey ?? null,\n\t\t\tuser_id: props.userId,\n\t\t\ttarget_type: props.targetType,\n\t\t\ttarget: props.target,\n\t\t\toutput: null,\n\t\t\tusage: null,\n\t\t\tmodel: null,\n\t\t\tcost_currency: null,\n\t\t\tcost_total_minor: null,\n\t\t\tduration_ms: null,\n\t\t\tstatus: \"pending\",\n\t\t\terror_message: null,\n\t\t},\n\t\treturning: [\"id\"],\n\t});\n\tif (createRes.error) return createRes;\n\n\treturn {\n\t\terror: undefined,\n\t\tdata: undefined,\n\t};\n};\n\nexport default storePendingGeneration;\n"],"mappings":"6DAGA,MAAM,EAcF,MAAO,EAAS,IAAU,CAC7B,IAAM,EAAgB,IAAI,EACzB,EAAQ,GAAG,OACX,EAAQ,OAAO,EAChB,EAEM,EAAc,MAAM,EAAc,wBAAwB,CAC/D,UAAW,EAAM,UACjB,OAAQ,CAAC,IAAI,EACb,UAAW,EAAQ,QAAQ,SAC5B,CAAC,EACD,GAAI,EAAY,MAAO,OAAO,EAE9B,GAAI,EAAY,KACf,MAAO,CACN,MAAO,IAAA,GACP,KAAM,IAAA,EACP,EAGD,IAAM,EAAY,MAAM,EAAc,aAAa,CAClD,KAAM,CACL,WAAY,EAAM,UAClB,oBAAqB,KACrB,YAAa,EAAM,QAAQ,IAC3B,gBAAiB,EAAM,QAAQ,QAC/B,WAAY,EAAQ,QAAQ,WAAa,KACzC,QAAS,EAAM,OACf,YAAa,EAAM,WACnB,OAAQ,EAAM,OACd,OAAQ,KACR,MAAO,KACP,MAAO,KACP,cAAe,KACf,iBAAkB,KAClB,YAAa,KACb,OAAQ,UACR,cAAe,IAChB,EACA,UAAW,CAAC,IAAI,CACjB,CAAC,EAGD,OAFI,EAAU,MAAc,EAErB,CACN,MAAO,IAAA,GACP,KAAM,IAAA,EACP,CACD"}