@taifoon/jev 0.2.12 → 0.2.13

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/README.md CHANGED
@@ -176,4 +176,4 @@ npx @taifoon/jev workflows export ./jev-workflows
176
176
 
177
177
  Independent project. Jev and TypeSafe are products of TypeSafe AI, Inc., which does not endorse this package.
178
178
 
179
- Built by Taifoon. MIT. The package has no runtime dependencies and contains no key. It calls Jev only with your own TypeSafe key.
179
+ Built by Taifoon. MIT. The package's only runtime dependency is Taifoon's own @taifoon/jev-wilson, the pricing; nothing third-party. It contains no key. It calls Jev only with your own TypeSafe key.
package/dist/wilson.d.ts CHANGED
@@ -1,49 +1,2 @@
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;
1
+ export { Z, MAX_PREMIUM_RATIO, RATIO_SCALE, wilson, wilsonUpperFailure, premiumAmount, premium } from '@taifoon/jev-wilson';
2
+ export type { SellerRecord, PremiumOpts, Premium } from '@taifoon/jev-wilson';
package/dist/wilson.js CHANGED
@@ -1,66 +1,3 @@
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
- }
1
+ // The pricing half is @taifoon/jev-wilson, the layer's own package, and this module is its re-export: one
2
+ // implementation, the same numbers as the layer's /v1/pools/quote. Installing @taifoon/jev installs it.
3
+ export { Z, MAX_PREMIUM_RATIO, RATIO_SCALE, wilson, wilsonUpperFailure, premiumAmount, premium } from '@taifoon/jev-wilson';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@taifoon/jev",
3
- "version": "0.2.12",
3
+ "version": "0.2.13",
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",
@@ -69,8 +69,10 @@
69
69
  "publishConfig": {
70
70
  "access": "public"
71
71
  },
72
+ "dependencies": {
73
+ "@taifoon/jev-wilson": "^0.2.0"
74
+ },
72
75
  "devDependencies": {
73
- "@taifoon/jev-wilson": "^0.1.0",
74
76
  "@types/node": "^25.9.2",
75
77
  "typescript": "5.9.2",
76
78
  "viem": "2.52.2",