privateer-agent 0.15.4 → 0.15.6
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 +11 -0
- package/bin/boot-bundle.d.mts +2 -0
- package/bin/boot-bundle.mjs +44 -0
- package/bin/fresh-supervisor.d.mts +5 -1
- package/bin/fresh-supervisor.mjs +47 -10
- package/bin/privateer-launch.mjs +27 -3
- package/bin/privateer-subagent.mjs +5 -2
- package/bin/privateer-verify.mjs +12 -0
- package/bin/session-recovery.d.mts +53 -0
- package/bin/session-recovery.mjs +240 -0
- package/bin/session-seal-preload.mjs +17 -0
- package/bin/session-seal.d.mts +25 -0
- package/bin/session-seal.mjs +242 -0
- package/dist-boot/boot.mjs +3 -0
- package/dist-boot/c-27JKSMWL.mjs +1460 -0
- package/dist-boot/c-2BMRFV24.mjs +269 -0
- package/dist-boot/c-2CTF6JA3.mjs +166 -0
- package/dist-boot/c-2G3BBHRJ.mjs +84 -0
- package/dist-boot/c-2IDLKXX6.mjs +250 -0
- package/dist-boot/c-2NJD5VYM.mjs +8 -0
- package/dist-boot/c-2S5EEQPW.mjs +1602 -0
- package/dist-boot/c-2WRDCUVI.mjs +25 -0
- package/dist-boot/c-2YN3M256.mjs +14 -0
- package/dist-boot/c-37GM3GMU.mjs +187 -0
- package/dist-boot/c-3STKRSVO.mjs +2480 -0
- package/dist-boot/c-3TPV6TQQ.mjs +2320 -0
- package/dist-boot/c-3UVHLQDJ.mjs +225 -0
- package/dist-boot/c-42PUUZYC.mjs +697 -0
- package/dist-boot/c-4D5UMWVW.mjs +683 -0
- package/dist-boot/c-4ETZRMTA.mjs +46 -0
- package/dist-boot/c-4QT25BD5.mjs +1482 -0
- package/dist-boot/c-4WVR32AP.mjs +2579 -0
- package/dist-boot/c-5EMM567G.mjs +152 -0
- package/dist-boot/c-5FA4CV63.mjs +145 -0
- package/dist-boot/c-5GV3X3RB.mjs +14 -0
- package/dist-boot/c-5JCEPRIY.mjs +52 -0
- package/dist-boot/c-5NDKIIWT.mjs +16 -0
- package/dist-boot/c-5QL3AR26.mjs +4665 -0
- package/dist-boot/c-5XY6MFKN.mjs +5142 -0
- package/dist-boot/c-65UZIZC7.mjs +2897 -0
- package/dist-boot/c-6FUXKHOK.mjs +1969 -0
- package/dist-boot/c-6JHWQE4V.mjs +18242 -0
- package/dist-boot/c-6LOBR4I6.mjs +5280 -0
- package/dist-boot/c-6QHOZXKQ.mjs +14394 -0
- package/dist-boot/c-6ZO2SADQ.mjs +178 -0
- package/dist-boot/c-6ZORVVZP.mjs +1449 -0
- package/dist-boot/c-76QH4UCP.mjs +2441 -0
- package/dist-boot/c-77GO5L5Y.mjs +20982 -0
- package/dist-boot/c-7M23XFTN.mjs +5052 -0
- package/dist-boot/c-7TC367E2.mjs +32 -0
- package/dist-boot/c-7UOG7POX.mjs +1524 -0
- package/dist-boot/c-7VHP3FLN.mjs +376 -0
- package/dist-boot/c-A73JHZP2.mjs +13207 -0
- package/dist-boot/c-ABXULAFL.mjs +71 -0
- package/dist-boot/c-ANDD2AQO.mjs +74 -0
- package/dist-boot/c-AOY77AZL.mjs +1430 -0
- package/dist-boot/c-AXEPZ22I.mjs +108 -0
- package/dist-boot/c-B2Y7VNHU.mjs +427 -0
- package/dist-boot/c-B7VJUH73.mjs +77 -0
- package/dist-boot/c-BFW6CDVL.mjs +24 -0
- package/dist-boot/c-BHNIF2AR.mjs +188 -0
- package/dist-boot/c-BKF2O6BL.mjs +23 -0
- package/dist-boot/c-BOZXFTZN.mjs +8 -0
- package/dist-boot/c-BRNYJWZL.mjs +28 -0
- package/dist-boot/c-C3N4Z2HO.mjs +93 -0
- package/dist-boot/c-C4IV7ZFG.mjs +717 -0
- package/dist-boot/c-C5NK6UYV.mjs +793 -0
- package/dist-boot/c-C67644MB.mjs +1659 -0
- package/dist-boot/c-C6S2YB53.mjs +620 -0
- package/dist-boot/c-CDBEJSBF.mjs +37 -0
- package/dist-boot/c-CG47HBKU.mjs +435 -0
- package/dist-boot/c-CKCTWCT5.mjs +51 -0
- package/dist-boot/c-CN77DCGF.mjs +60 -0
- package/dist-boot/c-CRBXNKFO.mjs +1795 -0
- package/dist-boot/c-CRIHASQ6.mjs +973 -0
- package/dist-boot/c-CU4NGAUO.mjs +3786 -0
- package/dist-boot/c-CWRFLGQU.mjs +1883 -0
- package/dist-boot/c-CYQB2USO.mjs +32 -0
- package/dist-boot/c-DEE67DJO.mjs +379 -0
- package/dist-boot/c-DIFDBYOP.mjs +1258 -0
- package/dist-boot/c-DOSGVXDZ.mjs +34879 -0
- package/dist-boot/c-DR7XQI32.mjs +381 -0
- package/dist-boot/c-DTGPSB46.mjs +14666 -0
- package/dist-boot/c-DTHDNA4P.mjs +320 -0
- package/dist-boot/c-E4Z3Y5B5.mjs +3864 -0
- package/dist-boot/c-E66Z2TI7.mjs +203 -0
- package/dist-boot/c-EBU6RLRV.mjs +1527 -0
- package/dist-boot/c-EBZZNGSF.mjs +432 -0
- package/dist-boot/c-EC3LJ2KF.mjs +1032 -0
- package/dist-boot/c-EQBKXWNX.mjs +15829 -0
- package/dist-boot/c-EUEPIW4S.mjs +574 -0
- package/dist-boot/c-EX4YVWAT.mjs +378 -0
- package/dist-boot/c-EYZGSAJU.mjs +98 -0
- package/dist-boot/c-F75VRKY4.mjs +172 -0
- package/dist-boot/c-FH4NXKHV.mjs +177 -0
- package/dist-boot/c-FHNUCTEM.mjs +140 -0
- package/dist-boot/c-FJ5T42DS.mjs +5349 -0
- package/dist-boot/c-FPCNRL7G.mjs +1728 -0
- package/dist-boot/c-G4DLN7Q4.mjs +8 -0
- package/dist-boot/c-G56GYQFZ.mjs +2507 -0
- package/dist-boot/c-GLIOERDQ.mjs +1200 -0
- package/dist-boot/c-GMJ5HUBM.mjs +14 -0
- package/dist-boot/c-H3HSGMAQ.mjs +461 -0
- package/dist-boot/c-HIKTO6P7.mjs +275 -0
- package/dist-boot/c-I2MCJ34O.mjs +464 -0
- package/dist-boot/c-I3C6LBW4.mjs +765 -0
- package/dist-boot/c-I54OKQHW.mjs +387 -0
- package/dist-boot/c-IFSP3R4D.mjs +80 -0
- package/dist-boot/c-IZK77VB7.mjs +171 -0
- package/dist-boot/c-J3Y25UGE.mjs +54 -0
- package/dist-boot/c-J5IESS7W.mjs +27750 -0
- package/dist-boot/c-JJWZBY7L.mjs +254 -0
- package/dist-boot/c-JKTFXTGF.mjs +463 -0
- package/dist-boot/c-JN57AXQ4.mjs +77 -0
- package/dist-boot/c-KFIO6LUW.mjs +1096 -0
- package/dist-boot/c-KIEMEFWW.mjs +478 -0
- package/dist-boot/c-KIVXWBYD.mjs +28 -0
- package/dist-boot/c-KP6CRIP4.mjs +580 -0
- package/dist-boot/c-L26VOJX4.mjs +11558 -0
- package/dist-boot/c-L5GHWG5G.mjs +5988 -0
- package/dist-boot/c-M7NSQAKK.mjs +353 -0
- package/dist-boot/c-MCEWOPBW.mjs +56 -0
- package/dist-boot/c-MGPIEG7I.mjs +20 -0
- package/dist-boot/c-NREXJV3M.mjs +393 -0
- package/dist-boot/c-O5PP6CTX.mjs +162 -0
- package/dist-boot/c-OBQDHSXM.mjs +1774 -0
- package/dist-boot/c-OLQHHDD4.mjs +21 -0
- package/dist-boot/c-OXW4JQQH.mjs +319 -0
- package/dist-boot/c-P3D7ZUWN.mjs +1288 -0
- package/dist-boot/c-P4PQZVV5.mjs +948 -0
- package/dist-boot/c-P63T3XL2.mjs +26373 -0
- package/dist-boot/c-P6N5DQGZ.mjs +194 -0
- package/dist-boot/c-P7MLKQFC.mjs +58 -0
- package/dist-boot/c-PB3PZJL5.mjs +1276 -0
- package/dist-boot/c-PTN4S6G2.mjs +1259 -0
- package/dist-boot/c-PYCE5J7U.mjs +1083 -0
- package/dist-boot/c-Q4HYCRLB.mjs +19410 -0
- package/dist-boot/c-QUXMETGG.mjs +68 -0
- package/dist-boot/c-RDMJZCOX.mjs +356 -0
- package/dist-boot/c-ROGJK76M.mjs +17 -0
- package/dist-boot/c-RQJJ26T4.mjs +708 -0
- package/dist-boot/c-RSKCUPJF.mjs +7559 -0
- package/dist-boot/c-RVJU4O6P.mjs +37 -0
- package/dist-boot/c-S2RVHR3M.mjs +165 -0
- package/dist-boot/c-SKMK3PEE.mjs +91120 -0
- package/dist-boot/c-TI7SM4EG.mjs +20 -0
- package/dist-boot/c-TILJ6GXD.mjs +1235 -0
- package/dist-boot/c-TT6BCUJD.mjs +114 -0
- package/dist-boot/c-U4ITOXAN.mjs +2107 -0
- package/dist-boot/c-UGERXVO2.mjs +7120 -0
- package/dist-boot/c-UPBH5AXY.mjs +1363 -0
- package/dist-boot/c-US2PUNZL.mjs +597 -0
- package/dist-boot/c-UU4WZPPE.mjs +20 -0
- package/dist-boot/c-UWVIYPQS.mjs +39 -0
- package/dist-boot/c-V4RHQBPQ.mjs +17683 -0
- package/dist-boot/c-V5MRVK47.mjs +351 -0
- package/dist-boot/c-V6CL266R.mjs +1755 -0
- package/dist-boot/c-VJTMFKYE.mjs +14975 -0
- package/dist-boot/c-VJTRUKIB.mjs +773 -0
- package/dist-boot/c-W4IFSHPW.mjs +43 -0
- package/dist-boot/c-WETGB2CF.mjs +113 -0
- package/dist-boot/c-WO3QSZUU.mjs +1337 -0
- package/dist-boot/c-WQLH73TY.mjs +242 -0
- package/dist-boot/c-XL735JW5.mjs +500 -0
- package/dist-boot/c-Y7HADL5B.mjs +1107 -0
- package/dist-boot/c-YGQHSVSK.mjs +41 -0
- package/dist-boot/c-YMP2AMEB.mjs +10350 -0
- package/dist-boot/c-YRDO2WEF.mjs +12012 -0
- package/dist-boot/c-YUSTRATJ.mjs +8 -0
- package/dist-boot/c-Z2262R22.mjs +2697 -0
- package/dist-boot/c-Z4ALQMJC.mjs +709 -0
- package/dist-boot/c-Z5ZUQVUY.mjs +62 -0
- package/dist-boot/c-ZDZUKXF7.mjs +874 -0
- package/dist-boot/c-ZJYLGIC3.mjs +32 -0
- package/dist-boot/c-ZNA5CDMI.mjs +77 -0
- package/dist-boot/c-ZSO6DI3M.mjs +204 -0
- package/dist-boot/c-ZWUVHKMK.mjs +100 -0
- package/dist-boot/c-ZY4MESEW.mjs +832 -0
- package/dist-boot/c-ZZ5REI4L.mjs +329 -0
- package/dist-boot/cli.mjs +51 -0
- package/dist-boot/ext-anthropic-attribution.mjs +207 -0
- package/dist-boot/ext-pi-background-tasks.mjs +7234 -0
- package/dist-boot/ext-pi-subagents.mjs +37 -0
- package/dist-boot/ext-privateer-account.mjs +4426 -0
- package/dist-boot/ext-privateer-brand.mjs +5274 -0
- package/dist-boot/ext-privateer-codemode.mjs +37 -0
- package/dist-boot/ext-privateer-computer.mjs +626 -0
- package/dist-boot/ext-privateer-connect.mjs +1862 -0
- package/dist-boot/ext-privateer-context.mjs +323 -0
- package/dist-boot/ext-privateer-desktop.mjs +92 -0
- package/dist-boot/ext-privateer-final-audit.mjs +48 -0
- package/dist-boot/ext-privateer-fresh.mjs +81 -0
- package/dist-boot/ext-privateer-gate.mjs +5959 -0
- package/dist-boot/ext-privateer-hints.mjs +236 -0
- package/dist-boot/ext-privateer-media.mjs +2626 -0
- package/dist-boot/ext-privateer-models.mjs +3397 -0
- package/dist-boot/ext-privateer-posture.mjs +3006 -0
- package/dist-boot/ext-privateer-privacy.mjs +4578 -0
- package/dist-boot/ext-privateer-recovery.mjs +287 -0
- package/dist-boot/ext-privateer-speak.mjs +4754 -0
- package/dist-boot/ext-privateer-terminals.mjs +725 -0
- package/dist-boot/ext-privateer-tools.mjs +528 -0
- package/dist-boot/ext-privateer-truncation.mjs +74 -0
- package/dist-boot/ext-privateer-update.mjs +210 -0
- package/dist-boot/ext-privateer-vision.mjs +148 -0
- package/dist-boot/ext-privateer-web.mjs +543 -0
- package/dist-boot/ext-rpiv-ask-user-question.mjs +710 -0
- package/dist-boot/manifest.json +9 -0
- package/extensions/privateer-brand.ts +3 -1
- package/extensions/privateer-context.ts +4 -2
- package/extensions/privateer-final-audit.ts +17 -0
- package/extensions/privateer-gate.ts +55 -9
- package/extensions/privateer-recovery.ts +175 -0
- package/extensions/privateer-web.ts +4 -4
- package/package.json +3 -1
- package/patches/@earendil-works+pi-coding-agent+1.3.0.patch +199 -2
- package/patches/pi-background-tasks+2.6.10.patch +91 -7
- package/src/cli/chat.ts +7 -1
- package/src/config/moatManifest.json +2 -0
- package/src/config/whatsNew.json +4 -4
- package/src/context.ts +33 -5
- package/src/engine/finalAudit.ts +38 -0
- package/src/engine/stallWatchdog.ts +8 -1
- package/src/providers/account.ts +34 -3
- package/src/remote/attentionPush.ts +40 -0
- package/src/remote/liveTaskSession.ts +7 -1
- package/src/remote/relayClient.ts +38 -4
- package/src/remote/remoteBridge.ts +17 -0
- package/src/remote/transcriptSnapshot.ts +104 -0
|
@@ -0,0 +1,597 @@
|
|
|
1
|
+
import{createRequire as __pvCR}from"node:module";import{fileURLToPath as __pvF}from"node:url";import{dirname as __pvD}from"node:path";const require=__pvCR(import.meta.url);const __pvUrl=(r)=>new URL(r,import.meta.url).href;const __pvFile=(r)=>__pvF(new URL(r,import.meta.url));
|
|
2
|
+
import {
|
|
3
|
+
__name
|
|
4
|
+
} from "./c-CN77DCGF.mjs";
|
|
5
|
+
|
|
6
|
+
// node_modules/pi-background-tasks/src/core/context/token-budget.ts?ext=pi-background-tasks
|
|
7
|
+
var TOKEN_BUDGET_CALIBRATION_VERSION = "pi-background-tasks.input-token-calibration.v1";
|
|
8
|
+
var TOKEN_BUDGET_RATE_SCALE = 100;
|
|
9
|
+
var TOKEN_BUDGET_HAIRCUT_BASIS_POINTS = 1500;
|
|
10
|
+
var TOKEN_BUDGET_LARGE_PROMPT_MIN_BYTES = 50 * 1024;
|
|
11
|
+
var TOKEN_BUDGET_CONSERVATIVE_RATE_X100 = 200;
|
|
12
|
+
var TOKEN_BUDGET_PROVABLE_RATE_X100 = 100;
|
|
13
|
+
var TOKEN_BUDGET_DELEGATE_CONSERVATIVE_RATE_X100 = TOKEN_BUDGET_PROVABLE_RATE_X100;
|
|
14
|
+
var TOKEN_BUDGET_MULTIBYTE_FATAL_RATE_X100 = TOKEN_BUDGET_CONSERVATIVE_RATE_X100;
|
|
15
|
+
var TOKEN_BUDGET_AFFINE_F_TOKENS = 512;
|
|
16
|
+
var TOKEN_BUDGET_WHITESPACE_FRACTION_SCALE = 1e4;
|
|
17
|
+
var TOKEN_BUDGET_CALIBRATION_CORPUS_MIN_WHITESPACE_FRACTION_X10000 = 18;
|
|
18
|
+
var TOKEN_BUDGET_DENSE_ASCII_WHITESPACE_THRESHOLD_X10000 = 10;
|
|
19
|
+
var ANTHROPIC_PROVENANCE = Object.freeze({
|
|
20
|
+
n: 85,
|
|
21
|
+
observed_min_bpt_x1000: 2047,
|
|
22
|
+
median_bpt_x1000: 2217,
|
|
23
|
+
max_bpt_x1000: 2481,
|
|
24
|
+
corpus_sha256: "sha256:large-fusion-prompts-2026-08-02",
|
|
25
|
+
corpus_date: "2026-08-02",
|
|
26
|
+
haircut_basis_points: TOKEN_BUDGET_HAIRCUT_BASIS_POINTS,
|
|
27
|
+
backed: true,
|
|
28
|
+
byte_level_bpe: true
|
|
29
|
+
});
|
|
30
|
+
var OPENAI_CODEX_PROVENANCE = Object.freeze({
|
|
31
|
+
n: 797,
|
|
32
|
+
observed_min_bpt_x1000: 3400,
|
|
33
|
+
median_bpt_x1000: 3721,
|
|
34
|
+
max_bpt_x1000: 4526,
|
|
35
|
+
corpus_sha256: "sha256:large-fusion-prompts-2026-08-02",
|
|
36
|
+
corpus_date: "2026-08-02",
|
|
37
|
+
haircut_basis_points: TOKEN_BUDGET_HAIRCUT_BASIS_POINTS,
|
|
38
|
+
backed: true,
|
|
39
|
+
byte_level_bpe: true
|
|
40
|
+
});
|
|
41
|
+
var UNKNOWN_PROVENANCE = Object.freeze({
|
|
42
|
+
n: 0,
|
|
43
|
+
observed_min_bpt_x1000: null,
|
|
44
|
+
median_bpt_x1000: null,
|
|
45
|
+
max_bpt_x1000: null,
|
|
46
|
+
corpus_sha256: null,
|
|
47
|
+
corpus_date: "unbacked",
|
|
48
|
+
haircut_basis_points: TOKEN_BUDGET_HAIRCUT_BASIS_POINTS,
|
|
49
|
+
backed: false,
|
|
50
|
+
byte_level_bpe: true
|
|
51
|
+
});
|
|
52
|
+
var TOKEN_BUDGET_FAMILY_CALIBRATIONS = Object.freeze({
|
|
53
|
+
anthropic: Object.freeze({
|
|
54
|
+
family: "anthropic",
|
|
55
|
+
rate_bytes_per_token_x100: 173,
|
|
56
|
+
affine_f_tokens: TOKEN_BUDGET_AFFINE_F_TOKENS,
|
|
57
|
+
provenance: ANTHROPIC_PROVENANCE
|
|
58
|
+
}),
|
|
59
|
+
"openai-codex": Object.freeze({
|
|
60
|
+
family: "openai-codex",
|
|
61
|
+
rate_bytes_per_token_x100: 289,
|
|
62
|
+
affine_f_tokens: TOKEN_BUDGET_AFFINE_F_TOKENS,
|
|
63
|
+
provenance: OPENAI_CODEX_PROVENANCE
|
|
64
|
+
}),
|
|
65
|
+
unknown: Object.freeze({
|
|
66
|
+
family: "unknown",
|
|
67
|
+
rate_bytes_per_token_x100: 100,
|
|
68
|
+
affine_f_tokens: TOKEN_BUDGET_AFFINE_F_TOKENS,
|
|
69
|
+
provenance: UNKNOWN_PROVENANCE
|
|
70
|
+
})
|
|
71
|
+
});
|
|
72
|
+
var MODEL_OVERRIDES = Object.freeze({
|
|
73
|
+
"anthropic/claude-opus-5": "anthropic",
|
|
74
|
+
"anthropic/claude-fable-5": "anthropic",
|
|
75
|
+
"openai-codex/gpt-5.6-sol": "openai-codex",
|
|
76
|
+
"openai-codex/gpt-5.6-terra": "openai-codex",
|
|
77
|
+
"openai-codex/gpt-5.5": "openai-codex",
|
|
78
|
+
"openai-codex/gpt-5.4-mini": "openai-codex"
|
|
79
|
+
});
|
|
80
|
+
var PROVIDER_DEFAULTS = Object.freeze({
|
|
81
|
+
anthropic: "anthropic",
|
|
82
|
+
"openai-codex": "openai-codex"
|
|
83
|
+
});
|
|
84
|
+
function resolveTokenBudgetFamily(route) {
|
|
85
|
+
const qualified = `${route.provider}/${route.model}`;
|
|
86
|
+
const overridden = MODEL_OVERRIDES[qualified];
|
|
87
|
+
if (overridden !== void 0) {
|
|
88
|
+
return {
|
|
89
|
+
family: overridden,
|
|
90
|
+
provider: route.provider,
|
|
91
|
+
model: route.model,
|
|
92
|
+
qualified_id: qualified,
|
|
93
|
+
backed: true,
|
|
94
|
+
resolution: "model_override"
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
const providerDefault = PROVIDER_DEFAULTS[route.provider];
|
|
98
|
+
if (providerDefault !== void 0) {
|
|
99
|
+
return {
|
|
100
|
+
family: providerDefault,
|
|
101
|
+
provider: route.provider,
|
|
102
|
+
model: route.model,
|
|
103
|
+
qualified_id: qualified,
|
|
104
|
+
backed: false,
|
|
105
|
+
resolution: "known_provider_unbacked_model"
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
family: "unknown",
|
|
110
|
+
provider: route.provider,
|
|
111
|
+
model: route.model,
|
|
112
|
+
qualified_id: qualified,
|
|
113
|
+
backed: false,
|
|
114
|
+
resolution: "unknown_provider_floor"
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
__name(resolveTokenBudgetFamily, "resolveTokenBudgetFamily");
|
|
118
|
+
function assertSafeNonNegativeInteger(value, label) {
|
|
119
|
+
if (!Number.isSafeInteger(value) || value < 0) {
|
|
120
|
+
throw new TypeError(`${label} must be a non-negative safe integer`);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
__name(assertSafeNonNegativeInteger, "assertSafeNonNegativeInteger");
|
|
124
|
+
function assertPositiveInteger(value, label) {
|
|
125
|
+
if (!Number.isSafeInteger(value) || value <= 0) {
|
|
126
|
+
throw new TypeError(`${label} must be a positive safe integer`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
__name(assertPositiveInteger, "assertPositiveInteger");
|
|
130
|
+
function calibrationFor(family) {
|
|
131
|
+
return TOKEN_BUDGET_FAMILY_CALIBRATIONS[family];
|
|
132
|
+
}
|
|
133
|
+
__name(calibrationFor, "calibrationFor");
|
|
134
|
+
function ceilDiv(numerator, denominator) {
|
|
135
|
+
assertSafeNonNegativeInteger(numerator, "division numerator");
|
|
136
|
+
assertPositiveInteger(denominator, "division denominator");
|
|
137
|
+
if (numerator === 0) return 0;
|
|
138
|
+
return Math.floor((numerator - 1) / denominator) + 1;
|
|
139
|
+
}
|
|
140
|
+
__name(ceilDiv, "ceilDiv");
|
|
141
|
+
function tokensAtRate(bytes, rateBytesPerTokenX100) {
|
|
142
|
+
assertSafeNonNegativeInteger(bytes, "bytes");
|
|
143
|
+
assertPositiveInteger(rateBytesPerTokenX100, "rateBytesPerTokenX100");
|
|
144
|
+
return ceilDiv(bytes * TOKEN_BUDGET_RATE_SCALE, rateBytesPerTokenX100);
|
|
145
|
+
}
|
|
146
|
+
__name(tokensAtRate, "tokensAtRate");
|
|
147
|
+
function conservativeFusionRate(configured) {
|
|
148
|
+
return Math.min(configured, TOKEN_BUDGET_CONSERVATIVE_RATE_X100);
|
|
149
|
+
}
|
|
150
|
+
__name(conservativeFusionRate, "conservativeFusionRate");
|
|
151
|
+
function normalizeSegment(segment, index) {
|
|
152
|
+
assertSafeNonNegativeInteger(segment.bytes, `segments[${String(index)}].bytes`);
|
|
153
|
+
const denseBytes = segment.denseBytes ?? 0;
|
|
154
|
+
assertSafeNonNegativeInteger(denseBytes, `segments[${String(index)}].denseBytes`);
|
|
155
|
+
if (segment.kind === "unknown_output_contract") {
|
|
156
|
+
if (segment.multibyteBytes !== void 0) {
|
|
157
|
+
throw new TypeError(
|
|
158
|
+
`segments[${String(index)}].multibyteBytes must not be set for unknown_output_contract`
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
if (segment.asciiWhitespaceBytes !== void 0) {
|
|
162
|
+
throw new TypeError(
|
|
163
|
+
`segments[${String(index)}].asciiWhitespaceBytes must not be set for unknown_output_contract`
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
if (denseBytes !== 0) {
|
|
167
|
+
throw new TypeError(
|
|
168
|
+
`segments[${String(index)}].denseBytes must be zero for unknown_output_contract`
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
kind: segment.kind,
|
|
173
|
+
bytes: segment.bytes,
|
|
174
|
+
multibyteBytes: 0,
|
|
175
|
+
denseBytes,
|
|
176
|
+
asciiWhitespaceBytes: 0,
|
|
177
|
+
whitespaceKnown: true
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
if (segment.kind !== "known_text" && segment.kind !== "known_json") {
|
|
181
|
+
throw new TypeError(`segments[${String(index)}].kind is not supported`);
|
|
182
|
+
}
|
|
183
|
+
if (segment.multibyteBytes === void 0) {
|
|
184
|
+
throw new TypeError(`segments[${String(index)}].multibyteBytes is required`);
|
|
185
|
+
}
|
|
186
|
+
assertSafeNonNegativeInteger(segment.multibyteBytes, `segments[${String(index)}].multibyteBytes`);
|
|
187
|
+
if (segment.multibyteBytes + denseBytes > segment.bytes) {
|
|
188
|
+
throw new TypeError(
|
|
189
|
+
`segments[${String(index)}] byte classes exceed segment byte length`
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
const whitespaceKnown = segment.asciiWhitespaceBytes !== void 0;
|
|
193
|
+
const asciiWhitespaceBytes = segment.asciiWhitespaceBytes ?? 0;
|
|
194
|
+
assertSafeNonNegativeInteger(
|
|
195
|
+
asciiWhitespaceBytes,
|
|
196
|
+
`segments[${String(index)}].asciiWhitespaceBytes`
|
|
197
|
+
);
|
|
198
|
+
if (asciiWhitespaceBytes > segment.bytes - segment.multibyteBytes) {
|
|
199
|
+
throw new TypeError(
|
|
200
|
+
`segments[${String(index)}].asciiWhitespaceBytes exceeds ASCII byte length`
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
return {
|
|
204
|
+
kind: segment.kind,
|
|
205
|
+
bytes: segment.bytes,
|
|
206
|
+
multibyteBytes: segment.multibyteBytes,
|
|
207
|
+
denseBytes,
|
|
208
|
+
asciiWhitespaceBytes,
|
|
209
|
+
whitespaceKnown
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
__name(normalizeSegment, "normalizeSegment");
|
|
213
|
+
function addBreakdown(target, delta) {
|
|
214
|
+
target.total_bytes += delta.total_bytes;
|
|
215
|
+
target.normal_bytes += delta.normal_bytes;
|
|
216
|
+
target.multibyte_bytes += delta.multibyte_bytes;
|
|
217
|
+
target.dense_bytes += delta.dense_bytes;
|
|
218
|
+
target.unknown_output_contract_bytes += delta.unknown_output_contract_bytes;
|
|
219
|
+
}
|
|
220
|
+
__name(addBreakdown, "addBreakdown");
|
|
221
|
+
function dominantByteClass(breakdown) {
|
|
222
|
+
const entries = [
|
|
223
|
+
{ byteClass: "dense_ascii", bytes: breakdown.dense_bytes, order: 0 },
|
|
224
|
+
{ byteClass: "multibyte", bytes: breakdown.multibyte_bytes, order: 1 },
|
|
225
|
+
{ byteClass: "unknown_output_contract", bytes: breakdown.unknown_output_contract_bytes, order: 2 },
|
|
226
|
+
{ byteClass: "normal", bytes: breakdown.normal_bytes, order: 3 }
|
|
227
|
+
];
|
|
228
|
+
entries.sort((left, right) => right.bytes - left.bytes || left.order - right.order);
|
|
229
|
+
return entries[0]?.byteClass ?? "normal";
|
|
230
|
+
}
|
|
231
|
+
__name(dominantByteClass, "dominantByteClass");
|
|
232
|
+
function profileForSegments(segments, breakdown) {
|
|
233
|
+
let asciiWhitespaceBytes = 0;
|
|
234
|
+
let whitespaceKnown = true;
|
|
235
|
+
for (const segment of segments) {
|
|
236
|
+
if (segment.kind === "unknown_output_contract") continue;
|
|
237
|
+
asciiWhitespaceBytes += segment.asciiWhitespaceBytes;
|
|
238
|
+
if (!segment.whitespaceKnown) whitespaceKnown = false;
|
|
239
|
+
}
|
|
240
|
+
const concreteKnownBytes = breakdown.total_bytes - breakdown.unknown_output_contract_bytes;
|
|
241
|
+
const whitespaceFraction = whitespaceKnown && concreteKnownBytes > 0 ? Math.floor(asciiWhitespaceBytes * TOKEN_BUDGET_WHITESPACE_FRACTION_SCALE / concreteKnownBytes) : null;
|
|
242
|
+
return {
|
|
243
|
+
...breakdown,
|
|
244
|
+
concrete_known_bytes: concreteKnownBytes,
|
|
245
|
+
ascii_whitespace_bytes: asciiWhitespaceBytes,
|
|
246
|
+
whitespace_fraction_x10000: whitespaceFraction,
|
|
247
|
+
whitespace_fraction_scale: TOKEN_BUDGET_WHITESPACE_FRACTION_SCALE,
|
|
248
|
+
whitespace_fraction_available: whitespaceKnown,
|
|
249
|
+
dominant_byte_class: dominantByteClass(breakdown)
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
__name(profileForSegments, "profileForSegments");
|
|
253
|
+
function denseAsciiGate(profile) {
|
|
254
|
+
const base = {
|
|
255
|
+
heuristic: "low_whitespace_fraction_proxy_not_tokenizer_bound",
|
|
256
|
+
corpus_min_whitespace_fraction_x10000: TOKEN_BUDGET_CALIBRATION_CORPUS_MIN_WHITESPACE_FRACTION_X10000,
|
|
257
|
+
threshold_whitespace_fraction_x10000: TOKEN_BUDGET_DENSE_ASCII_WHITESPACE_THRESHOLD_X10000,
|
|
258
|
+
measured_whitespace_fraction_x10000: profile.whitespace_fraction_x10000
|
|
259
|
+
};
|
|
260
|
+
if (profile.concrete_known_bytes < TOKEN_BUDGET_LARGE_PROMPT_MIN_BYTES) {
|
|
261
|
+
return {
|
|
262
|
+
...base,
|
|
263
|
+
evaluated: false,
|
|
264
|
+
out_of_distribution: false,
|
|
265
|
+
decision: "not_evaluated",
|
|
266
|
+
reason: "prompt_below_large_prompt_floor"
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
if (profile.normal_bytes === 0 || profile.multibyte_bytes > profile.normal_bytes) {
|
|
270
|
+
return {
|
|
271
|
+
...base,
|
|
272
|
+
evaluated: false,
|
|
273
|
+
out_of_distribution: false,
|
|
274
|
+
decision: "not_evaluated",
|
|
275
|
+
reason: "multibyte_or_non_ascii_dominant"
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
if (!profile.whitespace_fraction_available || profile.whitespace_fraction_x10000 === null) {
|
|
279
|
+
return {
|
|
280
|
+
...base,
|
|
281
|
+
evaluated: true,
|
|
282
|
+
out_of_distribution: true,
|
|
283
|
+
decision: "conservative_fallback",
|
|
284
|
+
reason: "whitespace_fraction_unavailable"
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
if (profile.whitespace_fraction_x10000 < TOKEN_BUDGET_DENSE_ASCII_WHITESPACE_THRESHOLD_X10000) {
|
|
288
|
+
return {
|
|
289
|
+
...base,
|
|
290
|
+
evaluated: true,
|
|
291
|
+
out_of_distribution: true,
|
|
292
|
+
decision: "conservative_fallback",
|
|
293
|
+
reason: "below_threshold"
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
return {
|
|
297
|
+
...base,
|
|
298
|
+
evaluated: true,
|
|
299
|
+
out_of_distribution: false,
|
|
300
|
+
decision: "calibrated_allowed",
|
|
301
|
+
reason: "at_or_above_threshold"
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
__name(denseAsciiGate, "denseAsciiGate");
|
|
305
|
+
function rateSourceWarning(input) {
|
|
306
|
+
if (input.source === "unknown_provider_floor") {
|
|
307
|
+
return `unknown provider family uses the provable 1.00 B/tok floor; no calibration backs ${input.family}`;
|
|
308
|
+
}
|
|
309
|
+
if (input.source === "unbacked_model_floor") {
|
|
310
|
+
return `model is not in the exact calibration backing set for family ${input.family}; using the provable 1.00 B/tok floor`;
|
|
311
|
+
}
|
|
312
|
+
if (input.source === "delegate_conservative") {
|
|
313
|
+
return "delegate launch/runtime uses the provable 1.00 B/tok profile when the prompt or route is below the backed large-prompt calibration domain";
|
|
314
|
+
}
|
|
315
|
+
if (input.source === "explicit_conservative") {
|
|
316
|
+
return "explicit conservative scope uses the provable 1.00 B/tok profile";
|
|
317
|
+
}
|
|
318
|
+
if (input.source === "conservative_small_prompt") {
|
|
319
|
+
return `calibrated rate withheld because measured prompt bytes ${String(input.profile.concrete_known_bytes)} are below the ${String(TOKEN_BUDGET_LARGE_PROMPT_MIN_BYTES)}-byte calibration floor; using conservative profile`;
|
|
320
|
+
}
|
|
321
|
+
if (input.source === "conservative_capacity_guard") {
|
|
322
|
+
return `calibrated rate withheld because route capacity evaluated at the conservative rate cannot hold the ${String(TOKEN_BUDGET_LARGE_PROMPT_MIN_BYTES)}-byte calibration floor`;
|
|
323
|
+
}
|
|
324
|
+
if (input.source === "conservative_dense_ascii_whitespace_gate") {
|
|
325
|
+
if (input.gate.reason === "whitespace_fraction_unavailable") {
|
|
326
|
+
return "calibrated rate withheld because known-text whitespace bytes were not supplied; provide asciiWhitespaceBytes from a one-pass UTF-8 measurement to use calibrated rates";
|
|
327
|
+
}
|
|
328
|
+
return `calibrated rate withheld because whitespace fraction ${String(input.gate.measured_whitespace_fraction_x10000 ?? 0)}/${String(TOKEN_BUDGET_WHITESPACE_FRACTION_SCALE)} is below the dense-ASCII gate ${String(TOKEN_BUDGET_DENSE_ASCII_WHITESPACE_THRESHOLD_X10000)}/${String(TOKEN_BUDGET_WHITESPACE_FRACTION_SCALE)}; this is a heuristic token-density proxy, not a bound`;
|
|
329
|
+
}
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
__name(rateSourceWarning, "rateSourceWarning");
|
|
333
|
+
function effectiveRateSource(input) {
|
|
334
|
+
const calibration = calibrationFor(input.family);
|
|
335
|
+
const configured = calibration.rate_bytes_per_token_x100;
|
|
336
|
+
const familyBacked = calibration.provenance.backed;
|
|
337
|
+
const backed = familyBacked && input.calibrationBacked;
|
|
338
|
+
const conservativeRate = conservativeFusionRate(configured);
|
|
339
|
+
const gate = denseAsciiGate(input.profile);
|
|
340
|
+
let source;
|
|
341
|
+
let effective;
|
|
342
|
+
let calibrationApplied = false;
|
|
343
|
+
if (!backed) {
|
|
344
|
+
source = input.familyResolution === "known_provider_unbacked_model" ? "unbacked_model_floor" : "unknown_provider_floor";
|
|
345
|
+
effective = TOKEN_BUDGET_PROVABLE_RATE_X100;
|
|
346
|
+
} else if (input.scope === "delegate" || input.scope === "delegate_launch" && (input.profile.concrete_known_bytes < TOKEN_BUDGET_LARGE_PROMPT_MIN_BYTES || input.allowedInputTokens !== void 0 && Math.floor(
|
|
347
|
+
input.allowedInputTokens * TOKEN_BUDGET_DELEGATE_CONSERVATIVE_RATE_X100 / TOKEN_BUDGET_RATE_SCALE
|
|
348
|
+
) < TOKEN_BUDGET_LARGE_PROMPT_MIN_BYTES)) {
|
|
349
|
+
source = "delegate_conservative";
|
|
350
|
+
effective = Math.min(configured, TOKEN_BUDGET_DELEGATE_CONSERVATIVE_RATE_X100);
|
|
351
|
+
} else if (input.scope === "conservative") {
|
|
352
|
+
source = "explicit_conservative";
|
|
353
|
+
effective = Math.min(configured, TOKEN_BUDGET_PROVABLE_RATE_X100);
|
|
354
|
+
} else if (input.profile.concrete_known_bytes < TOKEN_BUDGET_LARGE_PROMPT_MIN_BYTES) {
|
|
355
|
+
source = "conservative_small_prompt";
|
|
356
|
+
effective = conservativeRate;
|
|
357
|
+
} else if (input.allowedInputTokens !== void 0 && Math.floor(input.allowedInputTokens * conservativeRate / TOKEN_BUDGET_RATE_SCALE) < TOKEN_BUDGET_LARGE_PROMPT_MIN_BYTES) {
|
|
358
|
+
assertSafeNonNegativeInteger(input.allowedInputTokens, "allowedInputTokens");
|
|
359
|
+
source = "conservative_capacity_guard";
|
|
360
|
+
effective = conservativeRate;
|
|
361
|
+
} else if (gate.out_of_distribution) {
|
|
362
|
+
source = "conservative_dense_ascii_whitespace_gate";
|
|
363
|
+
effective = conservativeRate;
|
|
364
|
+
} else {
|
|
365
|
+
source = "calibrated_large_window";
|
|
366
|
+
effective = configured;
|
|
367
|
+
calibrationApplied = true;
|
|
368
|
+
}
|
|
369
|
+
const dominant = gate.out_of_distribution && input.profile.normal_bytes >= input.profile.multibyte_bytes ? "dense_ascii" : input.profile.dominant_byte_class;
|
|
370
|
+
const rateSourceInput = {
|
|
371
|
+
source,
|
|
372
|
+
family: input.family,
|
|
373
|
+
profile: input.profile,
|
|
374
|
+
gate,
|
|
375
|
+
scope: input.scope
|
|
376
|
+
};
|
|
377
|
+
return {
|
|
378
|
+
calibration_version: TOKEN_BUDGET_CALIBRATION_VERSION,
|
|
379
|
+
family: input.family,
|
|
380
|
+
configured_rate_bytes_per_token_x100: configured,
|
|
381
|
+
effective_rate_bytes_per_token_x100: effective,
|
|
382
|
+
conservative_rate_bytes_per_token_x100: conservativeRate,
|
|
383
|
+
delegate_conservative_rate_bytes_per_token_x100: TOKEN_BUDGET_DELEGATE_CONSERVATIVE_RATE_X100,
|
|
384
|
+
affine_f_tokens: calibration.affine_f_tokens,
|
|
385
|
+
scope: input.scope,
|
|
386
|
+
source,
|
|
387
|
+
backed,
|
|
388
|
+
provenance: calibration.provenance,
|
|
389
|
+
model_resolution: input.familyResolution,
|
|
390
|
+
scope_guard_min_bytes: TOKEN_BUDGET_LARGE_PROMPT_MIN_BYTES,
|
|
391
|
+
calibration_applied: calibrationApplied,
|
|
392
|
+
prompt_profile: { ...input.profile, dominant_byte_class: dominant },
|
|
393
|
+
dense_ascii_gate: gate,
|
|
394
|
+
dominant_byte_class: dominant,
|
|
395
|
+
warning: rateSourceWarning(rateSourceInput)
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
__name(effectiveRateSource, "effectiveRateSource");
|
|
399
|
+
function addBucket(buckets, rate, bytes, byteClass) {
|
|
400
|
+
if (bytes === 0) return;
|
|
401
|
+
const existing = buckets.get(rate);
|
|
402
|
+
if (existing === void 0) {
|
|
403
|
+
buckets.set(rate, { rate, bytes, classes: [byteClass] });
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
existing.bytes += bytes;
|
|
407
|
+
if (!existing.classes.includes(byteClass)) existing.classes.push(byteClass);
|
|
408
|
+
}
|
|
409
|
+
__name(addBucket, "addBucket");
|
|
410
|
+
function finalizeBuckets(buckets) {
|
|
411
|
+
return [...buckets.values()].sort((left, right) => left.rate - right.rate).map((bucket) => ({
|
|
412
|
+
rate_bytes_per_token_x100: bucket.rate,
|
|
413
|
+
bytes: bucket.bytes,
|
|
414
|
+
tokens: tokensAtRate(bucket.bytes, bucket.rate),
|
|
415
|
+
byte_classes: [...bucket.classes].sort()
|
|
416
|
+
}));
|
|
417
|
+
}
|
|
418
|
+
__name(finalizeBuckets, "finalizeBuckets");
|
|
419
|
+
function bucketTokenTotal(buckets) {
|
|
420
|
+
return buckets.reduce((sum, bucket) => sum + bucket.tokens, 0);
|
|
421
|
+
}
|
|
422
|
+
__name(bucketTokenTotal, "bucketTokenTotal");
|
|
423
|
+
function estimateInputTokens(input) {
|
|
424
|
+
const scope = input.scope ?? "fusion";
|
|
425
|
+
const normalized = [];
|
|
426
|
+
const total = {
|
|
427
|
+
total_bytes: 0,
|
|
428
|
+
normal_bytes: 0,
|
|
429
|
+
multibyte_bytes: 0,
|
|
430
|
+
dense_bytes: 0,
|
|
431
|
+
unknown_output_contract_bytes: 0
|
|
432
|
+
};
|
|
433
|
+
for (const [index, rawSegment] of input.segments.entries()) {
|
|
434
|
+
const segment = normalizeSegment(rawSegment, index);
|
|
435
|
+
const unknownBytes = segment.kind === "unknown_output_contract" ? segment.bytes : 0;
|
|
436
|
+
const normalBytes = segment.kind === "unknown_output_contract" ? 0 : segment.bytes - segment.multibyteBytes - segment.denseBytes;
|
|
437
|
+
const breakdown = {
|
|
438
|
+
total_bytes: segment.bytes,
|
|
439
|
+
normal_bytes: normalBytes,
|
|
440
|
+
multibyte_bytes: segment.multibyteBytes,
|
|
441
|
+
dense_bytes: segment.denseBytes,
|
|
442
|
+
unknown_output_contract_bytes: unknownBytes
|
|
443
|
+
};
|
|
444
|
+
addBreakdown(total, breakdown);
|
|
445
|
+
normalized.push(segment);
|
|
446
|
+
}
|
|
447
|
+
if (input.allowedInputTokens !== void 0) {
|
|
448
|
+
assertSafeNonNegativeInteger(input.allowedInputTokens, "allowedInputTokens");
|
|
449
|
+
}
|
|
450
|
+
const profile = profileForSegments(normalized, total);
|
|
451
|
+
const rateSource = effectiveRateSource({
|
|
452
|
+
family: input.family,
|
|
453
|
+
allowedInputTokens: input.allowedInputTokens,
|
|
454
|
+
scope,
|
|
455
|
+
profile,
|
|
456
|
+
calibrationBacked: input.calibrationBacked ?? true,
|
|
457
|
+
familyResolution: input.familyResolution ?? "family_direct"
|
|
458
|
+
});
|
|
459
|
+
const perSegment = [];
|
|
460
|
+
const fatalBuckets = /* @__PURE__ */ new Map();
|
|
461
|
+
const advisoryBuckets = /* @__PURE__ */ new Map();
|
|
462
|
+
let multibyteAdvisoryTotal = 0;
|
|
463
|
+
for (const segment of normalized) {
|
|
464
|
+
const unknownBytes = segment.kind === "unknown_output_contract" ? segment.bytes : 0;
|
|
465
|
+
const normalBytes = segment.kind === "unknown_output_contract" ? 0 : segment.bytes - segment.multibyteBytes - segment.denseBytes;
|
|
466
|
+
const normalRate = segment.kind === "unknown_output_contract" ? TOKEN_BUDGET_PROVABLE_RATE_X100 : rateSource.effective_rate_bytes_per_token_x100;
|
|
467
|
+
const normalTokens = tokensAtRate(normalBytes, normalRate);
|
|
468
|
+
const unknownTokens = tokensAtRate(unknownBytes, TOKEN_BUDGET_PROVABLE_RATE_X100);
|
|
469
|
+
const multibyteTokens = tokensAtRate(segment.multibyteBytes, TOKEN_BUDGET_MULTIBYTE_FATAL_RATE_X100);
|
|
470
|
+
const multibyteProvableTokens = tokensAtRate(segment.multibyteBytes, TOKEN_BUDGET_PROVABLE_RATE_X100);
|
|
471
|
+
const denseTokens = tokensAtRate(segment.denseBytes, TOKEN_BUDGET_PROVABLE_RATE_X100);
|
|
472
|
+
const tokens = normalTokens + unknownTokens + multibyteTokens + denseTokens;
|
|
473
|
+
const breakdown = {
|
|
474
|
+
total_bytes: segment.bytes,
|
|
475
|
+
normal_bytes: normalBytes,
|
|
476
|
+
multibyte_bytes: segment.multibyteBytes,
|
|
477
|
+
dense_bytes: segment.denseBytes,
|
|
478
|
+
unknown_output_contract_bytes: unknownBytes
|
|
479
|
+
};
|
|
480
|
+
addBucket(fatalBuckets, normalRate, normalBytes, "normal");
|
|
481
|
+
addBucket(fatalBuckets, TOKEN_BUDGET_MULTIBYTE_FATAL_RATE_X100, segment.multibyteBytes, "multibyte");
|
|
482
|
+
addBucket(fatalBuckets, TOKEN_BUDGET_PROVABLE_RATE_X100, segment.denseBytes, "dense_ascii");
|
|
483
|
+
addBucket(fatalBuckets, TOKEN_BUDGET_PROVABLE_RATE_X100, unknownBytes, "unknown_output_contract");
|
|
484
|
+
addBucket(advisoryBuckets, normalRate, normalBytes, "normal");
|
|
485
|
+
addBucket(advisoryBuckets, TOKEN_BUDGET_PROVABLE_RATE_X100, segment.multibyteBytes, "multibyte");
|
|
486
|
+
addBucket(advisoryBuckets, TOKEN_BUDGET_PROVABLE_RATE_X100, segment.denseBytes, "dense_ascii");
|
|
487
|
+
addBucket(advisoryBuckets, TOKEN_BUDGET_PROVABLE_RATE_X100, unknownBytes, "unknown_output_contract");
|
|
488
|
+
multibyteAdvisoryTotal += multibyteProvableTokens;
|
|
489
|
+
perSegment.push({
|
|
490
|
+
kind: segment.kind,
|
|
491
|
+
...breakdown,
|
|
492
|
+
ascii_whitespace_bytes: segment.asciiWhitespaceBytes,
|
|
493
|
+
normal_rate_bytes_per_token_x100: normalRate,
|
|
494
|
+
normal_tokens: normalTokens,
|
|
495
|
+
multibyte_rate_bytes_per_token_x100: TOKEN_BUDGET_MULTIBYTE_FATAL_RATE_X100,
|
|
496
|
+
multibyte_tokens: multibyteTokens,
|
|
497
|
+
multibyte_provable_tokens: multibyteProvableTokens,
|
|
498
|
+
dense_tokens: denseTokens,
|
|
499
|
+
unknown_output_contract_tokens: unknownTokens,
|
|
500
|
+
tokens
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
const rateBuckets = finalizeBuckets(fatalBuckets);
|
|
504
|
+
const advisoryRateBuckets = finalizeBuckets(advisoryBuckets);
|
|
505
|
+
const variableTokenTotal = bucketTokenTotal(rateBuckets);
|
|
506
|
+
return {
|
|
507
|
+
tokens: variableTokenTotal + rateSource.affine_f_tokens,
|
|
508
|
+
fixed_tokens: rateSource.affine_f_tokens,
|
|
509
|
+
perSegment,
|
|
510
|
+
byte_class_breakdown: total,
|
|
511
|
+
rate_buckets: rateBuckets,
|
|
512
|
+
advisory: {
|
|
513
|
+
multibyte_provable_rate_bytes_per_token_x100: TOKEN_BUDGET_PROVABLE_RATE_X100,
|
|
514
|
+
multibyte_provable_tokens: multibyteAdvisoryTotal,
|
|
515
|
+
input_tokens_if_multibyte_used_provable_ceiling: bucketTokenTotal(advisoryRateBuckets) + rateSource.affine_f_tokens,
|
|
516
|
+
rate_buckets: advisoryRateBuckets
|
|
517
|
+
},
|
|
518
|
+
rateSource
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
__name(estimateInputTokens, "estimateInputTokens");
|
|
522
|
+
function isAsciiWhitespace(byte) {
|
|
523
|
+
return byte === 32 || byte >= 9 && byte <= 13;
|
|
524
|
+
}
|
|
525
|
+
__name(isAsciiWhitespace, "isAsciiWhitespace");
|
|
526
|
+
function utf8ByteClassBreakdown(value) {
|
|
527
|
+
const bytes = Buffer.from(value, "utf8");
|
|
528
|
+
let multibyteBytes = 0;
|
|
529
|
+
let asciiWhitespaceBytes = 0;
|
|
530
|
+
for (const byte of bytes) {
|
|
531
|
+
if (byte >= 128) multibyteBytes += 1;
|
|
532
|
+
else if (isAsciiWhitespace(byte)) asciiWhitespaceBytes += 1;
|
|
533
|
+
}
|
|
534
|
+
return { bytes: bytes.length, multibyteBytes, denseBytes: 0, asciiWhitespaceBytes };
|
|
535
|
+
}
|
|
536
|
+
__name(utf8ByteClassBreakdown, "utf8ByteClassBreakdown");
|
|
537
|
+
function knownTextSegment(value) {
|
|
538
|
+
const breakdown = utf8ByteClassBreakdown(value);
|
|
539
|
+
return {
|
|
540
|
+
kind: "known_text",
|
|
541
|
+
bytes: breakdown.bytes,
|
|
542
|
+
multibyteBytes: breakdown.multibyteBytes,
|
|
543
|
+
denseBytes: breakdown.denseBytes,
|
|
544
|
+
asciiWhitespaceBytes: breakdown.asciiWhitespaceBytes
|
|
545
|
+
};
|
|
546
|
+
}
|
|
547
|
+
__name(knownTextSegment, "knownTextSegment");
|
|
548
|
+
function unknownOutputContractSegment(bytes) {
|
|
549
|
+
assertSafeNonNegativeInteger(bytes, "unknown output contract bytes");
|
|
550
|
+
return { kind: "unknown_output_contract", bytes, denseBytes: 0 };
|
|
551
|
+
}
|
|
552
|
+
__name(unknownOutputContractSegment, "unknownOutputContractSegment");
|
|
553
|
+
function maxKnownTextBytesForTokens(input) {
|
|
554
|
+
assertSafeNonNegativeInteger(input.allowedInputTokens, "allowedInputTokens");
|
|
555
|
+
const rate = effectiveRateSource({
|
|
556
|
+
family: input.family,
|
|
557
|
+
allowedInputTokens: input.allowedInputTokens,
|
|
558
|
+
scope: input.scope ?? "fusion",
|
|
559
|
+
profile: profileForSegments([], {
|
|
560
|
+
total_bytes: 0,
|
|
561
|
+
normal_bytes: 0,
|
|
562
|
+
multibyte_bytes: 0,
|
|
563
|
+
dense_bytes: 0,
|
|
564
|
+
unknown_output_contract_bytes: 0
|
|
565
|
+
}),
|
|
566
|
+
calibrationBacked: input.calibrationBacked ?? true,
|
|
567
|
+
familyResolution: input.familyResolution ?? "family_direct"
|
|
568
|
+
});
|
|
569
|
+
const variableTokens = input.allowedInputTokens - rate.affine_f_tokens;
|
|
570
|
+
if (variableTokens <= 0) return 0;
|
|
571
|
+
return Math.floor(variableTokens * rate.effective_rate_bytes_per_token_x100 / TOKEN_BUDGET_RATE_SCALE);
|
|
572
|
+
}
|
|
573
|
+
__name(maxKnownTextBytesForTokens, "maxKnownTextBytesForTokens");
|
|
574
|
+
function allowedInputTokens(contextWindowTokens, reserves) {
|
|
575
|
+
return contextWindowTokens - reserves.reservedOutputTokens - reserves.framingReserveTokens - reserves.safetyReserveTokens;
|
|
576
|
+
}
|
|
577
|
+
__name(allowedInputTokens, "allowedInputTokens");
|
|
578
|
+
function isUsableContextWindow(value) {
|
|
579
|
+
return Number.isFinite(value) && Number.isInteger(value) && value > 0;
|
|
580
|
+
}
|
|
581
|
+
__name(isUsableContextWindow, "isUsableContextWindow");
|
|
582
|
+
|
|
583
|
+
export {
|
|
584
|
+
TOKEN_BUDGET_CALIBRATION_VERSION,
|
|
585
|
+
TOKEN_BUDGET_RATE_SCALE,
|
|
586
|
+
TOKEN_BUDGET_LARGE_PROMPT_MIN_BYTES,
|
|
587
|
+
TOKEN_BUDGET_AFFINE_F_TOKENS,
|
|
588
|
+
TOKEN_BUDGET_FAMILY_CALIBRATIONS,
|
|
589
|
+
resolveTokenBudgetFamily,
|
|
590
|
+
estimateInputTokens,
|
|
591
|
+
utf8ByteClassBreakdown,
|
|
592
|
+
knownTextSegment,
|
|
593
|
+
unknownOutputContractSegment,
|
|
594
|
+
maxKnownTextBytesForTokens,
|
|
595
|
+
allowedInputTokens,
|
|
596
|
+
isUsableContextWindow
|
|
597
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import{createRequire as __pvCR}from"node:module";import{fileURLToPath as __pvF}from"node:url";import{dirname as __pvD}from"node:path";const require=__pvCR(import.meta.url);const __pvUrl=(r)=>new URL(r,import.meta.url).href;const __pvFile=(r)=>__pvF(new URL(r,import.meta.url));
|
|
2
|
+
import {
|
|
3
|
+
__name
|
|
4
|
+
} from "./c-CN77DCGF.mjs";
|
|
5
|
+
|
|
6
|
+
// node_modules/@earendil-works/pi-ai/dist/api/openai-prompt-cache.js
|
|
7
|
+
var OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH = 64;
|
|
8
|
+
function clampOpenAIPromptCacheKey(key) {
|
|
9
|
+
if (key === void 0)
|
|
10
|
+
return void 0;
|
|
11
|
+
const chars = Array.from(key);
|
|
12
|
+
if (chars.length <= OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH)
|
|
13
|
+
return key;
|
|
14
|
+
return chars.slice(0, OPENAI_PROMPT_CACHE_KEY_MAX_LENGTH).join("");
|
|
15
|
+
}
|
|
16
|
+
__name(clampOpenAIPromptCacheKey, "clampOpenAIPromptCacheKey");
|
|
17
|
+
|
|
18
|
+
export {
|
|
19
|
+
clampOpenAIPromptCacheKey
|
|
20
|
+
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import{createRequire as __pvCR}from"node:module";import{fileURLToPath as __pvF}from"node:url";import{dirname as __pvD}from"node:path";const require=__pvCR(import.meta.url);const __pvUrl=(r)=>new URL(r,import.meta.url).href;const __pvFile=(r)=>__pvF(new URL(r,import.meta.url));
|
|
2
|
+
import {
|
|
3
|
+
__name
|
|
4
|
+
} from "./c-CN77DCGF.mjs";
|
|
5
|
+
|
|
6
|
+
// node_modules/@earendil-works/pi-ai/dist/api/github-copilot-headers.js
|
|
7
|
+
function inferCopilotInitiator(messages) {
|
|
8
|
+
const last = messages[messages.length - 1];
|
|
9
|
+
return last && last.role !== "user" ? "agent" : "user";
|
|
10
|
+
}
|
|
11
|
+
__name(inferCopilotInitiator, "inferCopilotInitiator");
|
|
12
|
+
function hasCopilotVisionInput(messages) {
|
|
13
|
+
return messages.some((msg) => {
|
|
14
|
+
if (msg.role === "user" && Array.isArray(msg.content)) {
|
|
15
|
+
return msg.content.some((c) => c.type === "image");
|
|
16
|
+
}
|
|
17
|
+
if (msg.role === "toolResult" && Array.isArray(msg.content)) {
|
|
18
|
+
return msg.content.some((c) => c.type === "image");
|
|
19
|
+
}
|
|
20
|
+
return false;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
__name(hasCopilotVisionInput, "hasCopilotVisionInput");
|
|
24
|
+
function buildCopilotDynamicHeaders(params) {
|
|
25
|
+
const headers = {
|
|
26
|
+
"X-Initiator": inferCopilotInitiator(params.messages),
|
|
27
|
+
"Openai-Intent": "conversation-edits"
|
|
28
|
+
};
|
|
29
|
+
if (params.hasImages) {
|
|
30
|
+
headers["Copilot-Vision-Request"] = "true";
|
|
31
|
+
}
|
|
32
|
+
return headers;
|
|
33
|
+
}
|
|
34
|
+
__name(buildCopilotDynamicHeaders, "buildCopilotDynamicHeaders");
|
|
35
|
+
|
|
36
|
+
export {
|
|
37
|
+
hasCopilotVisionInput,
|
|
38
|
+
buildCopilotDynamicHeaders
|
|
39
|
+
};
|