@tangle-network/agent-eval 0.205.2 → 0.207.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 +11 -0
- package/dist/adapters/http.d.ts +1 -1
- package/dist/analyst/index.d.ts +1 -1
- package/dist/analyst/index.js +1 -1
- package/dist/{benchmark-command-DuDTN5ID.js → benchmark-command-DtP94cOB.js} +2 -2
- package/dist/{benchmark-command-DuDTN5ID.js.map → benchmark-command-DtP94cOB.js.map} +1 -1
- package/dist/benchmarks/index.d.ts +2 -2
- package/dist/campaign/index.d.ts +3 -3
- package/dist/campaign/index.js +2 -2
- package/dist/cli.js +3 -2
- package/dist/cli.js.map +1 -1
- package/dist/contract/index.d.ts +4 -4
- package/dist/{define-agent-eval-CKB6wyML.d.ts → define-agent-eval-B2YV-RDE.d.ts} +3 -3
- package/dist/{define-agent-eval-CKB6wyML.d.ts.map → define-agent-eval-B2YV-RDE.d.ts.map} +1 -1
- package/dist/{index-BRdZ0oJo.d.ts → index-CojsA_EE.d.ts} +2 -2
- package/dist/{index-BRdZ0oJo.d.ts.map → index-CojsA_EE.d.ts.map} +1 -1
- package/dist/{index-R8Xhod8e.d.ts → index-DVDiJIhi.d.ts} +3 -3
- package/dist/{index-R8Xhod8e.d.ts.map → index-DVDiJIhi.d.ts.map} +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/meta-eval/index.d.ts +69 -0
- package/dist/meta-eval/index.d.ts.map +1 -1
- package/dist/meta-eval/index.js +135 -1
- package/dist/meta-eval/index.js.map +1 -1
- package/dist/openapi.json +1 -1
- package/dist/rl.d.ts +12 -12
- package/dist/rl.d.ts.map +1 -1
- package/dist/rl.js +17 -17
- package/dist/rl.js.map +1 -1
- package/dist/search/index.d.ts +8 -2
- package/dist/search/index.d.ts.map +1 -1
- package/dist/search/index.js +1 -1
- package/dist/{search-kernel-DNpsHb8P.d.ts → search-kernel-CZ8KJQRw.d.ts} +6 -3
- package/dist/{search-kernel-DNpsHb8P.d.ts.map → search-kernel-CZ8KJQRw.d.ts.map} +1 -1
- package/dist/systemone-protocol-DKoi1NdK.d.ts +132 -0
- package/dist/systemone-protocol-DKoi1NdK.d.ts.map +1 -0
- package/dist/systemone-protocol.d.ts +2 -0
- package/dist/systemone-protocol.js +214 -0
- package/dist/systemone-protocol.js.map +1 -0
- package/dist/{jev-review-Cw06AKuF.d.ts → systemone-review-DGTKkLMG.d.ts} +16 -16
- package/dist/systemone-review-DGTKkLMG.d.ts.map +1 -0
- package/dist/{jev-review-DZEjDzlF.js → systemone-review-DTClwgmE.js} +11 -11
- package/dist/systemone-review-DTClwgmE.js.map +1 -0
- package/dist/systemone.d.ts +60 -0
- package/dist/systemone.d.ts.map +1 -0
- package/dist/{jev.js → systemone.js} +16 -16
- package/dist/systemone.js.map +1 -0
- package/dist/{tree-By7LtLUu.js → tree-CN8mlzUO.js} +11 -3
- package/dist/{tree-By7LtLUu.js.map → tree-CN8mlzUO.js.map} +1 -1
- package/docs/changes/jev-evidence-review.md +1 -1
- package/docs/changes/systemone-provider-neutral.md +36 -0
- package/docs/public-api.md +96 -70
- package/docs/search-ledger.md +9 -3
- package/docs/{jev-behavior-review.md → systemone-behavior-review.md} +17 -17
- package/docs/{jev-integrations.md → systemone-integrations.md} +4 -4
- package/docs/{jev-replay.md → systemone-replay.md} +6 -6
- package/docs/{jev.md → systemone.md} +96 -33
- package/package.json +9 -9
- package/dist/jev-protocol-BQLxwbqD.d.ts +0 -99
- package/dist/jev-protocol-BQLxwbqD.d.ts.map +0 -1
- package/dist/jev-protocol.d.ts +0 -2
- package/dist/jev-protocol.js +0 -114
- package/dist/jev-protocol.js.map +0 -1
- package/dist/jev-review-Cw06AKuF.d.ts.map +0 -1
- package/dist/jev-review-DZEjDzlF.js.map +0 -1
- package/dist/jev.d.ts +0 -60
- package/dist/jev.d.ts.map +0 -1
- package/dist/jev.js.map +0 -1
package/dist/search/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { A as SearchLedgerHash, C as SearchEdgeOperator, G as SearchSplit, H as SearchProposerKind, I as SearchNodeStatus, L as SearchOpenedEvent, T as SearchEstimateMethod, W as SearchSourceRef, i as SearchArtifactRef, j as SearchModelIdentity, l as SearchCandidateSurface, m as SearchClaim, t as NodeEstimate, y as SearchCloseReason } from "../search-ledger-types-p2xKfiDJ.js";
|
|
2
2
|
import { $ as SearchNode, it as SearchStateView } from "../types-ZUy5HGY5.js";
|
|
3
|
-
import {
|
|
3
|
+
import { L as SearchPolicy, M as SearchUnitExtension, at as OperatorYieldOptions, ct as operatorYield, dt as SampleSummary, et as EXPANSION_OPERATORS, ft as rankingSplit, it as OperatorYieldData, lt as LensResult, nt as MIN_OUTCOMES_FOR_WEIGHT, ot as OperatorYieldRow, p as SearchRunResult, pt as summarizeSamples, r as SearchArtifactCodec, rt as OperatorOutcomeCounts, s as SearchLane, st as OperatorYieldSignal, t as RunSearchOptions, tt as ExpansionOperator, ut as LensSignal, z as SearchPolicyView } from "../search-kernel-CZ8KJQRw.js";
|
|
4
4
|
import { AgentProfileResourceRef } from "@tangle-network/agent-interface";
|
|
5
5
|
//#region src/search/lenses/edit-credit.d.ts
|
|
6
6
|
/** Signal name a policy reads. */
|
|
@@ -1075,8 +1075,14 @@ interface TaskMatrixSpecialistRow {
|
|
|
1075
1075
|
interface TaskMatrixData {
|
|
1076
1076
|
split: 'train' | 'selection';
|
|
1077
1077
|
direction: 'maximize' | 'minimize';
|
|
1078
|
-
/** How `specialistGain` is computed. */
|
|
1078
|
+
/** How `specialistGain` is computed, including the node cap when sampled. */
|
|
1079
1079
|
method: string;
|
|
1080
|
+
/** Present only when nodes were sampled; absent for an unchanged full matrix. */
|
|
1081
|
+
sampling?: {
|
|
1082
|
+
nodesClustered: number;
|
|
1083
|
+
nodesTotal: number;
|
|
1084
|
+
cap: number;
|
|
1085
|
+
};
|
|
1080
1086
|
nodeIds: string[];
|
|
1081
1087
|
unitIds: string[];
|
|
1082
1088
|
nodeClusters: TaskMatrixCluster[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/search/lenses/edit-credit.ts","../../src/search/lenses/front.ts","../../src/search/lenses/geometry.ts","../../src/search/lenses/plateau.ts","../../src/search/lenses/landscape.ts","../../src/search/lenses/meta-search.ts","../../src/search/lenses/skill-manifold.ts","../../src/search/lenses/task-matrix.ts","../../src/search/lenses/tree.ts","../../src/search/nested-search.ts"],"mappings":";;;;;;qBA4Da;;qBA8BA,uBAAuB;UAKnB;;;;;;EAMf,aAAa,KAAK;;;EAGlB,QAAQ;;;EAGR;;KAGU;UAEK;EACf;EACA;EACA,UAAU;EACV;;EAEA;;UAGe;EACf;EACA;;;EAGA;;EAEA;;EAEA;;;;EAIA,YAAY;;EAEZ;;;EAGA;;EAEA;;;EAGA;EACA;;IAEE;;IAEA;;IAEA;;IAEA;;;;EAIF,QAAQ;EACR,SAAS;;;;EAIT;;UAGe;EACf;;EAEA;IACE;IACA;IACA;IACA;;;EAGF;EACA,QAAQ;;;;EAIR;;;EAGA;EACA;;EAEA;;EAEA;EACA;;;EAGA;;UAGe;;;;EAIf,UAAU,QAAQ;IAA2B;;EAC7C;IAAkB;IAAmB;MAAU;;;;EAE/C;EACA;EACA,QAAQ;;UAGO;EACf;EACA;EACA;EACA;EACA;EACA,UAAU;EACV,QAAQ;;EAER;EACA;;UAGe;EACf,OAAO;EACP;EACA;;IAEE;;IAEA;;IAEA,SAAS;;;;EAIX;IAAS;IAAe;;EACxB;IAAS;IAAe;IAAwB;;;EAEhD,OAAO;EACP,QAAQ,OAAO;;;EAGf,YAAY,OAAO;EACnB;IACE;;IAEA;;IAEA;IACA;IACA;;IAEA,OAAO;;EAET,iBAAiB;;;EAGjB;;IAEE;;;IAGA;IACA;;;;EAIF,SAAS;EACT;IACE,WAAW;IACX;IACA;IACA;IACA;;IAEA;;;;;UAMa,yBAAyB;;EAExC;;;EAGA;;KAGU,mBAAmB,W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;IACA,MAAM;IACN;IACA;IACA;IACA;IACA;IACA;;;EAGF;IACE,QAAQ;MAAQ;MAAc;;;IAE9B;IACA;;EAEF;IACE;IACA;;IAEA;IACA;IACA,OAAO;MAAQ;MAAc;MAAe;;IAC5C;;;EAGF;EACA;EACA,OAAO;EACP,OAAO;EACP,SAAS;IAAQ;IAAgB;IAAuB;;EACxD,WAAW;;;EAGX;EACA;;;;;;;wBA8Cc,cACd,OAAO,iBACP,qBACA,UAAS,uBACR,mBAAmB;;;;;;wBA0SN,iBACd,MAAM,mBAAmB,qBACxB;;;;;;;;;wBAg3Ba,kBACd,aAAa,kBACb;EAAW;IACV;;wBAsEa,oBAAoB,MAAM,mBAAmB;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../src/search/lenses/edit-credit.ts","../../src/search/lenses/front.ts","../../src/search/lenses/geometry.ts","../../src/search/lenses/plateau.ts","../../src/search/lenses/landscape.ts","../../src/search/lenses/meta-search.ts","../../src/search/lenses/skill-manifold.ts","../../src/search/lenses/task-matrix.ts","../../src/search/lenses/tree.ts","../../src/search/nested-search.ts"],"mappings":";;;;;;qBA4Da;;qBA8BA,uBAAuB;UAKnB;;;;;;EAMf,aAAa,KAAK;;;EAGlB,QAAQ;;;EAGR;;KAGU;UAEK;EACf;EACA;EACA,UAAU;EACV;;EAEA;;UAGe;EACf;EACA;;;EAGA;;EAEA;;EAEA;;;;EAIA,YAAY;;EAEZ;;;EAGA;;EAEA;;;EAGA;EACA;;IAEE;;IAEA;;IAEA;;IAEA;;;;EAIF,QAAQ;EACR,SAAS;;;;EAIT;;UAGe;EACf;;EAEA;IACE;IACA;IACA;IACA;;;EAGF;EACA,QAAQ;;;;EAIR;;;EAGA;EACA;;EAEA;;EAEA;EACA;;;EAGA;;UAGe;;;;EAIf,UAAU,QAAQ;IAA2B;;EAC7C;IAAkB;IAAmB;MAAU;;;;EAE/C;EACA;EACA,QAAQ;;UAGO;EACf;EACA;EACA;EACA;EACA;EACA,UA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;EACP;EACA;;wBAGc,KAAK,OAAO;EAC1B,MAAM;EACN;IAAU;IAAc;;;;;;KCId,0BAA0B,YAAY;;UAGjC,qBAAqB;EACpC,QAAQ;;EAER,aAAa;;;;EAIb;EACA;IAAQ;IAAgB;IAAgB,OAAO;IAAa;;EAC5D,QAAQ;;UAGO,uBAAuB,iBAC9B,KAAK,iBAAiB;;;EAG9B,QAAQ,oBAAoB;;;EAG5B,MAAM;;;EAGN,SAAS,OAAO,qBAAqB,WAAW,QAAQ;;;EAGxD,YAAY,OAAO,qBAAqB,WAAW,QAAQ;;;wBAI7C,eAAe,aAAa;;;;;wBAS5B,kBAAkB,YAAY,oBAAoB;;;;;;;wBA6B5C,gBAAgB,SACpC,SAAS,uBAAuB,WAC/B,QAAQ"}
|
package/dist/search/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { a as hashCanonical } from "../canonical-BsZVgBhW.js";
|
|
2
2
|
import { _ as rankingSplit, h as operatorYield, m as MIN_OUTCOMES_FOR_WEIGHT, n as runSearch, p as EXPANSION_OPERATORS, v as summarizeSamples } from "../search-kernel-mzeNuzr8.js";
|
|
3
|
-
import { A as editCreditText, C as draftOnPlateau, D as EDIT_CREDIT_ESTIMATOR, E as front, O as EDIT_CREDIT_SIGNAL, S as vectorEmbedding, T as screenedNodes, _ as lineageEdits, a as skillCalibration, b as surfaceDigestEdits, c as META_SEARCH_SIGNAL, d as objectiveKey, f as renderMetaSearchText, g as lineEditDistance, h as landscape, i as nextUnitExtension, k as editCredit, l as metaSearch, m as formatLandscape, n as taskMatrix, o as skillManifold, p as searchPolicyGenome, r as formatSkillManifold, s as META_SEARCH_SCORE_SOURCE, t as tree, u as metaSearchScore, v as nearestNeighbours, w as searchPlateau, x as surfaceTextEdits, y as profileTextLines } from "../tree-
|
|
3
|
+
import { A as editCreditText, C as draftOnPlateau, D as EDIT_CREDIT_ESTIMATOR, E as front, O as EDIT_CREDIT_SIGNAL, S as vectorEmbedding, T as screenedNodes, _ as lineageEdits, a as skillCalibration, b as surfaceDigestEdits, c as META_SEARCH_SIGNAL, d as objectiveKey, f as renderMetaSearchText, g as lineEditDistance, h as landscape, i as nextUnitExtension, k as editCredit, l as metaSearch, m as formatLandscape, n as taskMatrix, o as skillManifold, p as searchPolicyGenome, r as formatSkillManifold, s as META_SEARCH_SCORE_SOURCE, t as tree, u as metaSearchScore, v as nearestNeighbours, w as searchPlateau, x as surfaceTextEdits, y as profileTextLines } from "../tree-CN8mlzUO.js";
|
|
4
4
|
//#region src/search/nested-search.ts
|
|
5
5
|
/** The deterministic id of the inner search one outer cell attempt runs. */
|
|
6
6
|
function nestedSearchId(containment) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { o as CostLedger } from "./cost-ledger-DbQdN3nO.js";
|
|
2
2
|
import { a as RunRecord } from "./run-record-DF-fuu31.js";
|
|
3
|
-
import { A as SearchLedgerHash, C as SearchEdgeOperator, E as SearchExecutionIdentity, G as SearchSplit, H as SearchProposerKind, I as SearchNodeStatus, L as SearchOpenedEvent, N as SearchNodeDecision, O as SearchLedgerEntry, P as SearchNodeRef, Q as SearchTaskOutcome, R as SearchOperationKind, S as SearchEdgeAttribution, U as SearchReservation, V as SearchProposer, W as SearchSourceRef, Y as SearchSurfaceEvidence, Z as SearchTask, _ as SearchClaimPower, a as SearchAttemptAccounting, et as SearchTraceRef, i as SearchArtifactRef, j as SearchModelIdentity, k as SearchLedgerEvent, l as SearchCandidateSurface, m as SearchClaim, nt as EvaluationClaim, o as SearchAudit, p as SearchCellStage, t as NodeEstimate, tt as SearchUnknown, y as SearchCloseReason, z as SearchOperationRecordedEvent } from "./search-ledger-types-p2xKfiDJ.js";
|
|
3
|
+
import { A as SearchLedgerHash, C as SearchEdgeOperator, E as SearchExecutionIdentity, G as SearchSplit, H as SearchProposerKind, I as SearchNodeStatus, L as SearchOpenedEvent, N as SearchNodeDecision, O as SearchLedgerEntry, P as SearchNodeRef, Q as SearchTaskOutcome, R as SearchOperationKind, S as SearchEdgeAttribution, T as SearchEstimateMethod, U as SearchReservation, V as SearchProposer, W as SearchSourceRef, Y as SearchSurfaceEvidence, Z as SearchTask, _ as SearchClaimPower, a as SearchAttemptAccounting, et as SearchTraceRef, i as SearchArtifactRef, j as SearchModelIdentity, k as SearchLedgerEvent, l as SearchCandidateSurface, m as SearchClaim, nt as EvaluationClaim, o as SearchAudit, p as SearchCellStage, t as NodeEstimate, tt as SearchUnknown, y as SearchCloseReason, z as SearchOperationRecordedEvent } from "./search-ledger-types-p2xKfiDJ.js";
|
|
4
4
|
import { b as LedgerTrustedHeadRemoval, f as LedgerLineContext, h as LedgerTextStore, y as LedgerTrustedHead } from "./index-Bj96W0jZ.js";
|
|
5
5
|
import { $ as SearchNode, at as SearchUnitScore, it as SearchStateView, j as MutableSurface, tt as SearchScoredCell } from "./types-ZUy5HGY5.js";
|
|
6
6
|
//#region src/campaign/storage.d.ts
|
|
@@ -509,6 +509,9 @@ declare function operatorYield(state: SearchStateView, options?: OperatorYieldOp
|
|
|
509
509
|
//#region src/campaign/estimate-node.d.ts
|
|
510
510
|
/** The estimator every `NodeEstimate` names. */
|
|
511
511
|
declare const SEARCH_ESTIMATOR: SearchSourceRef;
|
|
512
|
+
/** The method a paired sample of `pairs` units supports: the one staging
|
|
513
|
+
* every `NodeEstimate` and every search lens uses. */
|
|
514
|
+
declare function searchEstimateMethod(pairs: number): SearchEstimateMethod;
|
|
512
515
|
interface EstimateNodeCellsInput {
|
|
513
516
|
nodeId: string;
|
|
514
517
|
against: string;
|
|
@@ -1186,5 +1189,5 @@ declare function searchDivergence(state: SearchStateView, nodeId: string): {
|
|
|
1186
1189
|
reason: string;
|
|
1187
1190
|
} | null;
|
|
1188
1191
|
//#endregion
|
|
1189
|
-
export {
|
|
1190
|
-
//# sourceMappingURL=search-kernel-
|
|
1192
|
+
export { searchPosterior as $, inMemoryCampaignStorage as $t, SearchCellPlan as A, SearchHistoryCoverage as At, aide as B, verifySearchHistoryReceipt as Bt, decideSearchClaim as C, developmentClaim as Ct, AshaOptions as D, CreateSearchHistoryReceiptInput as Dt, verifySearchClaim as E, surfaceNode as Et, AideOptions as F, assertCompleteSearchHistory as Ft, EstimateNodeCellsInput as G, SearchLedgerTrustedHeadMode as Gt, crowdedFrontierParent as H, OpenSearchLedgerOptions as Ht, SearchExpansion as I, assertSearchHistoryMatchesState as It, SearchPosterior as J, replaySearchLedgerText as Jt, NodePosterior as K, openSearchLedger as Kt, SearchPolicy as L, createSearchHistoryReceipt as Lt, SearchUnitExtension as M, SearchHistoryPolicy as Mt, asha as N, SearchHistoryReceipt as Nt, SearchAllocationView as O, SearchHistoryAdmissionOptions as Ot, uniform as P, SearchHistoryRequiredError as Pt, searchEstimateMethod as Q, fsCampaignStorage as Qt, SearchPolicyNode as R, searchHistoryCoverageRow as Rt, SearchClaimVerification as S, SettleSearchCellInput as St, searchClaimReserveUsd as T, surfaceDiff as Tt, incumbent as U, SearchLedger as Ut, beam as V, FileSearchLedger as Vt, incumbentWithOperatorBandit as W, SearchLedgerAppendResult as Wt, estimateNodeFromCells as X, CampaignStorage as Xt, estimateNode as Y, validateSearchLedgerEvent as Yt, searchCellSetDigest as Z, createRunCostLedger as Zt, searchPolicyView as _, SearchLedgerBinding as _t, SearchCellWork as a, OperatorYieldOptions as at, SearchClaimDecision as b, SearchRecorderOptions as bt, SearchProposalBlob as c, operatorYield as ct, SearchProposedChild as d, SampleSummary as dt, EXPANSION_OPERATORS as et, SearchProposerPort as f, rankingSplit as ft, searchExpansionIndex as g, RegisterSearchNodeInput as gt, searchDivergence as h, RecordSearchEdgeInput as ht, SearchCellResult as i, OperatorYieldData as it, SearchRungDecision as j, SearchHistoryCoverageRow as jt, SearchAllocator as k, SearchHistoryAuditSummary as kt, SearchProposalRequest as l, LensResult as lt, runSearch as m, AllocateSearchCellInput as mt, SEARCH_KERNEL_SOURCE as n, MIN_OUTCOMES_FOR_WEIGHT as nt, SearchExecutor as o, OperatorYieldRow as ot, SearchRunResult as p, summarizeSamples as pt, SEARCH_ESTIMATOR as q, parseSearchLedgerLine as qt, SearchArtifactCodec as r, OperatorOutcomeCounts as rt, SearchLane as s, OperatorYieldSignal as st, RunSearchOptions as t, ExpansionOperator as tt, SearchProposalResult as u, LensSignal as ut, PlanSearchClaimInput as v, SearchOpening as vt, planSearchClaim as w, searchEdgeId as wt, SearchClaimPlan as x, SearchRunIdentity as xt, SEARCH_CLAIM_RULE as y, SearchRecorder as yt, SearchPolicyView as z, verifySearchHistoryArtifact as zt };
|
|
1193
|
+
//# sourceMappingURL=search-kernel-CZ8KJQRw.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"search-kernel-
|
|
1
|
+
{"version":3,"file":"search-kernel-CZ8KJQRw.d.ts","names":[],"sources":["../src/campaign/storage.ts","../src/campaign/search-ledger.ts","../src/campaign/search-history-receipt.ts","../src/campaign/search-ledger-recording.ts","../src/search/lenses/shared.ts","../src/search/lenses/operator-yield.ts","../src/campaign/estimate-node.ts","../src/campaign/search-policy.ts","../src/campaign/allocation.ts","../src/campaign/search-claim.ts","../src/campaign/search-kernel.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;UAoBiB;;;;WAIN;;EAET,UAAU;;EAEV,OAAO;;EAEP,KAAK;;EAEL,MAAM,cAAc,kBAAkB;;;EAGtC,OAAO,cAAc,iBAAiB;;;;;;;;;iBAUxB,qBAAqB;;;;iBA2CrB,2BAA2B;;iBAoC3B,oBAAoB;EAClC,SAAS;EACT;EACA;;EAEA;IACE;;;;;iBC2ZY,0BAA0B,iBAAiB;;;;;;;;;;;;;;KAqB/C;UAEK;EACf;EACA;EACA,cAAc;;;;;;;EAOd,QAAQ;;UAGO;EACf,OAAO;;EAEP;EACA,OAAO;;UAGQ;WACN;WACA;;WAEA;EACT,OAAO,OAAO,oBAAoB,QAAQ;;EAE1C,SAAS,QAAQ;;EAEjB,eAAe,QAAQ;;EAEvB,kBAAkB,QAAQ;;;EAG1B,oBAAoB,QAAQ;;;;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c,UAAU;;EACrC,UAAU;IACR,MAAM;IACN,OAAO,MAAM,oBAAoB;IACjC;IACA;IACA,aAAa,SAAS;IACtB;;;;;;;;;;;iBA2mCY,iBACd,OAAO,iBACP;EACE;EACA;EACA;EACA;IAED;;;;;;;;iBA4Fa,iBACd,OAAO,iBACP;EACG,OAAO;EAAc"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
//#region src/systemone-protocol.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* The System One wire contract (TypeSafe-originated, https://api.typesafe.ai/openapi.json; also
|
|
4
|
+
* served by Cloudflare Workers AI and Perplexity). This module names no endpoint, credential or
|
|
5
|
+
* model; callers can use TypeSafe's SDK builders unchanged.
|
|
6
|
+
*/
|
|
7
|
+
type SystemOneJson = string | number | boolean | null | SystemOneJson[] | {
|
|
8
|
+
[key: string]: SystemOneJson;
|
|
9
|
+
};
|
|
10
|
+
/** What the TypeSafe route accepts as `state` and as a score level: text or JSON, never null. */
|
|
11
|
+
type SystemOneState = string | {
|
|
12
|
+
[key: string]: SystemOneJson;
|
|
13
|
+
} | SystemOneJson[];
|
|
14
|
+
/** Instructions and choice or noul descriptions, which TypeSafe also accepts as null. */
|
|
15
|
+
type SystemOneDescription = SystemOneState | null;
|
|
16
|
+
type SystemOneScoreCriteria = readonly [SystemOneState, SystemOneState, ...SystemOneState[]];
|
|
17
|
+
type SystemOneQuestion = {
|
|
18
|
+
type: 'noul';
|
|
19
|
+
instructions?: SystemOneDescription;
|
|
20
|
+
criteria?: {
|
|
21
|
+
true?: SystemOneDescription;
|
|
22
|
+
false?: SystemOneDescription;
|
|
23
|
+
} | null;
|
|
24
|
+
} | {
|
|
25
|
+
type: 'score';
|
|
26
|
+
instructions?: SystemOneDescription;
|
|
27
|
+
criteria: SystemOneScoreCriteria;
|
|
28
|
+
} | {
|
|
29
|
+
type: 'choice';
|
|
30
|
+
instructions?: SystemOneDescription;
|
|
31
|
+
criteria: Record<string, SystemOneDescription>;
|
|
32
|
+
};
|
|
33
|
+
type SystemOneQuestions = Record<string, SystemOneQuestion>;
|
|
34
|
+
interface SystemOneRequest<Q extends SystemOneQuestions = SystemOneQuestions> {
|
|
35
|
+
model: string;
|
|
36
|
+
state: SystemOneState;
|
|
37
|
+
questions: Q;
|
|
38
|
+
}
|
|
39
|
+
/** Historical Tangle observations accepted null state and score levels. Not a live request. */
|
|
40
|
+
type SystemOneRecordedQuestion = Exclude<SystemOneQuestion, {
|
|
41
|
+
type: 'score';
|
|
42
|
+
}> | {
|
|
43
|
+
type: 'score';
|
|
44
|
+
instructions?: SystemOneDescription;
|
|
45
|
+
criteria: readonly [SystemOneDescription, SystemOneDescription, ...SystemOneDescription[]];
|
|
46
|
+
};
|
|
47
|
+
type SystemOneRecordedQuestions = Record<string, SystemOneRecordedQuestion>;
|
|
48
|
+
interface SystemOneRecordedRequest<Q extends SystemOneRecordedQuestions = SystemOneRecordedQuestions> {
|
|
49
|
+
model: string;
|
|
50
|
+
state: SystemOneDescription;
|
|
51
|
+
questions: Q;
|
|
52
|
+
}
|
|
53
|
+
type ScoreKeys<T extends readonly SystemOneDescription[]> = number extends T['length'] ? number : Extract<keyof T, `${number}`>;
|
|
54
|
+
type SystemOneAnswerFor<Q extends SystemOneRecordedQuestion> = Q extends {
|
|
55
|
+
type: 'noul';
|
|
56
|
+
} ? {
|
|
57
|
+
readonly type: 'noul';
|
|
58
|
+
readonly noul: number;
|
|
59
|
+
} : Q extends {
|
|
60
|
+
type: 'score';
|
|
61
|
+
criteria: infer C extends readonly SystemOneDescription[];
|
|
62
|
+
} ? {
|
|
63
|
+
readonly type: 'score';
|
|
64
|
+
readonly score: number;
|
|
65
|
+
readonly confidence: number;
|
|
66
|
+
readonly legend: { readonly [K in ScoreKeys<C>]: C[K]; };
|
|
67
|
+
readonly probabilities: { readonly [K in ScoreKeys<C>]: number; };
|
|
68
|
+
} : Q extends {
|
|
69
|
+
type: 'choice';
|
|
70
|
+
criteria: infer C;
|
|
71
|
+
} ? {
|
|
72
|
+
readonly type: 'choice';
|
|
73
|
+
readonly choice: keyof C & string;
|
|
74
|
+
readonly confidence: number;
|
|
75
|
+
readonly probabilities: { readonly [K in keyof C]: number; };
|
|
76
|
+
} : never;
|
|
77
|
+
type SystemOneAnswer = SystemOneAnswerFor<SystemOneQuestion>;
|
|
78
|
+
interface SystemOneResult<Q extends SystemOneRecordedQuestions = SystemOneQuestions> {
|
|
79
|
+
readonly model: string;
|
|
80
|
+
readonly answers: { readonly [K in keyof Q]: SystemOneAnswerFor<Q[K]>; };
|
|
81
|
+
readonly usage: {
|
|
82
|
+
readonly input_tokens: number;
|
|
83
|
+
readonly output_tokens: number;
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
declare class SystemOneResponseError extends Error {
|
|
87
|
+
constructor(message: string);
|
|
88
|
+
}
|
|
89
|
+
/** Validate named questions without a state, as a judge does before it has input. */
|
|
90
|
+
declare function parseSystemOneQuestions(raw: unknown): SystemOneQuestions;
|
|
91
|
+
declare function parseSystemOneRequest(raw: unknown): SystemOneRequest;
|
|
92
|
+
/** Read immutable historical evidence without rewriting it or authorizing new inference.
|
|
93
|
+
* Live transports must still call parseSystemOneRequest, even for re-execution of an old request. */
|
|
94
|
+
declare function parseSystemOneRecordedRequest(raw: unknown): SystemOneRecordedRequest;
|
|
95
|
+
declare function systemOneUsage(raw: unknown): SystemOneResult['usage'];
|
|
96
|
+
/** Validate native evidence, not model alias policy or the caller's scoring rules. */
|
|
97
|
+
declare function parseSystemOneResult<Q extends SystemOneRecordedQuestions>(raw: unknown, request: SystemOneRecordedRequest<Q>): SystemOneResult<Q>;
|
|
98
|
+
/**
|
|
99
|
+
* How one provider reports results, measured from its responses. The caller that owns the
|
|
100
|
+
* provider route supplies it; this module names no provider.
|
|
101
|
+
*/
|
|
102
|
+
interface SystemOneResultProfile {
|
|
103
|
+
/** Decimal places the provider rounds probabilities and scores to. Omit when it reports exact values. */
|
|
104
|
+
readonly decimals?: number;
|
|
105
|
+
/**
|
|
106
|
+
* `canonical`: the provider's `confidence` already follows `systemOneConfidence`.
|
|
107
|
+
* `provider-defined`: it follows another definition, kept as `provider_confidence`.
|
|
108
|
+
*/
|
|
109
|
+
readonly confidence: 'canonical' | 'provider-defined';
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The one confidence definition every route reports, TypeSafe's published formulas
|
|
113
|
+
* (https://docs.typesafe.ai/confidence). Choice: (p_max − 1/n)/(1 − 1/n), and 1 for one option.
|
|
114
|
+
* Score: 1 − Σ p_i·|i − m| / MAD_uniform, where m is the most likely level (the lowest on ties)
|
|
115
|
+
* and MAD_uniform = (1/n)·Σ|i − (n − 1)/2|. Expects a normalized distribution; noul has none.
|
|
116
|
+
*/
|
|
117
|
+
declare function systemOneConfidence(answer: {
|
|
118
|
+
readonly type: 'choice' | 'score';
|
|
119
|
+
readonly probabilities: Readonly<Record<string, number>>;
|
|
120
|
+
}): number;
|
|
121
|
+
/**
|
|
122
|
+
* Remove a provider's declared rounding and apply the one confidence definition, before
|
|
123
|
+
* `parseSystemOneResult`. An answer that already passes the strict checks keeps its
|
|
124
|
+
* probabilities and score. One that fails them only within the declared rounding is renormalized
|
|
125
|
+
* and its score recomputed from that distribution; larger error throws. Noul answers never change.
|
|
126
|
+
* Returns `raw` itself when nothing changes and never mutates it; shapes it cannot read are left
|
|
127
|
+
* for the strict parser to refuse.
|
|
128
|
+
*/
|
|
129
|
+
declare function normalizeSystemOneResult(raw: unknown, request: SystemOneRecordedRequest, profile: SystemOneResultProfile): unknown;
|
|
130
|
+
//#endregion
|
|
131
|
+
export { systemOneUsage as S, parseSystemOneQuestions as _, SystemOneQuestion as a, parseSystemOneResult as b, SystemOneRecordedQuestions as c, SystemOneResponseError as d, SystemOneResult as f, normalizeSystemOneResult as g, SystemOneState as h, SystemOneJson as i, SystemOneRecordedRequest as l, SystemOneScoreCriteria as m, SystemOneAnswerFor as n, SystemOneQuestions as o, SystemOneResultProfile as p, SystemOneDescription as r, SystemOneRecordedQuestion as s, SystemOneAnswer as t, SystemOneRequest as u, parseSystemOneRecordedRequest as v, systemOneConfidence as x, parseSystemOneRequest as y };
|
|
132
|
+
//# sourceMappingURL=systemone-protocol-DKoi1NdK.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"systemone-protocol-DKoi1NdK.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;;iBA2C9B,qBAAqB,UAAU,4BAC7C,cACA,SAAS,yBAAyB,KACjC,gBAAgB;;;;;UA0DF;;WAEN;;;;;WAKA;;;;;;;;iBASK,oBAAoB;WACzB;WACA,eAAe,SAAS;;;;;;;;;;iBAwHnB,yBACd,cACA,SAAS,0BACT,SAAS"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { S as systemOneUsage, _ as parseSystemOneQuestions, a as SystemOneQuestion, b as parseSystemOneResult, c as SystemOneRecordedQuestions, d as SystemOneResponseError, f as SystemOneResult, g as normalizeSystemOneResult, h as SystemOneState, i as SystemOneJson, l as SystemOneRecordedRequest, m as SystemOneScoreCriteria, n as SystemOneAnswerFor, o as SystemOneQuestions, p as SystemOneResultProfile, r as SystemOneDescription, s as SystemOneRecordedQuestion, t as SystemOneAnswer, u as SystemOneRequest, v as parseSystemOneRecordedRequest, x as systemOneConfidence, y as parseSystemOneRequest } from "./systemone-protocol-DKoi1NdK.js";
|
|
2
|
+
export { SystemOneAnswer, SystemOneAnswerFor, SystemOneDescription, SystemOneJson, SystemOneQuestion, SystemOneQuestions, SystemOneRecordedQuestion, SystemOneRecordedQuestions, SystemOneRecordedRequest, SystemOneRequest, SystemOneResponseError, SystemOneResult, SystemOneResultProfile, SystemOneScoreCriteria, SystemOneState, normalizeSystemOneResult, parseSystemOneQuestions, parseSystemOneRecordedRequest, parseSystemOneRequest, parseSystemOneResult, systemOneConfidence, systemOneUsage };
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import { r as canonicalString } from "./canonical-BsZVgBhW.js";
|
|
2
|
+
import { isDeepStrictEqual } from "node:util";
|
|
3
|
+
//#region src/systemone-protocol.ts
|
|
4
|
+
var SystemOneResponseError = class extends Error {
|
|
5
|
+
constructor(message) {
|
|
6
|
+
super(`System One: ${message}`);
|
|
7
|
+
this.name = "SystemOneResponseError";
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
function object(value) {
|
|
11
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) throw new SystemOneResponseError("Expected an object");
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
function textOrJson(value, name) {
|
|
15
|
+
if (typeof value === "string") return;
|
|
16
|
+
if (value === null || typeof value !== "object") throw new TypeError(`${name} must be text or a JSON object/array`);
|
|
17
|
+
canonicalString(value);
|
|
18
|
+
}
|
|
19
|
+
function optionalTextOrJson(value, name) {
|
|
20
|
+
if (value !== null) textOrJson(value, name);
|
|
21
|
+
}
|
|
22
|
+
/** Validate named questions without a state, as a judge does before it has input. */
|
|
23
|
+
function parseSystemOneQuestions(raw) {
|
|
24
|
+
return readQuestions(raw, false);
|
|
25
|
+
}
|
|
26
|
+
function readQuestions(raw, recorded) {
|
|
27
|
+
const questions = object(raw);
|
|
28
|
+
if (!Object.keys(questions).length) throw new TypeError("At least one question is required");
|
|
29
|
+
for (const [name, rawQuestion] of Object.entries(questions)) {
|
|
30
|
+
const question = object(rawQuestion);
|
|
31
|
+
if (question.instructions !== void 0) optionalTextOrJson(question.instructions, `${name} instructions`);
|
|
32
|
+
if (question.type === "noul") {
|
|
33
|
+
if (question.criteria != null) {
|
|
34
|
+
const criteria = object(question.criteria);
|
|
35
|
+
if (Object.keys(criteria).some((key) => key !== "true" && key !== "false")) throw new TypeError("Noul criteria must describe true and/or false");
|
|
36
|
+
for (const value of Object.values(criteria)) if (value !== void 0) optionalTextOrJson(value, `${name} criteria`);
|
|
37
|
+
}
|
|
38
|
+
} else if (question.type === "score") {
|
|
39
|
+
if (!Array.isArray(question.criteria) || question.criteria.length < 2) throw new TypeError("Score criteria require at least two ordered entries");
|
|
40
|
+
for (const value of question.criteria) {
|
|
41
|
+
if (recorded && value === null) continue;
|
|
42
|
+
textOrJson(value, `${name} score level`);
|
|
43
|
+
}
|
|
44
|
+
} else if (question.type === "choice") {
|
|
45
|
+
const criteria = object(question.criteria);
|
|
46
|
+
if (!Object.keys(criteria).length) throw new TypeError("Choice criteria cannot be empty");
|
|
47
|
+
for (const value of Object.values(criteria)) optionalTextOrJson(value, `${name} choice`);
|
|
48
|
+
} else throw new TypeError("Unsupported native question type");
|
|
49
|
+
}
|
|
50
|
+
return raw;
|
|
51
|
+
}
|
|
52
|
+
function parseSystemOneRequest(raw) {
|
|
53
|
+
return readRequest(raw, false);
|
|
54
|
+
}
|
|
55
|
+
/** Read immutable historical evidence without rewriting it or authorizing new inference.
|
|
56
|
+
* Live transports must still call parseSystemOneRequest, even for re-execution of an old request. */
|
|
57
|
+
function parseSystemOneRecordedRequest(raw) {
|
|
58
|
+
canonicalString(raw);
|
|
59
|
+
return readRequest(raw, true);
|
|
60
|
+
}
|
|
61
|
+
function readRequest(raw, recorded) {
|
|
62
|
+
const request = object(raw);
|
|
63
|
+
if (typeof request.model !== "string" || !request.model.trim()) throw new TypeError("Evaluation requires a model");
|
|
64
|
+
if (!recorded || request.state !== null) textOrJson(request.state, "Evaluation state");
|
|
65
|
+
readQuestions(request.questions, recorded);
|
|
66
|
+
return raw;
|
|
67
|
+
}
|
|
68
|
+
function systemOneUsage(raw) {
|
|
69
|
+
const usage = object(object(raw).usage);
|
|
70
|
+
for (const key of ["input_tokens", "output_tokens"]) if (!Number.isSafeInteger(usage[key]) || Number(usage[key]) < 0) throw new SystemOneResponseError("Missing or invalid usage");
|
|
71
|
+
return usage;
|
|
72
|
+
}
|
|
73
|
+
/** The strict parser's allowance for floating-point error; provider rounding is normalized first. */
|
|
74
|
+
const TOLERANCE = 1e-4;
|
|
75
|
+
function levelsOf(question) {
|
|
76
|
+
return question.type === "score" ? question.criteria.map((_, index) => String(index)) : question.type === "choice" ? Object.keys(question.criteria) : [];
|
|
77
|
+
}
|
|
78
|
+
/** Σ level·p over score levels "0".."n-1". */
|
|
79
|
+
function expectation(levels, probabilities) {
|
|
80
|
+
return levels.reduce((total, level) => total + Number(level) * Number(probabilities[level]), 0);
|
|
81
|
+
}
|
|
82
|
+
function probability(value) {
|
|
83
|
+
if (typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1) throw new SystemOneResponseError("Invalid probability");
|
|
84
|
+
return value;
|
|
85
|
+
}
|
|
86
|
+
function exactKeys(value, names) {
|
|
87
|
+
if (Object.keys(value).length !== names.length || names.some((key) => !Object.hasOwn(value, key))) throw new SystemOneResponseError("Response keys differ from the request");
|
|
88
|
+
}
|
|
89
|
+
/** Validate native evidence, not model alias policy or the caller's scoring rules. */
|
|
90
|
+
function parseSystemOneResult(raw, request) {
|
|
91
|
+
canonicalString(raw);
|
|
92
|
+
const response = object(raw);
|
|
93
|
+
if (typeof response.model !== "string" || !response.model.trim()) throw new SystemOneResponseError("Missing served model");
|
|
94
|
+
const answers = object(response.answers);
|
|
95
|
+
exactKeys(answers, Object.keys(request.questions));
|
|
96
|
+
for (const [name, question] of Object.entries(request.questions)) {
|
|
97
|
+
const answer = object(answers[name]);
|
|
98
|
+
if (answer.type !== question.type) throw new SystemOneResponseError("Wrong answer type");
|
|
99
|
+
if (question.type === "noul") {
|
|
100
|
+
probability(answer.noul);
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
probability(answer.confidence);
|
|
104
|
+
const levels = levelsOf(question);
|
|
105
|
+
const probabilities = object(answer.probabilities);
|
|
106
|
+
exactKeys(probabilities, levels);
|
|
107
|
+
const sum = levels.reduce((total, level) => total + probability(probabilities[level]), 0);
|
|
108
|
+
if (Math.abs(sum - 1) > TOLERANCE) throw new SystemOneResponseError("Invalid probability distribution");
|
|
109
|
+
if (question.type === "score") {
|
|
110
|
+
const legend = object(answer.legend);
|
|
111
|
+
exactKeys(legend, levels);
|
|
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)) > TOLERANCE) 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)]) + TOLERANCE)) throw new SystemOneResponseError("Choice is not a highest-probability option");
|
|
115
|
+
}
|
|
116
|
+
systemOneUsage(raw);
|
|
117
|
+
return raw;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The one confidence definition every route reports, TypeSafe's published formulas
|
|
121
|
+
* (https://docs.typesafe.ai/confidence). Choice: (p_max − 1/n)/(1 − 1/n), and 1 for one option.
|
|
122
|
+
* Score: 1 − Σ p_i·|i − m| / MAD_uniform, where m is the most likely level (the lowest on ties)
|
|
123
|
+
* and MAD_uniform = (1/n)·Σ|i − (n − 1)/2|. Expects a normalized distribution; noul has none.
|
|
124
|
+
*/
|
|
125
|
+
function systemOneConfidence(answer) {
|
|
126
|
+
const labels = Object.keys(answer.probabilities);
|
|
127
|
+
const n = labels.length;
|
|
128
|
+
const p = labels.map((label, index) => answer.probabilities[answer.type === "score" ? String(index) : label]);
|
|
129
|
+
if (!n || answer.type === "score" && n < 2 || p.some((value) => typeof value !== "number" || !Number.isFinite(value) || value < 0 || value > 1)) throw new TypeError("Confidence requires a probability for every option or score level");
|
|
130
|
+
const values = p;
|
|
131
|
+
const peak = Math.max(...values);
|
|
132
|
+
let confidence;
|
|
133
|
+
if (answer.type === "choice") confidence = n === 1 ? 1 : (peak - 1 / n) / (1 - 1 / n);
|
|
134
|
+
else {
|
|
135
|
+
const mode = values.indexOf(peak);
|
|
136
|
+
const center = (n - 1) / 2;
|
|
137
|
+
const uniform = values.reduce((total, _, level) => total + Math.abs(level - center), 0) / n;
|
|
138
|
+
confidence = 1 - values.reduce((total, value, level) => total + value * Math.abs(level - mode), 0) / uniform;
|
|
139
|
+
}
|
|
140
|
+
return Math.min(1, Math.max(0, confidence));
|
|
141
|
+
}
|
|
142
|
+
function readProfile(profile) {
|
|
143
|
+
if (profile === null || typeof profile !== "object" || profile.decimals !== void 0 && (!Number.isSafeInteger(profile.decimals) || profile.decimals < 0 || profile.decimals > 15) || profile.confidence !== "canonical" && profile.confidence !== "provider-defined") throw new TypeError("Invalid System One result profile");
|
|
144
|
+
}
|
|
145
|
+
function normalizeAnswer(answer, question, profile) {
|
|
146
|
+
const levels = levelsOf(question);
|
|
147
|
+
const probabilities = answer.probabilities;
|
|
148
|
+
const keys = Object.keys(probabilities);
|
|
149
|
+
if (keys.length !== levels.length || levels.some((level) => {
|
|
150
|
+
const value = probabilities[level];
|
|
151
|
+
return !Object.hasOwn(probabilities, level) || typeof value !== "number" || !(value >= 0 && value <= 1);
|
|
152
|
+
})) return answer;
|
|
153
|
+
const q = probabilities;
|
|
154
|
+
const sum = keys.reduce((total, key) => total + q[key], 0);
|
|
155
|
+
const scored = question.type === "score";
|
|
156
|
+
const score = answer.score;
|
|
157
|
+
if (scored && (typeof score !== "number" || !Number.isFinite(score))) return answer;
|
|
158
|
+
let next = answer;
|
|
159
|
+
if (!(Math.abs(sum - 1) <= TOLERANCE && (!scored || Math.abs(score - expectation(levels, q)) <= TOLERANCE)) && profile.decimals !== void 0) {
|
|
160
|
+
const unit = 10 ** -profile.decimals;
|
|
161
|
+
if (Math.abs(sum - 1) > levels.length * unit / 2) throw new SystemOneResponseError("Distribution error exceeds declared rounding");
|
|
162
|
+
const levelTotal = levels.length * (levels.length - 1) / 2;
|
|
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) <= TOLERANCE ? q : Object.fromEntries(keys.map((key) => [key, q[key] / sum]));
|
|
165
|
+
next = {
|
|
166
|
+
...answer,
|
|
167
|
+
probabilities: p,
|
|
168
|
+
...scored ? { score: expectation(levels, p) } : {}
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
if (profile.confidence === "provider-defined" && typeof answer.confidence === "number" && !Object.hasOwn(answer, "provider_confidence")) next = {
|
|
172
|
+
...next,
|
|
173
|
+
provider_confidence: answer.confidence,
|
|
174
|
+
confidence: systemOneConfidence({
|
|
175
|
+
type: question.type,
|
|
176
|
+
probabilities: next.probabilities
|
|
177
|
+
})
|
|
178
|
+
};
|
|
179
|
+
return next;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Remove a provider's declared rounding and apply the one confidence definition, before
|
|
183
|
+
* `parseSystemOneResult`. An answer that already passes the strict checks keeps its
|
|
184
|
+
* probabilities and score. One that fails them only within the declared rounding is renormalized
|
|
185
|
+
* and its score recomputed from that distribution; larger error throws. Noul answers never change.
|
|
186
|
+
* Returns `raw` itself when nothing changes and never mutates it; shapes it cannot read are left
|
|
187
|
+
* for the strict parser to refuse.
|
|
188
|
+
*/
|
|
189
|
+
function normalizeSystemOneResult(raw, request, profile) {
|
|
190
|
+
readProfile(profile);
|
|
191
|
+
if (raw === null || typeof raw !== "object" || Array.isArray(raw)) return raw;
|
|
192
|
+
const response = raw;
|
|
193
|
+
const original = response.answers;
|
|
194
|
+
if (original === null || typeof original !== "object" || Array.isArray(original)) return raw;
|
|
195
|
+
const answers = { ...original };
|
|
196
|
+
let changed = false;
|
|
197
|
+
for (const [name, question] of Object.entries(request.questions)) {
|
|
198
|
+
const answer = answers[name];
|
|
199
|
+
if (question.type === "noul" || answer === null || typeof answer !== "object" || Array.isArray(answer) || answer.type !== question.type || answer.probabilities === null || typeof answer.probabilities !== "object" || Array.isArray(answer.probabilities)) continue;
|
|
200
|
+
const next = normalizeAnswer(answer, question, profile);
|
|
201
|
+
if (next !== answer) {
|
|
202
|
+
answers[name] = next;
|
|
203
|
+
changed = true;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return changed ? {
|
|
207
|
+
...response,
|
|
208
|
+
answers
|
|
209
|
+
} : raw;
|
|
210
|
+
}
|
|
211
|
+
//#endregion
|
|
212
|
+
export { SystemOneResponseError, normalizeSystemOneResult, parseSystemOneQuestions, parseSystemOneRecordedRequest, parseSystemOneRequest, parseSystemOneResult, systemOneConfidence, systemOneUsage };
|
|
213
|
+
|
|
214
|
+
//# sourceMappingURL=systemone-protocol.js.map
|
|
@@ -0,0 +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;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;EAElE,IAAI,SAAS,SAAS,QAChB;OAAA,SAAS,YAAY,MAAM;IAC7B,MAAM,WAAW,OAAO,SAAS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