forked from Yara724/api
Merge pull request 'fix: keep AI provider and billing metadata out of case results' (#376) from s.yahyaee/yara724-api:main into main
Reviewed-on: Yara724/api#376
This commit is contained in:
@@ -128,7 +128,9 @@ Provider monetary fields in tomans are converted to rials **once** by the respon
|
||||
normalizer: overall/genuine/aftermarket totals, component min/median/max, repair
|
||||
estimates and individual listing prices. Missing/invalid/unsafe numbers remain null,
|
||||
not zero. Unsupported currencies do not acquire a guessed conversion. Provider
|
||||
processing cost remains in USD and duration remains milliseconds. The UI explicitly
|
||||
processing cost and duration remain server-side diagnostics. They are excluded from
|
||||
expert-facing API results, together with request IDs, pipeline versions, model names
|
||||
and hashes, including when reading previously stored jobs. The UI explicitly
|
||||
labels monetary values as rials and identifies an LLM repair guess separately.
|
||||
|
||||
Each job uses one photo, so the provider's `pricing` summary is **that photo's**
|
||||
@@ -140,7 +142,8 @@ The expert selects the matching catalogue part and enters the final valuation.
|
||||
|
||||
Sources show used/unused status; only absolute HTTP(S) links without credentials
|
||||
are clickable. Price ranges, sample count, spread warning, original/aftermarket
|
||||
alternatives, notes, cache status, model, date, cost and duration remain available.
|
||||
alternatives, notes and the result date remain available. Model identity, billing,
|
||||
processing timings and cache diagnostics are not displayed.
|
||||
Legacy detection-only results still render normally. Opening the AI tab does not
|
||||
start paid pricing. No real claim images were sent during implementation tests;
|
||||
transport and UI tests use local fixtures. Validate actual market quality with the
|
||||
|
||||
@@ -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