fix: complete dynamic engine cleanup
This commit is contained in:
@@ -83,15 +83,7 @@ const eventDomainSchema = z.enum([
|
||||
"career",
|
||||
"health_pressure",
|
||||
]);
|
||||
const candidateEvidenceApiSchema = z.object({
|
||||
event_id: z.string().uuid(),
|
||||
domain: eventDomainSchema,
|
||||
candidate_time: z.string(),
|
||||
rule_ids: z.array(z.string()),
|
||||
points: z.number(),
|
||||
});
|
||||
|
||||
const candidateResultApiFields = {
|
||||
const candidateResultApiSchema = z.object({
|
||||
result_id: z.string().uuid(),
|
||||
confidence: z.enum(["low", "medium", "high"]),
|
||||
can_apply: z.boolean(),
|
||||
@@ -107,10 +99,15 @@ const candidateResultApiFields = {
|
||||
second_score: z.number(),
|
||||
margin_percent: z.number(),
|
||||
reasons: z.array(z.string()),
|
||||
evidence: z.array(candidateEvidenceApiSchema),
|
||||
evidence: z.array(z.object({
|
||||
event_id: z.string().uuid(),
|
||||
domain: eventDomainSchema,
|
||||
candidate_time: z.string(),
|
||||
rule_ids: z.array(z.string()),
|
||||
points: z.number(),
|
||||
})),
|
||||
algorithm_version: z.string(),
|
||||
} as const;
|
||||
const candidateResultApiSchema = z.object(candidateResultApiFields).passthrough();
|
||||
}).passthrough();
|
||||
|
||||
class UnexpectedProfileSourceError extends Error {
|
||||
readonly name = "UnexpectedProfileSourceError";
|
||||
|
||||
@@ -14,8 +14,6 @@ import type {
|
||||
JourneyEventScoreInput,
|
||||
} from "./birth-time-journey-service.ts";
|
||||
|
||||
export const journeyEngineTimeoutMs = 45_000;
|
||||
|
||||
export class BirthTimeJourneyEngineError extends Error {
|
||||
readonly name = "BirthTimeJourneyEngineError";
|
||||
readonly status: number;
|
||||
@@ -55,7 +53,10 @@ export function createJourneyEngineWire(options: {
|
||||
readonly apiBase: string;
|
||||
readonly dynamicToken: string | null;
|
||||
readonly fetchImpl: JourneyEngineFetch;
|
||||
readonly signalFactory?: (timeoutMs: number) => AbortSignal;
|
||||
}): JourneyEngineWire {
|
||||
const signalFactory = options.signalFactory
|
||||
?? ((timeoutMs: number) => AbortSignal.timeout(timeoutMs));
|
||||
return {
|
||||
async post(input) {
|
||||
const token = options.dynamicToken?.trim();
|
||||
@@ -69,7 +70,7 @@ export function createJourneyEngineWire(options: {
|
||||
...(input.authentication === "dynamic" ? { authorization: `Bearer ${token}` } : {}),
|
||||
},
|
||||
body: JSON.stringify(input.body),
|
||||
signal: AbortSignal.timeout(journeyEngineTimeoutMs),
|
||||
signal: signalFactory(45_000),
|
||||
});
|
||||
const payload = await response.json();
|
||||
if (!response.ok) throw new BirthTimeJourneyEngineError(response.status);
|
||||
|
||||
Reference in New Issue
Block a user