forked from Yara724/api
fix: keep AI provider and billing metadata out of case results
This commit is contained in:
@@ -235,3 +235,29 @@ export function normalizeAiResult(value: unknown): AiResult {
|
||||
caseReport: text(raw.case_report) ?? "",
|
||||
};
|
||||
}
|
||||
|
||||
/** Expert-facing view: keep provider diagnostics and billing metadata server-side. */
|
||||
export function publicAiResult(result: AiResult | null | undefined) {
|
||||
if (!result) return result;
|
||||
return {
|
||||
parts: result.parts,
|
||||
report: result.report,
|
||||
caseReport: result.caseReport,
|
||||
vehicle: result.vehicle,
|
||||
internalDamages: result.internalDamages,
|
||||
...(result.pricing
|
||||
? {
|
||||
pricing: {
|
||||
car: result.pricing.car,
|
||||
minSeverity: result.pricing.minSeverity,
|
||||
currency: result.pricing.currency,
|
||||
originalCurrency: result.pricing.originalCurrency,
|
||||
totals: result.pricing.totals,
|
||||
complete: result.pricing.complete,
|
||||
pricedParts: result.pricing.pricedParts,
|
||||
unpricedParts: result.pricing.unpricedParts,
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -187,7 +187,19 @@ describe("durable AI jobs", () => {
|
||||
{
|
||||
imageKey: aiImageKey(image.path),
|
||||
status: "completed",
|
||||
result,
|
||||
result: {
|
||||
...result,
|
||||
requestId: "PRIVATE_REQUEST",
|
||||
pipeline: { price_model: "PRIVATE_MODEL" },
|
||||
pricing: {
|
||||
car: "پژو",
|
||||
totals: { overall: 1200000 },
|
||||
costUsd: 0.04,
|
||||
model: "PRIVATE_MODEL",
|
||||
durationMs: 1000,
|
||||
},
|
||||
},
|
||||
errorRequestId: "PRIVATE_ERROR_REQUEST",
|
||||
path: "private",
|
||||
attempts: 1,
|
||||
},
|
||||
@@ -204,6 +216,16 @@ describe("durable AI jobs", () => {
|
||||
result,
|
||||
});
|
||||
expect(view.images[0]).not.toHaveProperty("path");
|
||||
expect(view.images[0]).not.toHaveProperty("errorRequestId");
|
||||
expect(view.images[0].result).not.toHaveProperty("requestId");
|
||||
expect(view.images[0].result).not.toHaveProperty("pipeline");
|
||||
expect(view.images[0].result.pricing).toMatchObject({
|
||||
car: "پژو",
|
||||
totals: { overall: 1200000 },
|
||||
});
|
||||
for (const key of ["costUsd", "model", "durationMs"])
|
||||
expect(view.images[0].result.pricing).not.toHaveProperty(key);
|
||||
expect(JSON.stringify(view)).not.toContain("PRIVATE_");
|
||||
});
|
||||
it("manual retry affects only failed jobs for current claim/photos", async () => {
|
||||
const { service, jobs } = setup();
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { publicAiResult } from "./ai-result";
|
||||
import { createHash, randomUUID } from "node:crypto";
|
||||
import { createReadStream } from "node:fs";
|
||||
import { realpath, stat } from "node:fs/promises";
|
||||
@@ -127,8 +128,7 @@ export class AiService implements OnModuleInit, OnModuleDestroy {
|
||||
completedAt: job?.completedAt,
|
||||
error: job?.error,
|
||||
errorCode: job?.errorCode,
|
||||
errorRequestId: job?.errorRequestId,
|
||||
result: job?.status === "completed" ? job.result : undefined,
|
||||
result: job?.status === "completed" ? publicAiResult(job.result) : undefined,
|
||||
};
|
||||
}),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user