diff --git a/package-lock.json b/package-lock.json index 8e83f3c..8b1f402 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8390,11 +8390,11 @@ } }, "node_modules/micromatch": { - "version": "4.0.5", - "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.5.tgz", - "integrity": "sha512-DMy+ERcEW2q8Z2Po+WNXuw3c5YaUSFjAO5GsJqfEl7UjvtIuFKO6ZrKvcItdy98dwFI2N1tg3zNIdKaQT+aNdA==", + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/micromatch/-/micromatch-4.0.8.tgz", + "integrity": "sha512-PXwfBhYu0hBCPw8Dn0E+WDYb7af3dSLVWKi3HGv84IdF4TyFoC0ysxFd0Goxw7nSv4T/PzEJQxsYsEiFCKo2BA==", "dependencies": { - "braces": "^3.0.2", + "braces": "^3.0.3", "picomatch": "^2.3.1" }, "engines": { diff --git a/packages/ingest/src/repositories/mongodb-repository.ts b/packages/ingest/src/repositories/mongodb-repository.ts index f7f758e..7e2972d 100644 --- a/packages/ingest/src/repositories/mongodb-repository.ts +++ b/packages/ingest/src/repositories/mongodb-repository.ts @@ -18,14 +18,18 @@ export class MongodbRepository { }); } - async insertTrace(langscoutData: TraceData): Promise { + async insertTrace(data: TraceData): Promise { const collection = this.db.collection(this.collectionName); - await collection.insertOne(langscoutData); + await collection.insertOne(data); } - async updateTrace(langscoutId: string, updateData: TraceData): Promise { + async updateTrace(id: string, updateData: TraceData): Promise { + if (!/^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(id)) { + throw new Error(`Invalid UUID v4 format (${id}) for updateTrace`); + } + const collection = this.db.collection(this.collectionName); - return collection.updateOne({ run_id: { $eq: langscoutId } }, { $set: { ...updateData } }); + return collection.updateOne({ run_id: { $eq: id } }, { $set: { ...updateData } }); } async insertFeedbackOnTraceByRunId(feedback: CreateFeedback) { diff --git a/packages/ingest/src/services/langchain-to-langscout-service.ts b/packages/ingest/src/services/langchain-to-langscout-service.ts index 5a1f051..95b8bb6 100644 --- a/packages/ingest/src/services/langchain-to-langscout-service.ts +++ b/packages/ingest/src/services/langchain-to-langscout-service.ts @@ -34,9 +34,12 @@ export class LangchainToLangscoutService { if (!langchainData.id) { throw new Error('id is required in data'); } + + + langchainData.run_id = langchainData.id; delete langchainData.id; - + this.convertToDates(langchainData); const updateResult = await this.repository.updateTrace(traceId, langchainData);