feat: decision-plane wiring — ER-pair decision.match tie-break (@siax/0pt-decision)
CI (SIAX Cloud) / integration (push) Has been skipped
masterplan-lock / check (push) Successful in 4s
CI (SIAX Cloud) / security (push) Successful in 15s
Security Scan (SIAX Cloud) / security (push) Successful in 15s
masterplan-lock / check (pull_request) Successful in 11s
CI (SIAX Cloud) / security (pull_request) Successful in 14s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 16s
CI (SIAX Cloud) / integration (pull_request) Successful in 25s
CI (SIAX Cloud) / quality (push) Failing after 32s
CI (SIAX Cloud) / quality (pull_request) Failing after 33s
CI (SIAX Cloud) / integration (push) Has been skipped
masterplan-lock / check (push) Successful in 4s
CI (SIAX Cloud) / security (push) Successful in 15s
Security Scan (SIAX Cloud) / security (push) Successful in 15s
masterplan-lock / check (pull_request) Successful in 11s
CI (SIAX Cloud) / security (pull_request) Successful in 14s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 16s
CI (SIAX Cloud) / integration (pull_request) Successful in 25s
CI (SIAX Cloud) / quality (push) Failing after 32s
CI (SIAX Cloud) / quality (pull_request) Failing after 33s
- packages/decision: erMatchDecision (0pt.er.pair_match mot siax-decision :4600) - comparePair async + borderline-band (±0.05 av review_threshold) → decision.match (D1 advisory) — deterministisk status GÄLLER om decision abstainar - OPT_DECISION_ER_ENABLED=1-gate (off tills kalibrering) - tests async-anpassade (await generateCandidates/rejects.toThrowError) - typecheck: 13 fel = pre-existing extraction-route (main-paritet), 0 nya fel - tester: 1108 passed | 184 skipped
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"name": "@siax/0pt-decision",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"main": "./src/index.ts",
|
||||
"types": "./src/index.ts",
|
||||
"exports": { ".": "./src/index.ts" },
|
||||
"scripts": { "test": "echo 'no tests yet'" }
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* `@siax/0pt-decision` — 0pt ER via siax-decision (:4600).
|
||||
*
|
||||
* Kaskad: hard rules + weighted-scoring (D0) → decision.match (D1-advisory)
|
||||
* för pending_review-ambiguitet → ABSTAINED/decision-nere → pending_review
|
||||
* gäller (fail-closed, aldrig fabricerat). 0pt behåller provenance-semantik.
|
||||
*/
|
||||
|
||||
const DECISION_URL = process.env.DECISION_API_URL ?? "http://127.0.0.1:4600";
|
||||
const DECISION_TOKEN = process.env.DECISION_TOKEN ?? "";
|
||||
const DECISION_TIMEOUT_MS = Number(process.env.DECISION_TIMEOUT_MS ?? 2000);
|
||||
|
||||
export interface DecisionMatch {
|
||||
decided: boolean;
|
||||
label?: "match" | "pending_review" | "non_match";
|
||||
confidence?: number;
|
||||
model?: string;
|
||||
latencyMs?: number;
|
||||
}
|
||||
|
||||
/** decision.match för ER-pair (semantic tie-break vid gränsfall). */
|
||||
export async function erMatchDecision(pair: {
|
||||
record_a: string;
|
||||
record_b: string;
|
||||
similarities: Array<{ field: string; similarity: number; weight: number }>;
|
||||
}): Promise<{ decided: boolean; label?: string; confidence?: number; model?: string; latencyMs?: number }> {
|
||||
try {
|
||||
const res = await fetch(`${DECISION_URL}/decision/match`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json", Authorization: `Bearer ${DECISION_TOKEN}` },
|
||||
body: JSON.stringify({
|
||||
decision: "0pt.er.pair_match",
|
||||
left: { record_id: pair.record_a },
|
||||
right: [{ record_id: pair.record_b }],
|
||||
instructions: "Do these two entity records refer to the same real-world entity?",
|
||||
minConfidence: 0.7,
|
||||
context: { field_similarities: pair.similarities },
|
||||
}),
|
||||
signal: AbortSignal.timeout(DECISION_TIMEOUT_MS),
|
||||
});
|
||||
if (!res.ok) return { decided: false };
|
||||
const out = (await res.json()) as { data?: { status?: string; choice?: string; confidence?: number; model?: string; latencyMs?: number } };
|
||||
const d = out.data;
|
||||
if (!d || d.status !== "DECIDED") return { decided: false, confidence: d?.confidence };
|
||||
const label = String(d.choice ?? "pending_review");
|
||||
return {
|
||||
decided: true,
|
||||
label: label === "0" ? "non_match" : label === "1" ? "match" : (label as "match" | "pending_review" | "non_match"),
|
||||
confidence: d.confidence,
|
||||
model: d.model,
|
||||
latencyMs: d.latencyMs,
|
||||
};
|
||||
} catch {
|
||||
return { decided: false };
|
||||
}
|
||||
}
|
||||
|
||||
/** Optional gate: enabled via OPT_DECISION_ER_ENABLED=1 (off tills kalibrering). */
|
||||
export function erDecisionEnabled(): boolean {
|
||||
const v = process.env.OPT_DECISION_ER_ENABLED;
|
||||
return v === "1" || v === "true";
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2022",
|
||||
"module": "NodeNext",
|
||||
"moduleResolution": "NodeNext",
|
||||
"strict": true,
|
||||
"noEmit": true,
|
||||
"skipLibCheck": true,
|
||||
"esModuleInterop": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
Reference in New Issue
Block a user