@taifoon/jev 0.2.9 → 0.2.10
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/dist/pipeline.js +1 -1
- package/dist/wilson.d.ts +49 -0
- package/dist/wilson.js +66 -0
- package/package.json +2 -4
package/dist/pipeline.js
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// (https://coord.taifoon.dev by default) the job comes from /v1/judge/queue, the pack from /v1/judge/evidence, the
|
|
6
6
|
// seller's terms from /v1/pools/quote, and — only with a relayer key — the answers are recorded on the layer through
|
|
7
7
|
// /v1/judge/answers/record. Nothing here signs a transaction.
|
|
8
|
-
import { premium as wilsonPremium, wilson } from '
|
|
8
|
+
import { premium as wilsonPremium, wilson } from './wilson.js';
|
|
9
9
|
import { facts as runFacts } from './facts.js';
|
|
10
10
|
import { grade } from './grade.js';
|
|
11
11
|
import { record } from './record.js';
|
package/dist/wilson.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/** z for a two-sided 95% interval, as the layer pins it. */
|
|
2
|
+
export declare const Z = 1.959963984540054;
|
|
3
|
+
/** The layer's pool rule: no pool covers above this premium ratio. */
|
|
4
|
+
export declare const MAX_PREMIUM_RATIO = 0.3;
|
|
5
|
+
/** The premium ratio is rounded to millionths before it multiplies the price. */
|
|
6
|
+
export declare const RATIO_SCALE = 1000000;
|
|
7
|
+
/** The Wilson score interval for `successes` of `n`. [0, 1] when n = 0. Same operations, same order as the layer. */
|
|
8
|
+
export declare function wilson(successes: number, n: number, z?: number): [number, number];
|
|
9
|
+
/** u_F: the upper Wilson bound on the failure rate, n - k failed of n. This is the layer's π ratio. */
|
|
10
|
+
export declare function wilsonUpperFailure(k: number, n: number, z?: number): number;
|
|
11
|
+
/** floor(price × round(ratio × 1e6) / 1e6), exactly as the layer's pool-quote computes it. */
|
|
12
|
+
export declare function premiumAmount(price: bigint, ratio: number): bigint;
|
|
13
|
+
export type SellerRecord = {
|
|
14
|
+
k: number;
|
|
15
|
+
n: number;
|
|
16
|
+
};
|
|
17
|
+
export type PremiumOpts = {
|
|
18
|
+
/** floor on the ratio; default 0 (the layer has none) */
|
|
19
|
+
min?: number;
|
|
20
|
+
/** cover only when ratio <= max; default 0.30 (the layer's pool rule) */
|
|
21
|
+
max?: number;
|
|
22
|
+
/** price in the token's smallest unit; when given, `amount` is computed */
|
|
23
|
+
price?: bigint | number | string;
|
|
24
|
+
/** z for the record form; default Z */
|
|
25
|
+
z?: number;
|
|
26
|
+
};
|
|
27
|
+
export type Premium = {
|
|
28
|
+
insurable: false;
|
|
29
|
+
reason: 'UNKNOWN';
|
|
30
|
+
ratio: null;
|
|
31
|
+
amount: null;
|
|
32
|
+
covered: false;
|
|
33
|
+
basis: 'record';
|
|
34
|
+
} | {
|
|
35
|
+
insurable: true;
|
|
36
|
+
ratio: number;
|
|
37
|
+
amount: bigint | null;
|
|
38
|
+
covered: boolean;
|
|
39
|
+
basis: 'record' | 'p_L';
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* The premium for the next job.
|
|
43
|
+
*
|
|
44
|
+
* premium({ k, n }, opts) prices from the record: ratio = u_F, bit-for-bit with the layer.
|
|
45
|
+
* premium(pL, opts) prices from a lower bound you already hold: ratio = 1 - p_L. Equal in real
|
|
46
|
+
* arithmetic, but 1 - p_L can differ from u_F in the last bits of a double.
|
|
47
|
+
* Use the record form when you need the layer's number to the last digit.
|
|
48
|
+
*/
|
|
49
|
+
export declare function premium(input: number | SellerRecord, opts?: PremiumOpts): Premium;
|
package/dist/wilson.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// GENERATED from @taifoon/jev-wilson 0.1.0 (src/wilson.ts) by scripts/vendor-wilson.mjs. Do not edit here.
|
|
2
|
+
// The pricing half only: z, the Wilson interval, the premium. Same numbers as the layer's /v1/pools/quote.
|
|
3
|
+
/** z for a two-sided 95% interval, as the layer pins it. */
|
|
4
|
+
export const Z = 1.959963984540054;
|
|
5
|
+
/** The layer's pool rule: no pool covers above this premium ratio. */
|
|
6
|
+
export const MAX_PREMIUM_RATIO = 0.3;
|
|
7
|
+
/** The premium ratio is rounded to millionths before it multiplies the price. */
|
|
8
|
+
export const RATIO_SCALE = 1_000_000;
|
|
9
|
+
function checkRecord(k, n) {
|
|
10
|
+
if (!Number.isInteger(k) || !Number.isInteger(n) || k < 0 || n < 0 || k > n) {
|
|
11
|
+
throw new RangeError(`need integers 0 <= k <= n, got k=${k}, n=${n}`);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/** The Wilson score interval for `successes` of `n`. [0, 1] when n = 0. Same operations, same order as the layer. */
|
|
15
|
+
export function wilson(successes, n, z = Z) {
|
|
16
|
+
if (n <= 0)
|
|
17
|
+
return [0, 1];
|
|
18
|
+
const p = successes / n, z2 = z * z;
|
|
19
|
+
const d = 1 + z2 / n;
|
|
20
|
+
const c = p + z2 / (2 * n);
|
|
21
|
+
const s = z * Math.sqrt((p * (1 - p) + z2 / (4 * n)) / n);
|
|
22
|
+
return [Math.max(0, (c - s) / d), Math.min(1, (c + s) / d)];
|
|
23
|
+
}
|
|
24
|
+
/** u_F: the upper Wilson bound on the failure rate, n - k failed of n. This is the layer's π ratio. */
|
|
25
|
+
export function wilsonUpperFailure(k, n, z = Z) {
|
|
26
|
+
checkRecord(k, n);
|
|
27
|
+
return wilson(n - k, n, z)[1];
|
|
28
|
+
}
|
|
29
|
+
/** JavaScript Math.round, kept explicit so the Python twin can match it. */
|
|
30
|
+
const roundHalfUp = (x) => Math.round(x);
|
|
31
|
+
/** floor(price × round(ratio × 1e6) / 1e6), exactly as the layer's pool-quote computes it. */
|
|
32
|
+
export function premiumAmount(price, ratio) {
|
|
33
|
+
if (price <= 0n)
|
|
34
|
+
throw new RangeError('price must be a positive integer in the token’s smallest unit');
|
|
35
|
+
return (price * BigInt(roundHalfUp(ratio * RATIO_SCALE))) / BigInt(RATIO_SCALE);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The premium for the next job.
|
|
39
|
+
*
|
|
40
|
+
* premium({ k, n }, opts) prices from the record: ratio = u_F, bit-for-bit with the layer.
|
|
41
|
+
* premium(pL, opts) prices from a lower bound you already hold: ratio = 1 - p_L. Equal in real
|
|
42
|
+
* arithmetic, but 1 - p_L can differ from u_F in the last bits of a double.
|
|
43
|
+
* Use the record form when you need the layer's number to the last digit.
|
|
44
|
+
*/
|
|
45
|
+
export function premium(input, opts = {}) {
|
|
46
|
+
const min = opts.min ?? 0;
|
|
47
|
+
const max = opts.max ?? MAX_PREMIUM_RATIO;
|
|
48
|
+
let raw;
|
|
49
|
+
let basis;
|
|
50
|
+
if (typeof input === 'number') {
|
|
51
|
+
if (!(input >= 0 && input <= 1))
|
|
52
|
+
throw new RangeError(`p_L must be in [0, 1], got ${input}`);
|
|
53
|
+
raw = 1 - input;
|
|
54
|
+
basis = 'p_L';
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
checkRecord(input.k, input.n);
|
|
58
|
+
if (input.k <= 0)
|
|
59
|
+
return { insurable: false, reason: 'UNKNOWN', ratio: null, amount: null, covered: false, basis: 'record' };
|
|
60
|
+
raw = wilsonUpperFailure(input.k, input.n, opts.z ?? Z);
|
|
61
|
+
basis = 'record';
|
|
62
|
+
}
|
|
63
|
+
const ratio = raw < min ? min : raw;
|
|
64
|
+
const amount = opts.price === undefined ? null : premiumAmount(BigInt(opts.price), ratio);
|
|
65
|
+
return { insurable: true, ratio, amount, covered: ratio <= max, basis };
|
|
66
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taifoon/jev",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"description": "Grade AI agent jobs with TypeSafe's Jev and record the verdict on chain: code checks the facts, Jev answers a published rubric, and you get a receipt, the on-chain record and the evaluator call for ERC-8183 and Virtuals ACP. No runtime dependencies, no key inside.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jev",
|
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
"access": "public"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
|
+
"@taifoon/jev-wilson": "^0.1.0",
|
|
73
74
|
"@types/node": "^25.9.2",
|
|
74
75
|
"typescript": "5.9.2",
|
|
75
76
|
"viem": "2.52.2",
|
|
@@ -78,8 +79,5 @@
|
|
|
78
79
|
"bin": {
|
|
79
80
|
"jev": "bin/jev.mjs",
|
|
80
81
|
"taifoon-jev": "bin/jev.mjs"
|
|
81
|
-
},
|
|
82
|
-
"dependencies": {
|
|
83
|
-
"@taifoon/jev-wilson": "^0.1.0"
|
|
84
82
|
}
|
|
85
83
|
}
|