@tangle-network/agent-eval 0.220.2 → 0.221.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +30 -0
- package/dist/adapters/http.d.ts +2 -2
- package/dist/{agent-profile-D01Io2Xw.d.ts → agent-profile-Bc7ADJY4.d.ts} +2 -2
- package/dist/{agent-profile-D01Io2Xw.d.ts.map → agent-profile-Bc7ADJY4.d.ts.map} +1 -1
- package/dist/analyst/index.d.ts +77 -78
- package/dist/analyst/index.d.ts.map +1 -1
- package/dist/analyst/index.js +204 -25
- package/dist/analyst/index.js.map +1 -1
- package/dist/{analyze-runs-DqPJaJ4X.js → analyze-runs-CHmsykNJ.js} +4 -4
- package/dist/{analyze-runs-DqPJaJ4X.js.map → analyze-runs-CHmsykNJ.js.map} +1 -1
- package/dist/{analyze-runs-BWAHBDAw.d.ts → analyze-runs-D7In4c3z.d.ts} +2 -2
- package/dist/{analyze-runs-BWAHBDAw.d.ts.map → analyze-runs-D7In4c3z.d.ts.map} +1 -1
- package/dist/{benchmark-command-Dx0E4a6z.js → benchmark-command-8XQfpUK3.js} +13 -11
- package/dist/benchmark-command-8XQfpUK3.js.map +1 -0
- package/dist/benchmarks/index.d.ts +4 -4
- package/dist/benchmarks/index.js +3 -3
- package/dist/calibration-CTwxpJ-t.js +197 -0
- package/dist/calibration-CTwxpJ-t.js.map +1 -0
- package/dist/campaign/index.d.ts +6 -6
- package/dist/campaign/index.js +5 -5
- package/dist/{campaign-BVPC6ODQ.js → campaign-Bt6rbWIU.js} +9 -8
- package/dist/{campaign-BVPC6ODQ.js.map → campaign-Bt6rbWIU.js.map} +1 -1
- package/dist/cli.js +1 -1
- package/dist/{completion-verifier-Cigap8CG.js → completion-verifier-YwoeujPl.js} +2 -2
- package/dist/{completion-verifier-Cigap8CG.js.map → completion-verifier-YwoeujPl.js.map} +1 -1
- package/dist/contract/index.d.ts +10 -10
- package/dist/contract/index.js +7 -7
- package/dist/decision-point-Co3u3W8k.js +831 -0
- package/dist/decision-point-Co3u3W8k.js.map +1 -0
- package/dist/default-registry-BMHqNR6_.d.ts +257 -0
- package/dist/default-registry-BMHqNR6_.d.ts.map +1 -0
- package/dist/{default-registry-ovrIBGmH.js → default-registry-BbFCkqvB.js} +607 -14
- package/dist/default-registry-BbFCkqvB.js.map +1 -0
- package/dist/{define-agent-eval-C2nFhHPu.d.ts → define-agent-eval-Bsoi2GUV.d.ts} +7 -7
- package/dist/{define-agent-eval-C2nFhHPu.d.ts.map → define-agent-eval-Bsoi2GUV.d.ts.map} +1 -1
- package/dist/{define-agent-eval-UQY3VbJ2.js → define-agent-eval-CJhECJNL.js} +4 -4
- package/dist/{define-agent-eval-UQY3VbJ2.js.map → define-agent-eval-CJhECJNL.js.map} +1 -1
- package/dist/diagnosis/index.d.ts +2 -2
- package/dist/diagnosis/index.js +1 -1
- package/dist/{dspy-rlm-engine-Bn_Mt_LW.js → dspy-rlm-engine-BTy7u0jQ.js} +3 -3
- package/dist/{dspy-rlm-engine-Bn_Mt_LW.js.map → dspy-rlm-engine-BTy7u0jQ.js.map} +1 -1
- package/dist/{engine-BpGGw6cd.d.ts → engine-BF95CWzH.d.ts} +2 -2
- package/dist/{engine-BpGGw6cd.d.ts.map → engine-BF95CWzH.d.ts.map} +1 -1
- package/dist/{eval-campaign-BUMIxKTE.js → eval-campaign-DoX5vz3E.js} +2 -2
- package/dist/{eval-campaign-BUMIxKTE.js.map → eval-campaign-DoX5vz3E.js.map} +1 -1
- package/dist/{evaluation-CBdQt_kr.d.ts → evaluation-D1PGzkPR.d.ts} +3 -3
- package/dist/{evaluation-CBdQt_kr.d.ts.map → evaluation-D1PGzkPR.d.ts.map} +1 -1
- package/dist/evaluation-wdGyZ7jV.js +147 -0
- package/dist/evaluation-wdGyZ7jV.js.map +1 -0
- package/dist/evaluation.d.ts +1 -1
- package/dist/evaluation.js +1 -136
- package/dist/{exact-types-BYFmYq44.d.ts → exact-types-CVn1QxFO.d.ts} +2 -2
- package/dist/{exact-types-BYFmYq44.d.ts.map → exact-types-CVn1QxFO.d.ts.map} +1 -1
- package/dist/experiment/index.d.ts +3 -3
- package/dist/experiment/index.js +2 -2
- package/dist/{external-optimizer-process-wOLfzsCC.js → external-optimizer-process-E5yY2SYS.js} +2 -2
- package/dist/{external-optimizer-process-wOLfzsCC.js.map → external-optimizer-process-E5yY2SYS.js.map} +1 -1
- package/dist/{external-optimizer-subprocess-D670Oxf2.js → external-optimizer-subprocess-DA02c_L6.js} +12 -19
- package/dist/{external-optimizer-subprocess-D670Oxf2.js.map → external-optimizer-subprocess-DA02c_L6.js.map} +1 -1
- package/dist/{feedback-trajectory-DhB9WzYg.d.ts → feedback-trajectory-BZhVCWuz.d.ts} +3 -3
- package/dist/{feedback-trajectory-DhB9WzYg.d.ts.map → feedback-trajectory-BZhVCWuz.d.ts.map} +1 -1
- package/dist/finding-composition-8n0fFgVI.js +131 -0
- package/dist/finding-composition-8n0fFgVI.js.map +1 -0
- package/dist/{findings-store-CvNo712L.js → findings-store-DRiFdoid.js} +4 -4
- package/dist/{findings-store-CvNo712L.js.map → findings-store-DRiFdoid.js.map} +1 -1
- package/dist/{index-CVFStrQD.d.ts → index-BJZ7s-sv.d.ts} +7 -58
- package/dist/index-BJZ7s-sv.d.ts.map +1 -0
- package/dist/{index-Q6DvdcwI.d.ts → index-BvX3CFNS.d.ts} +6 -6
- package/dist/{index-Q6DvdcwI.d.ts.map → index-BvX3CFNS.d.ts.map} +1 -1
- package/dist/index-DWd1gUwR.d.ts +1086 -0
- package/dist/index-DWd1gUwR.d.ts.map +1 -0
- package/dist/{index-DAXfpVf7.d.ts → index-y7i8l6Y_.d.ts} +8 -8
- package/dist/{index-DAXfpVf7.d.ts.map → index-y7i8l6Y_.d.ts.map} +1 -1
- package/dist/index.d.ts +18 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -15
- package/dist/{kind-factory-BhxbtUsQ.js → kind-factory-Dl0PmNQL.js} +2 -2
- package/dist/{kind-factory-BhxbtUsQ.js.map → kind-factory-Dl0PmNQL.js.map} +1 -1
- package/dist/{llm-judge-Cc8vDJh_.js → llm-judge-3uAeRawE.js} +4 -4
- package/dist/{llm-judge-Cc8vDJh_.js.map → llm-judge-3uAeRawE.js.map} +1 -1
- package/dist/{matrix-Cf-AGxGh.d.ts → matrix-BXo3PSqM.d.ts} +2 -2
- package/dist/{matrix-Cf-AGxGh.d.ts.map → matrix-BXo3PSqM.d.ts.map} +1 -1
- package/dist/meta-eval/index.d.ts +3 -638
- package/dist/meta-eval/index.js +3 -193
- package/dist/meta-eval/index.js.map +1 -1
- package/dist/multishot/golden/index.d.ts +1 -1
- package/dist/multishot/index.d.ts +2 -2
- package/dist/openapi.json +1 -1
- package/dist/outcome-observations-FLmRpgYa.js +78 -0
- package/dist/outcome-observations-FLmRpgYa.js.map +1 -0
- package/dist/{paired-arms-Ct4LTKc1.js → paired-arms-B2ttLc0_.js} +108 -31
- package/dist/paired-arms-B2ttLc0_.js.map +1 -0
- package/dist/{power-and-mde-N5nU4_Ly.js → power-and-mde-CQX-0weG.js} +2 -2
- package/dist/{power-and-mde-N5nU4_Ly.js.map → power-and-mde-CQX-0weG.js.map} +1 -1
- package/dist/{prime-protocol-CckHBxGu.d.ts → prime-protocol-BEaqBoQE.d.ts} +2 -2
- package/dist/{prime-protocol-CckHBxGu.d.ts.map → prime-protocol-BEaqBoQE.d.ts.map} +1 -1
- package/dist/{proposal-findings-E1aSC_cU.js → proposal-findings-D0_zkQ2l.js} +2 -2
- package/dist/{proposal-findings-E1aSC_cU.js.map → proposal-findings-D0_zkQ2l.js.map} +1 -1
- package/dist/{registry-B_yG-1jh.d.ts → registry-DDKaUrmM.d.ts} +3 -3
- package/dist/{registry-B_yG-1jh.d.ts.map → registry-DDKaUrmM.d.ts.map} +1 -1
- package/dist/reporting.d.ts +1 -1
- package/dist/reporting.js +3 -3
- package/dist/rl.d.ts +4 -5
- package/dist/rl.d.ts.map +1 -1
- package/dist/rl.js +5 -4
- package/dist/rl.js.map +1 -1
- package/dist/{rubric-predictive-validity-noY7uE03.d.ts → rubric-predictive-validity-Cd5SCtAf.d.ts} +58 -3
- package/dist/rubric-predictive-validity-Cd5SCtAf.d.ts.map +1 -0
- package/dist/{rubric-predictive-validity-D3_oI72N.js → rubric-predictive-validity-CeKW2GQN.js} +3 -77
- package/dist/rubric-predictive-validity-CeKW2GQN.js.map +1 -0
- package/dist/search/index.d.ts +2 -2
- package/dist/{search-kernel-Dloxd6gs.d.ts → search-kernel-C6__V0IS.d.ts} +2 -2
- package/dist/{search-kernel-Dloxd6gs.d.ts.map → search-kernel-C6__V0IS.d.ts.map} +1 -1
- package/dist/{skillopt-optimization-method-DLKqdhcR.js → skillopt-optimization-method-D21dH_Bh.js} +4 -4
- package/dist/{skillopt-optimization-method-DLKqdhcR.js.map → skillopt-optimization-method-D21dH_Bh.js.map} +1 -1
- package/dist/{statistical-heldout-3z3I-kJN.d.ts → statistical-heldout-pD1Yah-0.d.ts} +58 -8
- package/dist/statistical-heldout-pD1Yah-0.d.ts.map +1 -0
- package/dist/{store-otlp-dyWE3wAG.js → store-otlp-BVZfR168.js} +2 -2
- package/dist/{store-otlp-dyWE3wAG.js.map → store-otlp-BVZfR168.js.map} +1 -1
- package/dist/{store-tool-spans-DIUgZbzu.js → store-tool-spans-CjYiF4fF.js} +3 -3
- package/dist/{store-tool-spans-DIUgZbzu.js.map → store-tool-spans-CjYiF4fF.js.map} +1 -1
- package/dist/{store-tool-spans-DPwXHQkH.d.ts → store-tool-spans-DfnwWMFR.d.ts} +4 -4
- package/dist/{store-tool-spans-DPwXHQkH.d.ts.map → store-tool-spans-DfnwWMFR.d.ts.map} +1 -1
- package/dist/{summary-report-BsXJoYX5.js → summary-report-DHDWxe6p.js} +3 -3
- package/dist/{summary-report-BsXJoYX5.js.map → summary-report-DHDWxe6p.js.map} +1 -1
- package/dist/systemone-D3MrW63C.d.ts +400 -0
- package/dist/systemone-D3MrW63C.d.ts.map +1 -0
- package/dist/{systemone-protocol-DKoi1NdK.d.ts → systemone-protocol-Bl2EI2KQ.d.ts} +4 -2
- package/dist/{systemone-protocol-DKoi1NdK.d.ts.map → systemone-protocol-Bl2EI2KQ.d.ts.map} +1 -1
- package/dist/systemone-protocol.d.ts +2 -2
- package/dist/systemone-protocol.js +7 -7
- package/dist/systemone-protocol.js.map +1 -1
- package/dist/{systemone-review-CUBMuTLi.d.ts → systemone-review-C8DRiT_-.d.ts} +3 -3
- package/dist/{systemone-review-CUBMuTLi.d.ts.map → systemone-review-C8DRiT_-.d.ts.map} +1 -1
- package/dist/{systemone-review-DzdOJ8I6.js → systemone-review-DFGtIUcf.js} +2 -2
- package/dist/{systemone-review-DzdOJ8I6.js.map → systemone-review-DFGtIUcf.js.map} +1 -1
- package/dist/systemone.d.ts +5 -5
- package/dist/systemone.js +5 -343
- package/dist/{tool-groups-LISbBWCg.d.ts → tool-groups-DK1bu5TD.d.ts} +3 -3
- package/dist/tool-groups-DK1bu5TD.d.ts.map +1 -0
- package/dist/{trace-questions-C42fYEE4.d.ts → trace-questions-D_OKYZ6u.d.ts} +3 -3
- package/dist/{trace-questions-C42fYEE4.d.ts.map → trace-questions-D_OKYZ6u.d.ts.map} +1 -1
- package/dist/trace-repair/index.d.ts +1 -1
- package/dist/traces.d.ts +3 -3
- package/dist/traces.js +3 -3
- package/dist/{types-DqFMNTgK.js → types-CnWmj8NW.js} +19 -6
- package/dist/types-CnWmj8NW.js.map +1 -0
- package/dist/{types-CHfn1zg5.d.ts → types-DDKfH-N6.d.ts} +2 -2
- package/dist/{types-CHfn1zg5.d.ts.map → types-DDKfH-N6.d.ts.map} +1 -1
- package/dist/{types-8yQzNm8u.d.ts → types-DGImvHIr.d.ts} +150 -4
- package/dist/types-DGImvHIr.d.ts.map +1 -0
- package/dist/{types-D8GXK9Z5.d.ts → types-IERw_HxR.d.ts} +2 -2
- package/dist/{types-D8GXK9Z5.d.ts.map → types-IERw_HxR.d.ts.map} +1 -1
- package/dist/wire/index.d.ts +1 -1
- package/docs/behavioral-trace-questions.md +99 -0
- package/docs/experiment.md +27 -0
- package/docs/finding-layers.md +54 -1
- package/docs/systemone.md +107 -0
- package/package.json +1 -1
- package/dist/benchmark-command-Dx0E4a6z.js.map +0 -1
- package/dist/default-registry-Cwg_QN3d.d.ts +0 -70
- package/dist/default-registry-Cwg_QN3d.d.ts.map +0 -1
- package/dist/default-registry-ovrIBGmH.js.map +0 -1
- package/dist/evaluation.js.map +0 -1
- package/dist/index-CVFStrQD.d.ts.map +0 -1
- package/dist/judge-gate-Dc_mXQsL.d.ts +0 -453
- package/dist/judge-gate-Dc_mXQsL.d.ts.map +0 -1
- package/dist/meta-eval/index.d.ts.map +0 -1
- package/dist/outcome-store-CNt4iZ67.d.ts +0 -58
- package/dist/outcome-store-CNt4iZ67.d.ts.map +0 -1
- package/dist/paired-arms-Ct4LTKc1.js.map +0 -1
- package/dist/rubric-predictive-validity-D3_oI72N.js.map +0 -1
- package/dist/rubric-predictive-validity-noY7uE03.d.ts.map +0 -1
- package/dist/statistical-heldout-3z3I-kJN.d.ts.map +0 -1
- package/dist/systemone-DVA7t76V.d.ts +0 -135
- package/dist/systemone-DVA7t76V.d.ts.map +0 -1
- package/dist/systemone.js.map +0 -1
- package/dist/tool-groups-LISbBWCg.d.ts.map +0 -1
- package/dist/types-8yQzNm8u.d.ts.map +0 -1
- package/dist/types-DqFMNTgK.js.map +0 -1
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
import { f as CostReceiptInput, m as CustomTokenPricing } from "./cost-ledger-C1W3ICmP.js";
|
|
2
|
+
import { E as FindingLayer, i as AnalystFinding, j as FindingScope, m as EvidenceRef, n as AnalystContext, t as Analyst, w as FindingCalibration } from "./types-DGImvHIr.js";
|
|
3
|
+
import { It as calibrationFromPairs } from "./index-DWd1gUwR.js";
|
|
4
|
+
import { r as LedgerHash } from "./canonical-CFpojCN5.js";
|
|
5
|
+
import { R as Scenario, S as JudgeConfig, w as JudgeScore } from "./types-DDKfH-N6.js";
|
|
6
|
+
import { a as EvaluationResult, o as EvaluatorOptions, r as EvaluationContext } from "./evaluation-D1PGzkPR.js";
|
|
7
|
+
import { a as SystemOneJson, d as SystemOneRequest, g as SystemOneState, o as SystemOneQuestion, p as SystemOneResult, s as SystemOneQuestions } from "./systemone-protocol-Bl2EI2KQ.js";
|
|
8
|
+
import "./systemone-review-C8DRiT_-.js";
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
//#region src/analyst/findings-store.d.ts
|
|
11
|
+
/**
|
|
12
|
+
* One persisted row. We attach `run_id` on disk so a single file can
|
|
13
|
+
* hold multiple runs and the diff helper can query without re-walking
|
|
14
|
+
* separate files.
|
|
15
|
+
*/
|
|
16
|
+
interface PersistedFinding extends AnalystFinding {
|
|
17
|
+
run_id: string;
|
|
18
|
+
}
|
|
19
|
+
declare class FindingsStore {
|
|
20
|
+
readonly path: string;
|
|
21
|
+
private readonly appender;
|
|
22
|
+
constructor(path: string);
|
|
23
|
+
append(runId: string, findings: AnalystFinding[]): Promise<void>;
|
|
24
|
+
/** Load every persisted finding. Discards malformed trailing lines silently. */
|
|
25
|
+
loadAll(): PersistedFinding[];
|
|
26
|
+
/** Filter to a single run. */
|
|
27
|
+
loadRun(runId: string): PersistedFinding[];
|
|
28
|
+
}
|
|
29
|
+
interface FindingsDiff {
|
|
30
|
+
/** New finding ids in `current` that weren't in `previous`. */
|
|
31
|
+
appeared: PersistedFinding[];
|
|
32
|
+
/** Finding ids in `previous` that aren't in `current`. */
|
|
33
|
+
disappeared: PersistedFinding[];
|
|
34
|
+
/** Same finding id present in both runs and unchanged per the materiality test. */
|
|
35
|
+
persisted: PersistedFinding[];
|
|
36
|
+
/**
|
|
37
|
+
* Same finding id in both runs but at least one non-identity field
|
|
38
|
+
* shifted per `DiffPolicy.isMaterial`. Reported as [previous, current].
|
|
39
|
+
*/
|
|
40
|
+
changed: Array<{
|
|
41
|
+
previous: PersistedFinding;
|
|
42
|
+
current: PersistedFinding;
|
|
43
|
+
}>;
|
|
44
|
+
}
|
|
45
|
+
interface DiffPolicy {
|
|
46
|
+
/**
|
|
47
|
+
* Predicate that decides whether two findings (same finding_id) count
|
|
48
|
+
* as a material change. Defaults to {@link defaultIsMaterial}: severity
|
|
49
|
+
* shift, confidence Δ > 0.05, or evidence count change. Compliance /
|
|
50
|
+
* perf consumers MAY supply a stricter predicate (e.g. rationale text
|
|
51
|
+
* diff, metric Δ thresholds).
|
|
52
|
+
*/
|
|
53
|
+
isMaterial?: (previous: AnalystFinding, current: AnalystFinding) => boolean;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Diff two findings sets by stable finding_id. Callers typically load
|
|
57
|
+
* the two run-id slices from the same store and pass them in.
|
|
58
|
+
*/
|
|
59
|
+
declare function diffFindings(previous: PersistedFinding[], current: PersistedFinding[], policy?: DiffPolicy): FindingsDiff;
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/analyst/findings-ledger.d.ts
|
|
62
|
+
/** One finding as the ledger holds it. */
|
|
63
|
+
interface LedgerFinding extends PersistedFinding {
|
|
64
|
+
/** Position in the journal; later entries were appended later. */
|
|
65
|
+
sequence: number;
|
|
66
|
+
entryHash: LedgerHash;
|
|
67
|
+
}
|
|
68
|
+
interface FindingsLedgerRead {
|
|
69
|
+
findings: LedgerFinding[];
|
|
70
|
+
/** RFC 9162 Merkle root over every entry hash, in journal order. */
|
|
71
|
+
merkleRoot: LedgerHash;
|
|
72
|
+
}
|
|
73
|
+
type FindingsLedgerOutcome<T> = {
|
|
74
|
+
succeeded: true;
|
|
75
|
+
value: T;
|
|
76
|
+
} | {
|
|
77
|
+
succeeded: false;
|
|
78
|
+
error: {
|
|
79
|
+
kind: 'invalid' | 'conflict' | 'unavailable';
|
|
80
|
+
message: string;
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
interface FindingsLedger {
|
|
84
|
+
readonly path: string;
|
|
85
|
+
append(runId: string, findings: readonly AnalystFinding[]): Promise<FindingsLedgerOutcome<{
|
|
86
|
+
appended: number;
|
|
87
|
+
replayed: number;
|
|
88
|
+
}>>;
|
|
89
|
+
read(): Promise<FindingsLedgerOutcome<FindingsLedgerRead>>;
|
|
90
|
+
}
|
|
91
|
+
/** Open (or create on first append) the findings journal at `path`; every reopen requires its pin. */
|
|
92
|
+
declare function openFindingsLedger(options: {
|
|
93
|
+
path: string;
|
|
94
|
+
}): FindingsLedger;
|
|
95
|
+
interface FindingsQuery {
|
|
96
|
+
layer?: FindingLayer | readonly FindingLayer[];
|
|
97
|
+
subject?: string;
|
|
98
|
+
analystId?: string;
|
|
99
|
+
runId?: string;
|
|
100
|
+
claimId?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Findings whose `scope.domain_path` starts with this path. A finding with no
|
|
103
|
+
* domain path never matches, so a path query cannot return unscoped findings.
|
|
104
|
+
*/
|
|
105
|
+
domainPath?: readonly string[];
|
|
106
|
+
}
|
|
107
|
+
/** Filter ledger rows. Every set criterion must hold; 1.0.0 rows have no layer and never match one. */
|
|
108
|
+
declare function queryFindings<T extends AnalystFinding & {
|
|
109
|
+
run_id?: string;
|
|
110
|
+
}>(rows: readonly T[], query: FindingsQuery): T[];
|
|
111
|
+
interface FindingsTimeStep {
|
|
112
|
+
previous_run_id: string;
|
|
113
|
+
run_id: string;
|
|
114
|
+
diff: FindingsDiff;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Diff each run against the run before it, in the order runs first entered
|
|
118
|
+
* the ledger. Uses `diffFindings`, so `appeared`, `disappeared`, `persisted`
|
|
119
|
+
* and `changed` mean exactly what they mean for two runs.
|
|
120
|
+
*/
|
|
121
|
+
declare function diffFindingsOverTime(rows: readonly LedgerFinding[], policy?: DiffPolicy): FindingsTimeStep[];
|
|
122
|
+
//#endregion
|
|
123
|
+
//#region src/decision-point-records.d.ts
|
|
124
|
+
declare const decisionRouteSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
125
|
+
action: z.ZodLiteral<"act">;
|
|
126
|
+
route: z.ZodString;
|
|
127
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
128
|
+
action: z.ZodLiteral<"escalate">;
|
|
129
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
130
|
+
action: z.ZodLiteral<"record">;
|
|
131
|
+
}, z.core.$strict>], "action">;
|
|
132
|
+
/** A routing recommendation; the consumer retains execution authority. */
|
|
133
|
+
type DecisionRoute = z.infer<typeof decisionRouteSchema>;
|
|
134
|
+
declare const decisionRecordSchema: z.ZodObject<{
|
|
135
|
+
kind: z.ZodLiteral<"decision">;
|
|
136
|
+
pointId: z.ZodString;
|
|
137
|
+
definition: z.ZodUnknown;
|
|
138
|
+
consumer: z.ZodString;
|
|
139
|
+
definitionDigest: z.ZodString;
|
|
140
|
+
invocationId: z.ZodString;
|
|
141
|
+
inputDigest: z.ZodString;
|
|
142
|
+
stateDigest: z.ZodString;
|
|
143
|
+
requestedModel: z.ZodString;
|
|
144
|
+
servedModel: z.ZodNullable<z.ZodString>;
|
|
145
|
+
action: z.ZodEnum<{
|
|
146
|
+
act: "act";
|
|
147
|
+
escalate: "escalate";
|
|
148
|
+
record: "record";
|
|
149
|
+
}>;
|
|
150
|
+
answers: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
151
|
+
probabilities: z.ZodRecord<z.ZodString, z.ZodNumber>;
|
|
152
|
+
choice: z.ZodString;
|
|
153
|
+
recommendation: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
154
|
+
action: z.ZodLiteral<"act">;
|
|
155
|
+
route: z.ZodString;
|
|
156
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
157
|
+
action: z.ZodLiteral<"escalate">;
|
|
158
|
+
}, z.core.$strict>, z.ZodObject<{
|
|
159
|
+
action: z.ZodLiteral<"record">;
|
|
160
|
+
}, z.core.$strict>], "action">;
|
|
161
|
+
reason: z.ZodEnum<{
|
|
162
|
+
"model-mismatch": "model-mismatch";
|
|
163
|
+
"record-only": "record-only";
|
|
164
|
+
threshold: "threshold";
|
|
165
|
+
uncalibrated: "uncalibrated";
|
|
166
|
+
uncertain: "uncertain";
|
|
167
|
+
}>;
|
|
168
|
+
}, z.core.$strict>>;
|
|
169
|
+
error: z.ZodNullable<z.ZodEnum<{
|
|
170
|
+
cancelled: "cancelled";
|
|
171
|
+
"evaluation-failed": "evaluation-failed";
|
|
172
|
+
}>>;
|
|
173
|
+
receipt: z.ZodOptional<z.ZodUnknown>;
|
|
174
|
+
}, z.core.$strict>;
|
|
175
|
+
type DecisionRecord = z.infer<typeof decisionRecordSchema>;
|
|
176
|
+
//#endregion
|
|
177
|
+
//#region src/decision-point.d.ts
|
|
178
|
+
type DecisionQuestions = Record<string, Extract<SystemOneQuestion, {
|
|
179
|
+
type: 'choice';
|
|
180
|
+
}>>;
|
|
181
|
+
interface DecisionQuestionPolicy {
|
|
182
|
+
/** Capture an ancillary choice without routing authority or a calibration certificate. */
|
|
183
|
+
recordOnly?: boolean;
|
|
184
|
+
minimumProbability: number;
|
|
185
|
+
minimumMargin: number;
|
|
186
|
+
options: Record<string, DecisionRoute>;
|
|
187
|
+
/** Identity of an independently labeled calibration, bound to the exact question and model. */
|
|
188
|
+
calibration?: FindingCalibration & {
|
|
189
|
+
questionDigest: string;
|
|
190
|
+
servedModel: string;
|
|
191
|
+
evidenceRefs: EvidenceRef[];
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
interface DecisionPointOptions<Q extends DecisionQuestions> {
|
|
195
|
+
id: string;
|
|
196
|
+
version: string;
|
|
197
|
+
layers: FindingLayer[];
|
|
198
|
+
model: string;
|
|
199
|
+
questions: Q;
|
|
200
|
+
policy: { [K in keyof Q]: DecisionQuestionPolicy; };
|
|
201
|
+
ledger: FindingsLedger;
|
|
202
|
+
evaluator: SystemOneEvaluatorOptions;
|
|
203
|
+
}
|
|
204
|
+
interface DecisionInvocation {
|
|
205
|
+
runId: string;
|
|
206
|
+
invocationId: string;
|
|
207
|
+
layer: FindingLayer;
|
|
208
|
+
consumer: string;
|
|
209
|
+
state: SystemOneState;
|
|
210
|
+
scope: FindingScope;
|
|
211
|
+
at: string;
|
|
212
|
+
evidenceRefs: EvidenceRef[];
|
|
213
|
+
}
|
|
214
|
+
interface DecisionPointResult {
|
|
215
|
+
record: DecisionRecord | null;
|
|
216
|
+
finding: AnalystFinding;
|
|
217
|
+
replayed: boolean;
|
|
218
|
+
/** A reserved call without a durable result must escalate, including after a process crash. */
|
|
219
|
+
action: DecisionRoute['action'];
|
|
220
|
+
}
|
|
221
|
+
/** Model identity and authored option order are part of what a calibration measured. */
|
|
222
|
+
declare function decisionQuestionDigest(input: {
|
|
223
|
+
id: string;
|
|
224
|
+
version: string;
|
|
225
|
+
model: string;
|
|
226
|
+
servedModel: string;
|
|
227
|
+
name: string;
|
|
228
|
+
question: DecisionQuestions[string];
|
|
229
|
+
}): string;
|
|
230
|
+
/** Minimum independent nominal-label agreement required before routing can drive work. */
|
|
231
|
+
declare const DECISION_POINT_MIN_KAPPA = 0.77;
|
|
232
|
+
/** Cheap, reversible judgments only. This returns recommendations and never performs actions. */
|
|
233
|
+
declare function decisionPoint<const Q extends DecisionQuestions>(options: DecisionPointOptions<Q>): {
|
|
234
|
+
id: string;
|
|
235
|
+
definitionDigest: `sha256:${string}`;
|
|
236
|
+
decide(invocation: DecisionInvocation, context?: EvaluationContext): Promise<FindingsLedgerOutcome<DecisionPointResult>>;
|
|
237
|
+
observe(input: {
|
|
238
|
+
runId: string;
|
|
239
|
+
invocationId: string;
|
|
240
|
+
labels: Record<string, string>;
|
|
241
|
+
at: string;
|
|
242
|
+
evidenceRefs: EvidenceRef[];
|
|
243
|
+
}): Promise<FindingsLedgerOutcome<{
|
|
244
|
+
appended: number;
|
|
245
|
+
replayed: number;
|
|
246
|
+
}>>;
|
|
247
|
+
reliability: () => Promise<FindingsLedgerOutcome<{
|
|
248
|
+
ledgerRoot: string;
|
|
249
|
+
recordOnlyQuestions: string[];
|
|
250
|
+
attempts: number;
|
|
251
|
+
unresolved: number;
|
|
252
|
+
decisions: number;
|
|
253
|
+
failed: number;
|
|
254
|
+
labeled: number;
|
|
255
|
+
missingOutcomes: number;
|
|
256
|
+
questions: Record<string, {
|
|
257
|
+
n: number;
|
|
258
|
+
predictions: number;
|
|
259
|
+
missingLabels: number;
|
|
260
|
+
curve: ReturnType<typeof calibrationFromPairs>;
|
|
261
|
+
thresholds: Array<{
|
|
262
|
+
threshold: number;
|
|
263
|
+
n: number;
|
|
264
|
+
accuracy: number;
|
|
265
|
+
}>;
|
|
266
|
+
}>;
|
|
267
|
+
}>>;
|
|
268
|
+
};
|
|
269
|
+
//#endregion
|
|
270
|
+
//#region src/systemone-domain-match.d.ts
|
|
271
|
+
type SystemOneDomainCoverage = 'complete' | 'partial' | 'missing';
|
|
272
|
+
interface SystemOneDomainEvidence {
|
|
273
|
+
[key: string]: SystemOneJson;
|
|
274
|
+
id: string;
|
|
275
|
+
text: string;
|
|
276
|
+
}
|
|
277
|
+
interface SystemOneDomainMatchThresholds {
|
|
278
|
+
matchAtLeast: number;
|
|
279
|
+
noMatchAtLeast: number;
|
|
280
|
+
categoryAtLeast: number;
|
|
281
|
+
sourceAtLeast: number;
|
|
282
|
+
minimumMargin: number;
|
|
283
|
+
}
|
|
284
|
+
interface SystemOneDomainMatchInput {
|
|
285
|
+
version: string;
|
|
286
|
+
model: string;
|
|
287
|
+
intent: string;
|
|
288
|
+
categories: Record<string, string>;
|
|
289
|
+
evidence: SystemOneDomainEvidence[];
|
|
290
|
+
coverage: SystemOneDomainCoverage;
|
|
291
|
+
thresholds: SystemOneDomainMatchThresholds;
|
|
292
|
+
}
|
|
293
|
+
type DomainMatchQuestions = {
|
|
294
|
+
match: {
|
|
295
|
+
type: 'choice';
|
|
296
|
+
instructions: string;
|
|
297
|
+
criteria: {
|
|
298
|
+
match: string;
|
|
299
|
+
no_match: string;
|
|
300
|
+
uncertain: string;
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
category: {
|
|
304
|
+
type: 'choice';
|
|
305
|
+
instructions: string;
|
|
306
|
+
criteria: Record<string, string>;
|
|
307
|
+
};
|
|
308
|
+
source: {
|
|
309
|
+
type: 'choice';
|
|
310
|
+
instructions: string;
|
|
311
|
+
criteria: Record<string, string>;
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
interface PreparedSystemOneDomainMatch extends SystemOneDomainMatchInput {
|
|
315
|
+
request: SystemOneRequest<DomainMatchQuestions>;
|
|
316
|
+
/** Binds the intent, evidence, categories, thresholds, model, and authored option order. */
|
|
317
|
+
digest: string;
|
|
318
|
+
}
|
|
319
|
+
type SystemOneDomainMatchReason = 'match-threshold' | 'no-match-threshold' | 'missing-evidence' | 'partial-negative-evidence' | 'below-threshold' | 'ambiguous-thresholds' | 'category-unresolved' | 'source-unresolved';
|
|
320
|
+
interface SystemOneDomainMatchReport {
|
|
321
|
+
digest: string;
|
|
322
|
+
requestedModel: string;
|
|
323
|
+
servedModel: string;
|
|
324
|
+
status: 'match' | 'no_match' | 'uncertain';
|
|
325
|
+
category: string;
|
|
326
|
+
evidence: SystemOneDomainEvidence | null;
|
|
327
|
+
reason: SystemOneDomainMatchReason;
|
|
328
|
+
probabilities: {
|
|
329
|
+
match: Record<string, number>;
|
|
330
|
+
category: Record<string, number>;
|
|
331
|
+
source: Record<string, number>;
|
|
332
|
+
};
|
|
333
|
+
nativeConfidence: {
|
|
334
|
+
match: number;
|
|
335
|
+
category: number;
|
|
336
|
+
source: number;
|
|
337
|
+
};
|
|
338
|
+
scope: 'advisory-domain-match-not-authorization-or-truth';
|
|
339
|
+
}
|
|
340
|
+
/** Validate and freeze one domain classification before paid admission. */
|
|
341
|
+
declare function prepareSystemOneDomainMatch(input: SystemOneDomainMatchInput): PreparedSystemOneDomainMatch;
|
|
342
|
+
/** Shared selected-option margin for domain matching and calibrated routing. */
|
|
343
|
+
declare function systemOneChoiceMargin(probabilities: Record<string, number>, selected: string): number;
|
|
344
|
+
/** Interpret a retained native answer without another inference or any authorization effect. */
|
|
345
|
+
declare function assessSystemOneDomainMatch(prepared: PreparedSystemOneDomainMatch, raw: unknown): SystemOneDomainMatchReport;
|
|
346
|
+
//#endregion
|
|
347
|
+
//#region src/systemone.d.ts
|
|
348
|
+
type SystemOneEvaluate = EvaluatorOptions<SystemOneRequest, unknown>['execute'];
|
|
349
|
+
interface SystemOneEvaluatorOptions {
|
|
350
|
+
evaluate: SystemOneEvaluate;
|
|
351
|
+
costLedger?: EvaluatorOptions<SystemOneRequest, unknown>['costLedger'];
|
|
352
|
+
maximumCharge?: EvaluatorOptions<SystemOneRequest, unknown>['maximumCharge'];
|
|
353
|
+
pricing?: CustomTokenPricing;
|
|
354
|
+
receipt?: (response: unknown) => CostReceiptInput;
|
|
355
|
+
receiptFromError?: (error: Error) => CostReceiptInput | undefined;
|
|
356
|
+
/** Optional deployment policy; the protocol adapter does not hardcode model aliases. */
|
|
357
|
+
acceptModel?: (requested: string, served: string) => boolean;
|
|
358
|
+
}
|
|
359
|
+
/** Configure transport once; supply native state, questions, and model on every invocation. */
|
|
360
|
+
declare function systemOneEvaluator(options: SystemOneEvaluatorOptions): <const Q extends SystemOneQuestions>(request: SystemOneRequest<Q>, context?: EvaluationContext) => Promise<EvaluationResult<SystemOneResult<Q>>>;
|
|
361
|
+
type Input<A, S extends Scenario> = {
|
|
362
|
+
artifact: A;
|
|
363
|
+
scenario: S;
|
|
364
|
+
};
|
|
365
|
+
type QuestionSource<I, Q extends SystemOneQuestions> = Q | ((input: I) => Q | Promise<Q>);
|
|
366
|
+
interface SystemOneOptions extends SystemOneEvaluatorOptions {
|
|
367
|
+
model: string;
|
|
368
|
+
version: string;
|
|
369
|
+
questions: SystemOneQuestions;
|
|
370
|
+
}
|
|
371
|
+
interface SystemOneJudgeOptions<A, S extends Scenario = Scenario, Q extends SystemOneQuestions = SystemOneQuestions> extends SystemOneEvaluatorOptions {
|
|
372
|
+
model: string;
|
|
373
|
+
version: string;
|
|
374
|
+
questions: QuestionSource<Input<A, S>, Q>;
|
|
375
|
+
renderState: (input: Input<A, S>, context: EvaluationContext) => SystemOneState | Promise<SystemOneState>;
|
|
376
|
+
dimensions?: JudgeConfig<A, S>['dimensions'];
|
|
377
|
+
weights?: Record<string, number>;
|
|
378
|
+
map?: (value: SystemOneResult<Q>, input: Input<A, S>) => JudgeScore | Promise<JudgeScore>;
|
|
379
|
+
record?: (result: EvaluationResult<SystemOneResult<Q>>, input: Input<A, S>) => void | Promise<void>;
|
|
380
|
+
appliesTo?: (scenario: S) => boolean;
|
|
381
|
+
}
|
|
382
|
+
/** Optional convention. Choice utilities and non-uniform scales belong in an explicit map. */
|
|
383
|
+
declare function normalizedSystemOneScore(result: SystemOneResult, weights?: Record<string, number>): JudgeScore;
|
|
384
|
+
/** Convenience around the public evaluator. No domain questions, thresholds, or prose. */
|
|
385
|
+
declare function systemOneJudge<A, S extends Scenario = Scenario, Q extends SystemOneQuestions = SystemOneQuestions>(name: string, options: SystemOneJudgeOptions<A, S, Q>): JudgeConfig<A, S>;
|
|
386
|
+
interface SystemOneAnalystOptions<I, Q extends SystemOneQuestions = SystemOneQuestions> extends SystemOneEvaluatorOptions {
|
|
387
|
+
id: string;
|
|
388
|
+
description: string;
|
|
389
|
+
inputKind: Analyst<I>['inputKind'];
|
|
390
|
+
model: string;
|
|
391
|
+
version: string;
|
|
392
|
+
questions: Q | ((input: I, context: AnalystContext) => Q | Promise<Q>);
|
|
393
|
+
renderState: (input: I, context: AnalystContext) => SystemOneState | Promise<SystemOneState>;
|
|
394
|
+
findings: (value: SystemOneResult<Q>, input: I, context: AnalystContext) => AnalystFinding[] | Promise<AnalystFinding[]>;
|
|
395
|
+
record?: (result: EvaluationResult<SystemOneResult<Q>>, input: I, context: AnalystContext) => void | Promise<void>;
|
|
396
|
+
}
|
|
397
|
+
declare function systemOneAnalyst<I, Q extends SystemOneQuestions = SystemOneQuestions>(options: SystemOneAnalystOptions<I, Q>): Analyst<I>;
|
|
398
|
+
//#endregion
|
|
399
|
+
export { FindingsLedger as A, FindingsDiff as B, DecisionPointResult as C, decisionQuestionDigest as D, decisionPoint as E, LedgerFinding as F, PersistedFinding as H, diffFindingsOverTime as I, openFindingsLedger as L, FindingsLedgerRead as M, FindingsQuery as N, DecisionRecord as O, FindingsTimeStep as P, queryFindings as R, DecisionPointOptions as S, DecisionQuestions as T, diffFindings as U, FindingsStore as V, assessSystemOneDomainMatch as _, SystemOneOptions as a, DECISION_POINT_MIN_KAPPA as b, systemOneEvaluator as c, SystemOneDomainCoverage as d, SystemOneDomainEvidence as f, SystemOneDomainMatchThresholds as g, SystemOneDomainMatchReport as h, SystemOneJudgeOptions as i, FindingsLedgerOutcome as j, DecisionRoute as k, systemOneJudge as l, SystemOneDomainMatchReason as m, SystemOneEvaluate as n, normalizedSystemOneScore as o, SystemOneDomainMatchInput as p, SystemOneEvaluatorOptions as r, systemOneAnalyst as s, SystemOneAnalystOptions as t, PreparedSystemOneDomainMatch as u, prepareSystemOneDomainMatch as v, DecisionQuestionPolicy as w, DecisionInvocation as x, systemOneChoiceMargin as y, DiffPolicy as z };
|
|
400
|
+
//# sourceMappingURL=systemone-D3MrW63C.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"systemone-D3MrW63C.d.ts","names":["_$__meta_eval0.calibrationFromPairs"],"sources":["../src/analyst/findings-store.ts","../src/analyst/findings-ledger.ts","../src/decision-point-records.ts","../src/decision-point.ts","../src/systemone-domain-match.ts","../src/systemone.ts"],"mappings":";;;;;;;;;;;;;;;UA8BiB,yBAAyB;EACxC;;cAGW;WAGiB;mBAFX;EAEjB,YAA4B;EAItB,OAAO,eAAe,UAAU,mBAAmB;;EAQzD,WAAW;;EAkBX,QAAQ,gBAAgB;;UAOT;;EAEf,UAAU;;EAEV,aAAa;;EAEb,WAAW;;;;;EAKX,SAAS;IAAQ,UAAU;IAAkB,SAAS;;;UAGvC;;;;;;;;EAQf,cAAc,UAAU,gBAAgB,SAAS;;;;;;iBAkBnC,aACd,UAAU,oBACV,SAAS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AAI,OAAO,MAAM,GAAG,OAAO,aAAa,QAAQ;EAC9E,UACE,QAAQ,iBAAiB,gBAAgB,KACzC,OAAO,MAAM,GAAG,cACN;EACZ,aAAa,UAAU;;;iBA0BT,yBACd,QAAQ,iBACR,UAAU,yBACT;;iBAgCa,eACd,GACA,UAAU,WAAW,UACrB,UAAU,qBAAqB,oBAC/B,cAAc,SAAS,sBAAsB,GAAG,GAAG,KAAK,YAAY,GAAG;UAqDxD,wBAAwB,GAAG,UAAU,qBAAqB,4BACjE;EACR;EACA;EACA,WAAW,QAAQ;EACnB;EACA;EACA,WAAW,MAAM,OAAO,GAAG,SAAS,mBAAmB,IAAI,QAAQ;EACnE,cAAc,OAAO,GAAG,SAAS,mBAAmB,iBAAiB,QAAQ;EAC7E,WACE,OAAO,gBAAgB,IACvB,OAAO,GACP,SAAS,mBACN,mBAAmB,QAAQ;EAChC,UACE,QAAQ,iBAAiB,gBAAgB,KACzC,OAAO,GACP,SAAS,0BACC;;iBAGE,iBAAiB,GAAG,UAAU,qBAAqB,oBACjE,SAAS,wBAAwB,GAAG,KACnC,QAAQ"}
|
|
@@ -93,6 +93,8 @@ declare function parseSystemOneRequest(raw: unknown): SystemOneRequest;
|
|
|
93
93
|
* Live transports must still call parseSystemOneRequest, even for re-execution of an old request. */
|
|
94
94
|
declare function parseSystemOneRecordedRequest(raw: unknown): SystemOneRecordedRequest;
|
|
95
95
|
declare function systemOneUsage(raw: unknown): SystemOneResult['usage'];
|
|
96
|
+
/** The strict parser's allowance for floating-point error; provider rounding is normalized first. */
|
|
97
|
+
declare const SYSTEM_ONE_PROBABILITY_TOLERANCE = 0.0001;
|
|
96
98
|
/** Validate native evidence, not model alias policy or the caller's scoring rules. */
|
|
97
99
|
declare function parseSystemOneResult<Q extends SystemOneRecordedQuestions>(raw: unknown, request: SystemOneRecordedRequest<Q>): SystemOneResult<Q>;
|
|
98
100
|
/**
|
|
@@ -128,5 +130,5 @@ declare function systemOneConfidence(answer: {
|
|
|
128
130
|
*/
|
|
129
131
|
declare function normalizeSystemOneResult(raw: unknown, request: SystemOneRecordedRequest, profile: SystemOneResultProfile): unknown;
|
|
130
132
|
//#endregion
|
|
131
|
-
export { systemOneUsage as S,
|
|
132
|
-
//# sourceMappingURL=systemone-protocol-
|
|
133
|
+
export { systemOneUsage as C, systemOneConfidence as S, normalizeSystemOneResult as _, SystemOneJson as a, parseSystemOneRequest as b, SystemOneRecordedQuestion as c, SystemOneRequest as d, SystemOneResponseError as f, SystemOneState as g, SystemOneScoreCriteria as h, SystemOneDescription as i, SystemOneRecordedQuestions as l, SystemOneResultProfile as m, SystemOneAnswer as n, SystemOneQuestion as o, SystemOneResult as p, SystemOneAnswerFor as r, SystemOneQuestions as s, SYSTEM_ONE_PROBABILITY_TOLERANCE as t, SystemOneRecordedRequest as u, parseSystemOneQuestions as v, parseSystemOneResult as x, parseSystemOneRecordedRequest as y };
|
|
134
|
+
//# sourceMappingURL=systemone-protocol-Bl2EI2KQ.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"systemone-protocol-
|
|
1
|
+
{"version":3,"file":"systemone-protocol-Bl2EI2KQ.d.ts","names":[],"sources":["../src/systemone-protocol.ts"],"mappings":";;;;;;KAQY,mDAKR;GACG,cAAc;;;KAET;GAA6B,cAAc;IAAkB;;KAE7D,uBAAuB;KACvB,mCAAmC,gBAAgB,mBAAmB;KACtE;EAEN;EACA,eAAe;EACf;IAAa,OAAO;IAAsB,QAAQ;;;EAElD;EAAe,eAAe;EAAsB,UAAU;;EAE9D;EACA,eAAe;EACf,UAAU,eAAe;;KAEnB,qBAAqB,eAAe;UAC/B,iBAAiB,UAAU,qBAAqB;EAC/D;EACA,OAAO;EACP,WAAW;;;KAID,4BACR,QAAQ;EAAqB;;EAE3B;EACA,eAAe;EACf,oBAAoB,sBAAsB,yBAAyB;;KAE7D,6BAA6B,eAAe;UACvC,yBACf,UAAU,6BAA6B;EAEvC;EACA,OAAO;EACP,WAAW;;KAGR,UAAU,mBAAmB,yCAAyC,uBAEvE,cAAc;KACN,mBAAmB,UAAU,6BAA6B;EAAY;;WACnE;WAAuB;IAClC;EAAY;EAAe,gBAAgB,mBAAmB;;WAEjD;WACA;WACA;WACA,oBAAoB,KAAK,UAAU,KAAK,EAAE;WAC1C,2BAA2B,KAAK,UAAU;IAErD;EAAY;EAAgB,gBAAgB;;WAE/B;WACA,cAAc;WACd;WACA,2BAA2B,WAAW;;KAG7C,kBAAkB,mBAAmB;UAChC,gBAAgB,UAAU,6BAA6B;WAC7D;WACA,qBAAqB,WAAW,IAAI,mBAAmB,EAAE;WACzD;aAAkB;aAA+B;;;cAG/C,+BAA+B;EAC1C,YAAY;;;iBA6BE,wBAAwB,eAAe;iBAyCvC,sBAAsB,eAAe;;;iBAMrC,8BAA8B,eAAe;iBAe7C,eAAe,eAAe;;cAWjC;;iBAgCG,qBAAqB,UAAU,4BAC7C,cACA,SAAS,yBAAyB,KACjC,gBAAgB;;;;;UA4DF;;WAEN;;;;;WAKA;;;;;;;;iBASK,oBAAoB;WACzB;WACA,eAAe,SAAS;;;;;;;;;;iBAyHnB,yBACd,cACA,SAAS,0BACT,SAAS"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { SystemOneAnswer, SystemOneAnswerFor, SystemOneDescription, SystemOneJson, SystemOneQuestion, SystemOneQuestions, SystemOneRecordedQuestion, SystemOneRecordedQuestions, SystemOneRecordedRequest, SystemOneRequest, SystemOneResponseError, SystemOneResult, SystemOneResultProfile, SystemOneScoreCriteria, SystemOneState, normalizeSystemOneResult, parseSystemOneQuestions, parseSystemOneRecordedRequest, parseSystemOneRequest, parseSystemOneResult, systemOneConfidence, systemOneUsage };
|
|
1
|
+
import { C as systemOneUsage, S as systemOneConfidence, _ as normalizeSystemOneResult, a as SystemOneJson, b as parseSystemOneRequest, c as SystemOneRecordedQuestion, d as SystemOneRequest, f as SystemOneResponseError, g as SystemOneState, h as SystemOneScoreCriteria, i as SystemOneDescription, l as SystemOneRecordedQuestions, m as SystemOneResultProfile, n as SystemOneAnswer, o as SystemOneQuestion, p as SystemOneResult, r as SystemOneAnswerFor, s as SystemOneQuestions, t as SYSTEM_ONE_PROBABILITY_TOLERANCE, u as SystemOneRecordedRequest, v as parseSystemOneQuestions, x as parseSystemOneResult, y as parseSystemOneRecordedRequest } from "./systemone-protocol-Bl2EI2KQ.js";
|
|
2
|
+
export { SYSTEM_ONE_PROBABILITY_TOLERANCE, SystemOneAnswer, SystemOneAnswerFor, SystemOneDescription, SystemOneJson, SystemOneQuestion, SystemOneQuestions, SystemOneRecordedQuestion, SystemOneRecordedQuestions, SystemOneRecordedRequest, SystemOneRequest, SystemOneResponseError, SystemOneResult, SystemOneResultProfile, SystemOneScoreCriteria, SystemOneState, normalizeSystemOneResult, parseSystemOneQuestions, parseSystemOneRecordedRequest, parseSystemOneRequest, parseSystemOneResult, systemOneConfidence, systemOneUsage };
|
|
@@ -71,7 +71,7 @@ function systemOneUsage(raw) {
|
|
|
71
71
|
return usage;
|
|
72
72
|
}
|
|
73
73
|
/** The strict parser's allowance for floating-point error; provider rounding is normalized first. */
|
|
74
|
-
const
|
|
74
|
+
const SYSTEM_ONE_PROBABILITY_TOLERANCE = 1e-4;
|
|
75
75
|
function levelsOf(question) {
|
|
76
76
|
return question.type === "score" ? question.criteria.map((_, index) => String(index)) : question.type === "choice" ? Object.keys(question.criteria) : [];
|
|
77
77
|
}
|
|
@@ -105,13 +105,13 @@ function parseSystemOneResult(raw, request) {
|
|
|
105
105
|
const probabilities = object(answer.probabilities);
|
|
106
106
|
exactKeys(probabilities, levels);
|
|
107
107
|
const sum = levels.reduce((total, level) => total + probability(probabilities[level]), 0);
|
|
108
|
-
if (Math.abs(sum - 1) >
|
|
108
|
+
if (Math.abs(sum - 1) > 1e-4) throw new SystemOneResponseError("Invalid probability distribution");
|
|
109
109
|
if (question.type === "score") {
|
|
110
110
|
const legend = object(answer.legend);
|
|
111
111
|
exactKeys(legend, levels);
|
|
112
112
|
if (levels.some((level) => !isDeepStrictEqual(legend[level], question.criteria[Number(level)]))) throw new SystemOneResponseError("Provider changed the rubric");
|
|
113
|
-
if (typeof answer.score !== "number" || !Number.isFinite(answer.score) || Math.abs(answer.score - expectation(levels, probabilities)) >
|
|
114
|
-
} else if (typeof answer.choice !== "string" || !Object.hasOwn(probabilities, answer.choice) || levels.some((level) => Number(probabilities[level]) > Number(probabilities[String(answer.choice)]) +
|
|
113
|
+
if (typeof answer.score !== "number" || !Number.isFinite(answer.score) || Math.abs(answer.score - expectation(levels, probabilities)) > 1e-4) throw new SystemOneResponseError("Score differs from its distribution");
|
|
114
|
+
} else if (typeof answer.choice !== "string" || !Object.hasOwn(probabilities, answer.choice) || levels.some((level) => Number(probabilities[level]) > Number(probabilities[String(answer.choice)]) + 1e-4)) throw new SystemOneResponseError("Choice is not a highest-probability option");
|
|
115
115
|
}
|
|
116
116
|
systemOneUsage(raw);
|
|
117
117
|
return raw;
|
|
@@ -156,12 +156,12 @@ function normalizeAnswer(answer, question, profile) {
|
|
|
156
156
|
const score = answer.score;
|
|
157
157
|
if (scored && (typeof score !== "number" || !Number.isFinite(score))) return answer;
|
|
158
158
|
let next = answer;
|
|
159
|
-
if (!(Math.abs(sum - 1) <=
|
|
159
|
+
if (!(Math.abs(sum - 1) <= 1e-4 && (!scored || Math.abs(score - expectation(levels, q)) <= 1e-4)) && profile.decimals !== void 0) {
|
|
160
160
|
const unit = 10 ** -profile.decimals;
|
|
161
161
|
if (Math.abs(sum - 1) > levels.length * unit / 2) throw new SystemOneResponseError("Distribution error exceeds declared rounding");
|
|
162
162
|
const levelTotal = levels.length * (levels.length - 1) / 2;
|
|
163
163
|
if (scored && Math.abs(score - expectation(levels, q)) > unit / 2 + unit * levelTotal) throw new SystemOneResponseError("Score error exceeds declared rounding");
|
|
164
|
-
const p = Math.abs(sum - 1) <=
|
|
164
|
+
const p = Math.abs(sum - 1) <= 1e-4 ? q : Object.fromEntries(keys.map((key) => [key, q[key] / sum]));
|
|
165
165
|
next = {
|
|
166
166
|
...answer,
|
|
167
167
|
probabilities: p,
|
|
@@ -209,6 +209,6 @@ function normalizeSystemOneResult(raw, request, profile) {
|
|
|
209
209
|
} : raw;
|
|
210
210
|
}
|
|
211
211
|
//#endregion
|
|
212
|
-
export { SystemOneResponseError, normalizeSystemOneResult, parseSystemOneQuestions, parseSystemOneRecordedRequest, parseSystemOneRequest, parseSystemOneResult, systemOneConfidence, systemOneUsage };
|
|
212
|
+
export { SYSTEM_ONE_PROBABILITY_TOLERANCE, SystemOneResponseError, normalizeSystemOneResult, parseSystemOneQuestions, parseSystemOneRecordedRequest, parseSystemOneRequest, parseSystemOneResult, systemOneConfidence, systemOneUsage };
|
|
213
213
|
|
|
214
214
|
//# sourceMappingURL=systemone-protocol.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"systemone-protocol.js","names":[],"sources":["../src/systemone-protocol.ts"],"sourcesContent":["import { isDeepStrictEqual } from 'node:util'\nimport { canonicalString } from './ledger-core/canonical'\n\n/**\n * The System One wire contract (TypeSafe-originated, https://api.typesafe.ai/openapi.json; also\n * served by Cloudflare Workers AI and Perplexity). This module names no endpoint, credential or\n * model; callers can use TypeSafe's SDK builders unchanged.\n */\nexport type SystemOneJson =\n | string\n | number\n | boolean\n | null\n | SystemOneJson[]\n | { [key: string]: SystemOneJson }\n/** What the TypeSafe route accepts as `state` and as a score level: text or JSON, never null. */\nexport type SystemOneState = string | { [key: string]: SystemOneJson } | SystemOneJson[]\n/** Instructions and choice or noul descriptions, which TypeSafe also accepts as null. */\nexport type SystemOneDescription = SystemOneState | null\nexport type SystemOneScoreCriteria = readonly [SystemOneState, SystemOneState, ...SystemOneState[]]\nexport type SystemOneQuestion =\n | {\n type: 'noul'\n instructions?: SystemOneDescription\n criteria?: { true?: SystemOneDescription; false?: SystemOneDescription } | null\n }\n | { type: 'score'; instructions?: SystemOneDescription; criteria: SystemOneScoreCriteria }\n | {\n type: 'choice'\n instructions?: SystemOneDescription\n criteria: Record<string, SystemOneDescription>\n }\nexport type SystemOneQuestions = Record<string, SystemOneQuestion>\nexport interface SystemOneRequest<Q extends SystemOneQuestions = SystemOneQuestions> {\n model: string\n state: SystemOneState\n questions: Q\n}\n\n/** Historical Tangle observations accepted null state and score levels. Not a live request. */\nexport type SystemOneRecordedQuestion =\n | Exclude<SystemOneQuestion, { type: 'score' }>\n | {\n type: 'score'\n instructions?: SystemOneDescription\n criteria: readonly [SystemOneDescription, SystemOneDescription, ...SystemOneDescription[]]\n }\nexport type SystemOneRecordedQuestions = Record<string, SystemOneRecordedQuestion>\nexport interface SystemOneRecordedRequest<\n Q extends SystemOneRecordedQuestions = SystemOneRecordedQuestions,\n> {\n model: string\n state: SystemOneDescription\n questions: Q\n}\n\ntype ScoreKeys<T extends readonly SystemOneDescription[]> = number extends T['length']\n ? number\n : Extract<keyof T, `${number}`>\nexport type SystemOneAnswerFor<Q extends SystemOneRecordedQuestion> = Q extends { type: 'noul' }\n ? { readonly type: 'noul'; readonly noul: number }\n : Q extends { type: 'score'; criteria: infer C extends readonly SystemOneDescription[] }\n ? {\n readonly type: 'score'\n readonly score: number\n readonly confidence: number\n readonly legend: { readonly [K in ScoreKeys<C>]: C[K] }\n readonly probabilities: { readonly [K in ScoreKeys<C>]: number }\n }\n : Q extends { type: 'choice'; criteria: infer C }\n ? {\n readonly type: 'choice'\n readonly choice: keyof C & string\n readonly confidence: number\n readonly probabilities: { readonly [K in keyof C]: number }\n }\n : never\nexport type SystemOneAnswer = SystemOneAnswerFor<SystemOneQuestion>\nexport interface SystemOneResult<Q extends SystemOneRecordedQuestions = SystemOneQuestions> {\n readonly model: string\n readonly answers: { readonly [K in keyof Q]: SystemOneAnswerFor<Q[K]> }\n readonly usage: { readonly input_tokens: number; readonly output_tokens: number }\n}\n\nexport class SystemOneResponseError extends Error {\n constructor(message: string) {\n super(`System One: ${message}`)\n this.name = 'SystemOneResponseError'\n }\n}\n\nfunction object(value: unknown): Record<string, unknown> {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n throw new SystemOneResponseError('Expected an object')\n }\n return value as Record<string, unknown>\n}\n\n// Providers answer 422 for a null state, and TypeSafe also for a null score level. Refusing them\n// here reports the caller's mistake before a paid round trip, not as a provider failure after one.\nfunction textOrJson(value: unknown, name: string): void {\n if (typeof value === 'string') return\n if (value === null || typeof value !== 'object') {\n throw new TypeError(`${name} must be text or a JSON object/array`)\n }\n // Reuse the canonical JSON validator rather than accepting lossy Map/Date coercions.\n canonicalString(value)\n}\n\nfunction optionalTextOrJson(value: unknown, name: string): void {\n if (value !== null) textOrJson(value, name)\n}\n\n/** Validate named questions without a state, as a judge does before it has input. */\nexport function parseSystemOneQuestions(raw: unknown): SystemOneQuestions {\n return readQuestions(raw, false) as SystemOneQuestions\n}\n\nfunction readQuestions(raw: unknown, recorded: boolean): SystemOneRecordedQuestions {\n const questions = object(raw)\n if (!Object.keys(questions).length) throw new TypeError('At least one question is required')\n for (const [name, rawQuestion] of Object.entries(questions)) {\n const question = object(rawQuestion)\n if (question.instructions !== undefined) {\n optionalTextOrJson(question.instructions, `${name} instructions`)\n }\n if (question.type === 'noul') {\n if (question.criteria != null) {\n const criteria = object(question.criteria)\n if (Object.keys(criteria).some((key) => key !== 'true' && key !== 'false')) {\n throw new TypeError('Noul criteria must describe true and/or false')\n }\n for (const value of Object.values(criteria)) {\n if (value !== undefined) optionalTextOrJson(value, `${name} criteria`)\n }\n }\n } else if (question.type === 'score') {\n if (!Array.isArray(question.criteria) || question.criteria.length < 2) {\n throw new TypeError('Score criteria require at least two ordered entries')\n }\n for (const value of question.criteria) {\n if (recorded && value === null) continue\n textOrJson(value, `${name} score level`)\n }\n } else if (question.type === 'choice') {\n const criteria = object(question.criteria)\n if (!Object.keys(criteria).length) throw new TypeError('Choice criteria cannot be empty')\n for (const value of Object.values(criteria)) optionalTextOrJson(value, `${name} choice`)\n } else {\n throw new TypeError('Unsupported native question type')\n }\n }\n return raw as SystemOneRecordedQuestions\n}\n\nexport function parseSystemOneRequest(raw: unknown): SystemOneRequest {\n return readRequest(raw, false) as SystemOneRequest\n}\n\n/** Read immutable historical evidence without rewriting it or authorizing new inference.\n * Live transports must still call parseSystemOneRequest, even for re-execution of an old request. */\nexport function parseSystemOneRecordedRequest(raw: unknown): SystemOneRecordedRequest {\n canonicalString(raw)\n return readRequest(raw, true)\n}\n\nfunction readRequest(raw: unknown, recorded: boolean): SystemOneRecordedRequest {\n const request = object(raw)\n if (typeof request.model !== 'string' || !request.model.trim()) {\n throw new TypeError('Evaluation requires a model')\n }\n if (!recorded || request.state !== null) textOrJson(request.state, 'Evaluation state')\n readQuestions(request.questions, recorded)\n return raw as SystemOneRecordedRequest\n}\n\nexport function systemOneUsage(raw: unknown): SystemOneResult['usage'] {\n const usage = object(object(raw).usage)\n for (const key of ['input_tokens', 'output_tokens']) {\n if (!Number.isSafeInteger(usage[key]) || Number(usage[key]) < 0) {\n throw new SystemOneResponseError('Missing or invalid usage')\n }\n }\n return usage as unknown as SystemOneResult['usage']\n}\n\n/** The strict parser's allowance for floating-point error; provider rounding is normalized first. */\nconst TOLERANCE = 0.0001\n\nfunction levelsOf(question: SystemOneRecordedQuestion): string[] {\n return question.type === 'score'\n ? question.criteria.map((_, index) => String(index))\n : question.type === 'choice'\n ? Object.keys(question.criteria)\n : []\n}\n\n/** Σ level·p over score levels \"0\"..\"n-1\". */\nfunction expectation(levels: string[], probabilities: Record<string, unknown>): number {\n return levels.reduce((total, level) => total + Number(level) * Number(probabilities[level]), 0)\n}\n\nfunction probability(value: unknown): number {\n if (typeof value !== 'number' || !Number.isFinite(value) || value < 0 || value > 1) {\n throw new SystemOneResponseError('Invalid probability')\n }\n return value\n}\n\nfunction exactKeys(value: Record<string, unknown>, names: string[]): void {\n if (\n Object.keys(value).length !== names.length ||\n names.some((key) => !Object.hasOwn(value, key))\n ) {\n throw new SystemOneResponseError('Response keys differ from the request')\n }\n}\n\n/** Validate native evidence, not model alias policy or the caller's scoring rules. */\nexport function parseSystemOneResult<Q extends SystemOneRecordedQuestions>(\n raw: unknown,\n request: SystemOneRecordedRequest<Q>,\n): SystemOneResult<Q> {\n // Preserve extension metadata, rejecting values that change when persisted as JSON.\n canonicalString(raw)\n const response = object(raw)\n if (typeof response.model !== 'string' || !response.model.trim()) {\n throw new SystemOneResponseError('Missing served model')\n }\n const answers = object(response.answers)\n exactKeys(answers, Object.keys(request.questions))\n for (const [name, question] of Object.entries(request.questions)) {\n const answer = object(answers[name])\n if (answer.type !== question.type) throw new SystemOneResponseError('Wrong answer type')\n if (question.type === 'noul') {\n probability(answer.noul)\n continue\n }\n probability(answer.confidence)\n const levels = levelsOf(question)\n const probabilities = object(answer.probabilities)\n exactKeys(probabilities, levels)\n const sum = levels.reduce((total, level) => total + probability(probabilities[level]), 0)\n if (Math.abs(sum - 1) > TOLERANCE) {\n throw new SystemOneResponseError('Invalid probability distribution')\n }\n if (question.type === 'score') {\n const legend = object(answer.legend)\n exactKeys(legend, levels)\n if (\n levels.some((level) => !isDeepStrictEqual(legend[level], question.criteria[Number(level)]))\n ) {\n throw new SystemOneResponseError('Provider changed the rubric')\n }\n if (\n typeof answer.score !== 'number' ||\n !Number.isFinite(answer.score) ||\n Math.abs(answer.score - expectation(levels, probabilities)) > TOLERANCE\n ) {\n throw new SystemOneResponseError('Score differs from its distribution')\n }\n } else if (\n typeof answer.choice !== 'string' ||\n !Object.hasOwn(probabilities, answer.choice) ||\n levels.some(\n (level) =>\n Number(probabilities[level]) > Number(probabilities[String(answer.choice)]) + TOLERANCE,\n )\n ) {\n throw new SystemOneResponseError('Choice is not a highest-probability option')\n }\n }\n systemOneUsage(raw)\n return raw as SystemOneResult<Q>\n}\n\n/**\n * How one provider reports results, measured from its responses. The caller that owns the\n * provider route supplies it; this module names no provider.\n */\nexport interface SystemOneResultProfile {\n /** Decimal places the provider rounds probabilities and scores to. Omit when it reports exact values. */\n readonly decimals?: number\n /**\n * `canonical`: the provider's `confidence` already follows `systemOneConfidence`.\n * `provider-defined`: it follows another definition, kept as `provider_confidence`.\n */\n readonly confidence: 'canonical' | 'provider-defined'\n}\n\n/**\n * The one confidence definition every route reports, TypeSafe's published formulas\n * (https://docs.typesafe.ai/confidence). Choice: (p_max − 1/n)/(1 − 1/n), and 1 for one option.\n * Score: 1 − Σ p_i·|i − m| / MAD_uniform, where m is the most likely level (the lowest on ties)\n * and MAD_uniform = (1/n)·Σ|i − (n − 1)/2|. Expects a normalized distribution; noul has none.\n */\nexport function systemOneConfidence(answer: {\n readonly type: 'choice' | 'score'\n readonly probabilities: Readonly<Record<string, number>>\n}): number {\n const labels = Object.keys(answer.probabilities)\n const n = labels.length\n const p = labels.map(\n (label, index) => answer.probabilities[answer.type === 'score' ? String(index) : label],\n )\n if (\n !n ||\n (answer.type === 'score' && n < 2) ||\n p.some(\n (value) => typeof value !== 'number' || !Number.isFinite(value) || value < 0 || value > 1,\n )\n ) {\n throw new TypeError('Confidence requires a probability for every option or score level')\n }\n const values = p as number[]\n const peak = Math.max(...values)\n let confidence: number\n if (answer.type === 'choice') {\n confidence = n === 1 ? 1 : (peak - 1 / n) / (1 - 1 / n)\n } else {\n const mode = values.indexOf(peak)\n const center = (n - 1) / 2\n const uniform = values.reduce((total, _, level) => total + Math.abs(level - center), 0) / n\n const spread = values.reduce((total, value, level) => total + value * Math.abs(level - mode), 0)\n confidence = 1 - spread / uniform\n }\n return Math.min(1, Math.max(0, confidence))\n}\n\nfunction readProfile(profile: SystemOneResultProfile): void {\n if (\n profile === null ||\n typeof profile !== 'object' ||\n (profile.decimals !== undefined &&\n (!Number.isSafeInteger(profile.decimals) || profile.decimals < 0 || profile.decimals > 15)) ||\n (profile.confidence !== 'canonical' && profile.confidence !== 'provider-defined')\n ) {\n throw new TypeError('Invalid System One result profile')\n }\n}\n\nfunction normalizeAnswer(\n answer: Record<string, unknown>,\n question: Exclude<SystemOneRecordedQuestion, { type: 'noul' }>,\n profile: SystemOneResultProfile,\n): Record<string, unknown> {\n const levels = levelsOf(question)\n const probabilities = answer.probabilities as Record<string, unknown>\n const keys = Object.keys(probabilities)\n if (\n keys.length !== levels.length ||\n levels.some((level) => {\n const value = probabilities[level]\n return (\n !Object.hasOwn(probabilities, level) ||\n typeof value !== 'number' ||\n !(value >= 0 && value <= 1)\n )\n })\n ) {\n // Leave shapes the strict parser refuses for it to name.\n return answer\n }\n const q = probabilities as Record<string, number>\n const sum = keys.reduce((total, key) => total + q[key]!, 0)\n const scored = question.type === 'score'\n const score = answer.score\n if (scored && (typeof score !== 'number' || !Number.isFinite(score))) return answer\n let next = answer\n const consistent =\n Math.abs(sum - 1) <= TOLERANCE &&\n (!scored || Math.abs((score as number) - expectation(levels, q)) <= TOLERANCE)\n if (!consistent && profile.decimals !== undefined) {\n // Rounding to `decimals` moves each reported probability by at most one unit in the last\n // place, and the reported score by half a unit; anything larger is a provider defect.\n const unit = 10 ** -profile.decimals\n if (Math.abs(sum - 1) > (levels.length * unit) / 2) {\n throw new SystemOneResponseError('Distribution error exceeds declared rounding')\n }\n const levelTotal = (levels.length * (levels.length - 1)) / 2\n if (\n scored &&\n Math.abs((score as number) - expectation(levels, q)) > unit / 2 + unit * levelTotal\n ) {\n throw new SystemOneResponseError('Score error exceeds declared rounding')\n }\n const p =\n Math.abs(sum - 1) <= TOLERANCE\n ? q\n : Object.fromEntries(keys.map((key) => [key, q[key]! / sum]))\n next = { ...answer, probabilities: p, ...(scored ? { score: expectation(levels, p) } : {}) }\n }\n // An answer that already carries provider_confidence was normalized before.\n if (\n profile.confidence === 'provider-defined' &&\n typeof answer.confidence === 'number' &&\n !Object.hasOwn(answer, 'provider_confidence')\n ) {\n next = {\n ...next,\n provider_confidence: answer.confidence,\n confidence: systemOneConfidence({\n type: question.type,\n probabilities: next.probabilities as Record<string, number>,\n }),\n }\n }\n return next\n}\n\n/**\n * Remove a provider's declared rounding and apply the one confidence definition, before\n * `parseSystemOneResult`. An answer that already passes the strict checks keeps its\n * probabilities and score. One that fails them only within the declared rounding is renormalized\n * and its score recomputed from that distribution; larger error throws. Noul answers never change.\n * Returns `raw` itself when nothing changes and never mutates it; shapes it cannot read are left\n * for the strict parser to refuse.\n */\nexport function normalizeSystemOneResult(\n raw: unknown,\n request: SystemOneRecordedRequest,\n profile: SystemOneResultProfile,\n): unknown {\n readProfile(profile)\n if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) return raw\n const response = raw as Record<string, unknown>\n const original = response.answers\n if (original === null || typeof original !== 'object' || Array.isArray(original)) return raw\n const answers: Record<string, unknown> = { ...original }\n let changed = false\n for (const [name, question] of Object.entries(request.questions)) {\n const answer = answers[name]\n if (\n question.type === 'noul' ||\n answer === null ||\n typeof answer !== 'object' ||\n Array.isArray(answer) ||\n (answer as Record<string, unknown>).type !== question.type ||\n (answer as Record<string, unknown>).probabilities === null ||\n typeof (answer as Record<string, unknown>).probabilities !== 'object' ||\n Array.isArray((answer as Record<string, unknown>).probabilities)\n ) {\n continue\n }\n const next = normalizeAnswer(answer as Record<string, unknown>, question, profile)\n if (next !== answer) {\n answers[name] = next\n changed = true\n }\n }\n return changed ? { ...response, answers } : raw\n}\n"],"mappings":";;;AAoFA,IAAa,yBAAb,cAA4C,MAAM;CAChD,YAAY,SAAiB;EAC3B,MAAM,eAAe,SAAS;EAC9B,KAAK,OAAO;CACd;AACF;AAEA,SAAS,OAAO,OAAyC;CACvD,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GACpE,MAAM,IAAI,uBAAuB,oBAAoB;CAEvD,OAAO;AACT;AAIA,SAAS,WAAW,OAAgB,MAAoB;CACtD,IAAI,OAAO,UAAU,UAAU;CAC/B,IAAI,UAAU,QAAQ,OAAO,UAAU,UACrC,MAAM,IAAI,UAAU,GAAG,KAAK,qCAAqC;CAGnE,gBAAgB,KAAK;AACvB;AAEA,SAAS,mBAAmB,OAAgB,MAAoB;CAC9D,IAAI,UAAU,MAAM,WAAW,OAAO,IAAI;AAC5C;;AAGA,SAAgB,wBAAwB,KAAkC;C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
+
{"version":3,"file":"systemone-protocol.js","names":[],"sources":["../src/systemone-protocol.ts"],"sourcesContent":["import { isDeepStrictEqual } from 'node:util'\nimport { canonicalString } from './ledger-core/canonical'\n\n/**\n * The System One wire contract (TypeSafe-originated, https://api.typesafe.ai/openapi.json; also\n * served by Cloudflare Workers AI and Perplexity). This module names no endpoint, credential or\n * model; callers can use TypeSafe's SDK builders unchanged.\n */\nexport type SystemOneJson =\n | string\n | number\n | boolean\n | null\n | SystemOneJson[]\n | { [key: string]: SystemOneJson }\n/** What the TypeSafe route accepts as `state` and as a score level: text or JSON, never null. */\nexport type SystemOneState = string | { [key: string]: SystemOneJson } | SystemOneJson[]\n/** Instructions and choice or noul descriptions, which TypeSafe also accepts as null. */\nexport type SystemOneDescription = SystemOneState | null\nexport type SystemOneScoreCriteria = readonly [SystemOneState, SystemOneState, ...SystemOneState[]]\nexport type SystemOneQuestion =\n | {\n type: 'noul'\n instructions?: SystemOneDescription\n criteria?: { true?: SystemOneDescription; false?: SystemOneDescription } | null\n }\n | { type: 'score'; instructions?: SystemOneDescription; criteria: SystemOneScoreCriteria }\n | {\n type: 'choice'\n instructions?: SystemOneDescription\n criteria: Record<string, SystemOneDescription>\n }\nexport type SystemOneQuestions = Record<string, SystemOneQuestion>\nexport interface SystemOneRequest<Q extends SystemOneQuestions = SystemOneQuestions> {\n model: string\n state: SystemOneState\n questions: Q\n}\n\n/** Historical Tangle observations accepted null state and score levels. Not a live request. */\nexport type SystemOneRecordedQuestion =\n | Exclude<SystemOneQuestion, { type: 'score' }>\n | {\n type: 'score'\n instructions?: SystemOneDescription\n criteria: readonly [SystemOneDescription, SystemOneDescription, ...SystemOneDescription[]]\n }\nexport type SystemOneRecordedQuestions = Record<string, SystemOneRecordedQuestion>\nexport interface SystemOneRecordedRequest<\n Q extends SystemOneRecordedQuestions = SystemOneRecordedQuestions,\n> {\n model: string\n state: SystemOneDescription\n questions: Q\n}\n\ntype ScoreKeys<T extends readonly SystemOneDescription[]> = number extends T['length']\n ? number\n : Extract<keyof T, `${number}`>\nexport type SystemOneAnswerFor<Q extends SystemOneRecordedQuestion> = Q extends { type: 'noul' }\n ? { readonly type: 'noul'; readonly noul: number }\n : Q extends { type: 'score'; criteria: infer C extends readonly SystemOneDescription[] }\n ? {\n readonly type: 'score'\n readonly score: number\n readonly confidence: number\n readonly legend: { readonly [K in ScoreKeys<C>]: C[K] }\n readonly probabilities: { readonly [K in ScoreKeys<C>]: number }\n }\n : Q extends { type: 'choice'; criteria: infer C }\n ? {\n readonly type: 'choice'\n readonly choice: keyof C & string\n readonly confidence: number\n readonly probabilities: { readonly [K in keyof C]: number }\n }\n : never\nexport type SystemOneAnswer = SystemOneAnswerFor<SystemOneQuestion>\nexport interface SystemOneResult<Q extends SystemOneRecordedQuestions = SystemOneQuestions> {\n readonly model: string\n readonly answers: { readonly [K in keyof Q]: SystemOneAnswerFor<Q[K]> }\n readonly usage: { readonly input_tokens: number; readonly output_tokens: number }\n}\n\nexport class SystemOneResponseError extends Error {\n constructor(message: string) {\n super(`System One: ${message}`)\n this.name = 'SystemOneResponseError'\n }\n}\n\nfunction object(value: unknown): Record<string, unknown> {\n if (value === null || typeof value !== 'object' || Array.isArray(value)) {\n throw new SystemOneResponseError('Expected an object')\n }\n return value as Record<string, unknown>\n}\n\n// Providers answer 422 for a null state, and TypeSafe also for a null score level. Refusing them\n// here reports the caller's mistake before a paid round trip, not as a provider failure after one.\nfunction textOrJson(value: unknown, name: string): void {\n if (typeof value === 'string') return\n if (value === null || typeof value !== 'object') {\n throw new TypeError(`${name} must be text or a JSON object/array`)\n }\n // Reuse the canonical JSON validator rather than accepting lossy Map/Date coercions.\n canonicalString(value)\n}\n\nfunction optionalTextOrJson(value: unknown, name: string): void {\n if (value !== null) textOrJson(value, name)\n}\n\n/** Validate named questions without a state, as a judge does before it has input. */\nexport function parseSystemOneQuestions(raw: unknown): SystemOneQuestions {\n return readQuestions(raw, false) as SystemOneQuestions\n}\n\nfunction readQuestions(raw: unknown, recorded: boolean): SystemOneRecordedQuestions {\n const questions = object(raw)\n if (!Object.keys(questions).length) throw new TypeError('At least one question is required')\n for (const [name, rawQuestion] of Object.entries(questions)) {\n const question = object(rawQuestion)\n if (question.instructions !== undefined) {\n optionalTextOrJson(question.instructions, `${name} instructions`)\n }\n if (question.type === 'noul') {\n if (question.criteria != null) {\n const criteria = object(question.criteria)\n if (Object.keys(criteria).some((key) => key !== 'true' && key !== 'false')) {\n throw new TypeError('Noul criteria must describe true and/or false')\n }\n for (const value of Object.values(criteria)) {\n if (value !== undefined) optionalTextOrJson(value, `${name} criteria`)\n }\n }\n } else if (question.type === 'score') {\n if (!Array.isArray(question.criteria) || question.criteria.length < 2) {\n throw new TypeError('Score criteria require at least two ordered entries')\n }\n for (const value of question.criteria) {\n if (recorded && value === null) continue\n textOrJson(value, `${name} score level`)\n }\n } else if (question.type === 'choice') {\n const criteria = object(question.criteria)\n if (!Object.keys(criteria).length) throw new TypeError('Choice criteria cannot be empty')\n for (const value of Object.values(criteria)) optionalTextOrJson(value, `${name} choice`)\n } else {\n throw new TypeError('Unsupported native question type')\n }\n }\n return raw as SystemOneRecordedQuestions\n}\n\nexport function parseSystemOneRequest(raw: unknown): SystemOneRequest {\n return readRequest(raw, false) as SystemOneRequest\n}\n\n/** Read immutable historical evidence without rewriting it or authorizing new inference.\n * Live transports must still call parseSystemOneRequest, even for re-execution of an old request. */\nexport function parseSystemOneRecordedRequest(raw: unknown): SystemOneRecordedRequest {\n canonicalString(raw)\n return readRequest(raw, true)\n}\n\nfunction readRequest(raw: unknown, recorded: boolean): SystemOneRecordedRequest {\n const request = object(raw)\n if (typeof request.model !== 'string' || !request.model.trim()) {\n throw new TypeError('Evaluation requires a model')\n }\n if (!recorded || request.state !== null) textOrJson(request.state, 'Evaluation state')\n readQuestions(request.questions, recorded)\n return raw as SystemOneRecordedRequest\n}\n\nexport function systemOneUsage(raw: unknown): SystemOneResult['usage'] {\n const usage = object(object(raw).usage)\n for (const key of ['input_tokens', 'output_tokens']) {\n if (!Number.isSafeInteger(usage[key]) || Number(usage[key]) < 0) {\n throw new SystemOneResponseError('Missing or invalid usage')\n }\n }\n return usage as unknown as SystemOneResult['usage']\n}\n\n/** The strict parser's allowance for floating-point error; provider rounding is normalized first. */\nexport const SYSTEM_ONE_PROBABILITY_TOLERANCE = 0.0001\n\nfunction levelsOf(question: SystemOneRecordedQuestion): string[] {\n return question.type === 'score'\n ? question.criteria.map((_, index) => String(index))\n : question.type === 'choice'\n ? Object.keys(question.criteria)\n : []\n}\n\n/** Σ level·p over score levels \"0\"..\"n-1\". */\nfunction expectation(levels: string[], probabilities: Record<string, unknown>): number {\n return levels.reduce((total, level) => total + Number(level) * Number(probabilities[level]), 0)\n}\n\nfunction probability(value: unknown): number {\n if (typeof value !== 'number' || !Number.isFinite(value) || value < 0 || value > 1) {\n throw new SystemOneResponseError('Invalid probability')\n }\n return value\n}\n\nfunction exactKeys(value: Record<string, unknown>, names: string[]): void {\n if (\n Object.keys(value).length !== names.length ||\n names.some((key) => !Object.hasOwn(value, key))\n ) {\n throw new SystemOneResponseError('Response keys differ from the request')\n }\n}\n\n/** Validate native evidence, not model alias policy or the caller's scoring rules. */\nexport function parseSystemOneResult<Q extends SystemOneRecordedQuestions>(\n raw: unknown,\n request: SystemOneRecordedRequest<Q>,\n): SystemOneResult<Q> {\n // Preserve extension metadata, rejecting values that change when persisted as JSON.\n canonicalString(raw)\n const response = object(raw)\n if (typeof response.model !== 'string' || !response.model.trim()) {\n throw new SystemOneResponseError('Missing served model')\n }\n const answers = object(response.answers)\n exactKeys(answers, Object.keys(request.questions))\n for (const [name, question] of Object.entries(request.questions)) {\n const answer = object(answers[name])\n if (answer.type !== question.type) throw new SystemOneResponseError('Wrong answer type')\n if (question.type === 'noul') {\n probability(answer.noul)\n continue\n }\n probability(answer.confidence)\n const levels = levelsOf(question)\n const probabilities = object(answer.probabilities)\n exactKeys(probabilities, levels)\n const sum = levels.reduce((total, level) => total + probability(probabilities[level]), 0)\n if (Math.abs(sum - 1) > SYSTEM_ONE_PROBABILITY_TOLERANCE) {\n throw new SystemOneResponseError('Invalid probability distribution')\n }\n if (question.type === 'score') {\n const legend = object(answer.legend)\n exactKeys(legend, levels)\n if (\n levels.some((level) => !isDeepStrictEqual(legend[level], question.criteria[Number(level)]))\n ) {\n throw new SystemOneResponseError('Provider changed the rubric')\n }\n if (\n typeof answer.score !== 'number' ||\n !Number.isFinite(answer.score) ||\n Math.abs(answer.score - expectation(levels, probabilities)) >\n SYSTEM_ONE_PROBABILITY_TOLERANCE\n ) {\n throw new SystemOneResponseError('Score differs from its distribution')\n }\n } else if (\n typeof answer.choice !== 'string' ||\n !Object.hasOwn(probabilities, answer.choice) ||\n levels.some(\n (level) =>\n Number(probabilities[level]) >\n Number(probabilities[String(answer.choice)]) + SYSTEM_ONE_PROBABILITY_TOLERANCE,\n )\n ) {\n throw new SystemOneResponseError('Choice is not a highest-probability option')\n }\n }\n systemOneUsage(raw)\n return raw as SystemOneResult<Q>\n}\n\n/**\n * How one provider reports results, measured from its responses. The caller that owns the\n * provider route supplies it; this module names no provider.\n */\nexport interface SystemOneResultProfile {\n /** Decimal places the provider rounds probabilities and scores to. Omit when it reports exact values. */\n readonly decimals?: number\n /**\n * `canonical`: the provider's `confidence` already follows `systemOneConfidence`.\n * `provider-defined`: it follows another definition, kept as `provider_confidence`.\n */\n readonly confidence: 'canonical' | 'provider-defined'\n}\n\n/**\n * The one confidence definition every route reports, TypeSafe's published formulas\n * (https://docs.typesafe.ai/confidence). Choice: (p_max − 1/n)/(1 − 1/n), and 1 for one option.\n * Score: 1 − Σ p_i·|i − m| / MAD_uniform, where m is the most likely level (the lowest on ties)\n * and MAD_uniform = (1/n)·Σ|i − (n − 1)/2|. Expects a normalized distribution; noul has none.\n */\nexport function systemOneConfidence(answer: {\n readonly type: 'choice' | 'score'\n readonly probabilities: Readonly<Record<string, number>>\n}): number {\n const labels = Object.keys(answer.probabilities)\n const n = labels.length\n const p = labels.map(\n (label, index) => answer.probabilities[answer.type === 'score' ? String(index) : label],\n )\n if (\n !n ||\n (answer.type === 'score' && n < 2) ||\n p.some(\n (value) => typeof value !== 'number' || !Number.isFinite(value) || value < 0 || value > 1,\n )\n ) {\n throw new TypeError('Confidence requires a probability for every option or score level')\n }\n const values = p as number[]\n const peak = Math.max(...values)\n let confidence: number\n if (answer.type === 'choice') {\n confidence = n === 1 ? 1 : (peak - 1 / n) / (1 - 1 / n)\n } else {\n const mode = values.indexOf(peak)\n const center = (n - 1) / 2\n const uniform = values.reduce((total, _, level) => total + Math.abs(level - center), 0) / n\n const spread = values.reduce((total, value, level) => total + value * Math.abs(level - mode), 0)\n confidence = 1 - spread / uniform\n }\n return Math.min(1, Math.max(0, confidence))\n}\n\nfunction readProfile(profile: SystemOneResultProfile): void {\n if (\n profile === null ||\n typeof profile !== 'object' ||\n (profile.decimals !== undefined &&\n (!Number.isSafeInteger(profile.decimals) || profile.decimals < 0 || profile.decimals > 15)) ||\n (profile.confidence !== 'canonical' && profile.confidence !== 'provider-defined')\n ) {\n throw new TypeError('Invalid System One result profile')\n }\n}\n\nfunction normalizeAnswer(\n answer: Record<string, unknown>,\n question: Exclude<SystemOneRecordedQuestion, { type: 'noul' }>,\n profile: SystemOneResultProfile,\n): Record<string, unknown> {\n const levels = levelsOf(question)\n const probabilities = answer.probabilities as Record<string, unknown>\n const keys = Object.keys(probabilities)\n if (\n keys.length !== levels.length ||\n levels.some((level) => {\n const value = probabilities[level]\n return (\n !Object.hasOwn(probabilities, level) ||\n typeof value !== 'number' ||\n !(value >= 0 && value <= 1)\n )\n })\n ) {\n // Leave shapes the strict parser refuses for it to name.\n return answer\n }\n const q = probabilities as Record<string, number>\n const sum = keys.reduce((total, key) => total + q[key]!, 0)\n const scored = question.type === 'score'\n const score = answer.score\n if (scored && (typeof score !== 'number' || !Number.isFinite(score))) return answer\n let next = answer\n const consistent =\n Math.abs(sum - 1) <= SYSTEM_ONE_PROBABILITY_TOLERANCE &&\n (!scored ||\n Math.abs((score as number) - expectation(levels, q)) <= SYSTEM_ONE_PROBABILITY_TOLERANCE)\n if (!consistent && profile.decimals !== undefined) {\n // Rounding to `decimals` moves each reported probability by at most one unit in the last\n // place, and the reported score by half a unit; anything larger is a provider defect.\n const unit = 10 ** -profile.decimals\n if (Math.abs(sum - 1) > (levels.length * unit) / 2) {\n throw new SystemOneResponseError('Distribution error exceeds declared rounding')\n }\n const levelTotal = (levels.length * (levels.length - 1)) / 2\n if (\n scored &&\n Math.abs((score as number) - expectation(levels, q)) > unit / 2 + unit * levelTotal\n ) {\n throw new SystemOneResponseError('Score error exceeds declared rounding')\n }\n const p =\n Math.abs(sum - 1) <= SYSTEM_ONE_PROBABILITY_TOLERANCE\n ? q\n : Object.fromEntries(keys.map((key) => [key, q[key]! / sum]))\n next = { ...answer, probabilities: p, ...(scored ? { score: expectation(levels, p) } : {}) }\n }\n // An answer that already carries provider_confidence was normalized before.\n if (\n profile.confidence === 'provider-defined' &&\n typeof answer.confidence === 'number' &&\n !Object.hasOwn(answer, 'provider_confidence')\n ) {\n next = {\n ...next,\n provider_confidence: answer.confidence,\n confidence: systemOneConfidence({\n type: question.type,\n probabilities: next.probabilities as Record<string, number>,\n }),\n }\n }\n return next\n}\n\n/**\n * Remove a provider's declared rounding and apply the one confidence definition, before\n * `parseSystemOneResult`. An answer that already passes the strict checks keeps its\n * probabilities and score. One that fails them only within the declared rounding is renormalized\n * and its score recomputed from that distribution; larger error throws. Noul answers never change.\n * Returns `raw` itself when nothing changes and never mutates it; shapes it cannot read are left\n * for the strict parser to refuse.\n */\nexport function normalizeSystemOneResult(\n raw: unknown,\n request: SystemOneRecordedRequest,\n profile: SystemOneResultProfile,\n): unknown {\n readProfile(profile)\n if (raw === null || typeof raw !== 'object' || Array.isArray(raw)) return raw\n const response = raw as Record<string, unknown>\n const original = response.answers\n if (original === null || typeof original !== 'object' || Array.isArray(original)) return raw\n const answers: Record<string, unknown> = { ...original }\n let changed = false\n for (const [name, question] of Object.entries(request.questions)) {\n const answer = answers[name]\n if (\n question.type === 'noul' ||\n answer === null ||\n typeof answer !== 'object' ||\n Array.isArray(answer) ||\n (answer as Record<string, unknown>).type !== question.type ||\n (answer as Record<string, unknown>).probabilities === null ||\n typeof (answer as Record<string, unknown>).probabilities !== 'object' ||\n Array.isArray((answer as Record<string, unknown>).probabilities)\n ) {\n continue\n }\n const next = normalizeAnswer(answer as Record<string, unknown>, question, profile)\n if (next !== answer) {\n answers[name] = next\n changed = true\n }\n }\n return changed ? { ...response, answers } : raw\n}\n"],"mappings":";;;AAoFA,IAAa,yBAAb,cAA4C,MAAM;CAChD,YAAY,SAAiB;EAC3B,MAAM,eAAe,SAAS;EAC9B,KAAK,OAAO;CACd;AACF;AAEA,SAAS,OAAO,OAAyC;CACvD,IAAI,UAAU,QAAQ,OAAO,UAAU,YAAY,MAAM,QAAQ,KAAK,GACpE,MAAM,IAAI,uBAAuB,oBAAoB;CAEvD,OAAO;AACT;AAIA,SAAS,WAAW,OAAgB,MAAoB;CACtD,IAAI,OAAO,UAAU,UAAU;CAC/B,IAAI,UAAU,QAAQ,OAAO,UAAU,UACrC,MAAM,IAAI,UAAU,GAAG,KAAK,qCAAqC;CAGnE,gBAAgB,KAAK;AACvB;AAEA,SAAS,mBAAmB,OAAgB,MAAoB;CAC9D,IAAI,UAAU,MAAM,WAAW,OAAO,IAAI;AAC5C;;AAGA,SAAgB,wBAAwB,KAAkC;CACxE,OAAO,cAAc,KAAK,KAAK;AACjC;AAEA,SAAS,cAAc,KAAc,UAA+C;CAClF,MAAM,YAAY,OAAO,GAAG;CAC5B,IAAI,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,QAAQ,MAAM,IAAI,UAAU,mCAAmC;CAC3F,KAAK,MAAM,CAAC,MAAM,gBAAgB,OAAO,QAAQ,SAAS,GAAG;EAC3D,MAAM,WAAW,OAAO,WAAW;EACnC,IAAI,SAAS,iBAAiB,KAAA,GAC5B,mBAAmB,SAAS,cAAc,GAAG,KAAK,cAAc;EA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qB,OAAO;EAC5B,YAAY,oBAAoB;GAC9B,MAAM,SAAS;GACf,eAAe,KAAK;EACtB,CAAC;CACH;CAEF,OAAO;AACT;;;;;;;;;AAUA,SAAgB,yBACd,KACA,SACA,SACS;CACT,YAAY,OAAO;CACnB,IAAI,QAAQ,QAAQ,OAAO,QAAQ,YAAY,MAAM,QAAQ,GAAG,GAAG,OAAO;CAC1E,MAAM,WAAW;CACjB,MAAM,WAAW,SAAS;CAC1B,IAAI,aAAa,QAAQ,OAAO,aAAa,YAAY,MAAM,QAAQ,QAAQ,GAAG,OAAO;CACzF,MAAM,UAAmC,EAAE,GAAG,SAAS;CACvD,IAAI,UAAU;CACd,KAAK,MAAM,CAAC,MAAM,aAAa,OAAO,QAAQ,QAAQ,SAAS,GAAG;EAChE,MAAM,SAAS,QAAQ;EACvB,IACE,SAAS,SAAS,UAClB,WAAW,QACX,OAAO,WAAW,YAClB,MAAM,QAAQ,MAAM,KACnB,OAAmC,SAAS,SAAS,QACrD,OAAmC,kBAAkB,QACtD,OAAQ,OAAmC,kBAAkB,YAC7D,MAAM,QAAS,OAAmC,aAAa,GAE/D;EAEF,MAAM,OAAO,gBAAgB,QAAmC,UAAU,OAAO;EACjF,IAAI,SAAS,QAAQ;GACnB,QAAQ,QAAQ;GAChB,UAAU;EACZ;CACF;CACA,OAAO,UAAU;EAAE,GAAG;EAAU;CAAQ,IAAI;AAC9C"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { i as AnalystFinding } from "./types-
|
|
2
|
-
import {
|
|
1
|
+
import { i as AnalystFinding } from "./types-DGImvHIr.js";
|
|
2
|
+
import { d as SystemOneRequest, p as SystemOneResult, s as SystemOneQuestions } from "./systemone-protocol-Bl2EI2KQ.js";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
//#region src/systemone-review.d.ts
|
|
5
5
|
declare const checkSchema: z.ZodObject<{
|
|
@@ -73,4 +73,4 @@ declare function systemOneReviewFindings<Q extends SystemOneQuestions>(review: P
|
|
|
73
73
|
}): AnalystFinding[];
|
|
74
74
|
//#endregion
|
|
75
75
|
export { SystemOneReviewReport as a, systemOneReviewFindings as c, SystemOneReviewInput as i, SystemOneReviewAssessment as n, assessSystemOneReview as o, SystemOneReviewCheck as r, prepareSystemOneReview as s, PreparedSystemOneReview as t };
|
|
76
|
-
//# sourceMappingURL=systemone-review-
|
|
76
|
+
//# sourceMappingURL=systemone-review-C8DRiT_-.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"systemone-review-
|
|
1
|
+
{"version":3,"file":"systemone-review-C8DRiT_-.d.ts","names":[],"sources":["../src/systemone-review.ts"],"mappings":";;;;cAcM,aAAW,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0Bb,EAAA,KAAA;;KAGQ,uBAAuB,EAAE,aAAa;UACjC,qBAAqB,UAAU,qBAAqB;EACnE;EACA,SAAS,iBAAiB;EAC1B,WAAW,WAAW,IAAI;;UAGX,wBAAwB,UAAU,qBAAqB,4BAC9D,qBAAqB;;EAE7B;;UAGe;EACf;EACA;EACA;;EAQA;EACA;EACA;EACA;EACA,OAAO;;UAGQ;EACf;EACA;EACA;EACA,aAAa;;;iBAWC,6BAA6B,UAAU,oBACrD,OAAO,qBAAqB,KAC3B,wBAAwB;;iBAuCX,sBAAsB,UAAU,oBAC9C,QAAQ,wBAAwB,IAChC,eACC;;iBAyDa,wBAAwB,UAAU,oBAChD,QAAQ,wBAAwB,IAChC,QAAQ,gBAAgB,IACxB;EAAW;EAAmB;IAC7B"}
|