@sriinnu/fiche 0.18.0-bootstrap.0 → 0.19.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 +134 -0
- package/LICENSE +22 -0
- package/NOTICE +13 -0
- package/PRIVACY.md +41 -0
- package/README.md +289 -0
- package/SECURITY.md +53 -0
- package/assets/JETBRAINS_MONO_LICENSE.txt +89 -0
- package/assets/SPLEEN_LICENSE.txt +24 -0
- package/assets/UNIFONT_LICENSE.txt +476 -0
- package/assets/fiche-logo-dark.svg +61 -0
- package/assets/fiche-logo-light.svg +61 -0
- package/assets/fiche-logo.svg +71 -0
- package/assets/fiche-mark.svg +48 -0
- package/bin/cli.js +7 -0
- package/bin/mcp.js +8 -0
- package/dist/calibrate.d.ts +30 -0
- package/dist/calibrate.js +588 -0
- package/dist/core/anthropic-vision.d.ts +28 -0
- package/dist/core/anthropic-vision.js +34 -0
- package/dist/core/applicability.d.ts +63 -0
- package/dist/core/applicability.js +151 -0
- package/dist/core/atlas-gray-jbmono10.d.ts +26 -0
- package/dist/core/atlas-gray-jbmono10.js +64 -0
- package/dist/core/atlas-gray-jbmono12.d.ts +26 -0
- package/dist/core/atlas-gray-jbmono12.js +64 -0
- package/dist/core/atlas-gray-jbmono14.d.ts +26 -0
- package/dist/core/atlas-gray-jbmono14.js +64 -0
- package/dist/core/atlas-gray.d.ts +26 -0
- package/dist/core/atlas-gray.js +64 -0
- package/dist/core/atlas-jbmono10.d.ts +34 -0
- package/dist/core/atlas-jbmono10.js +71 -0
- package/dist/core/atlas-jbmono12.d.ts +34 -0
- package/dist/core/atlas-jbmono12.js +71 -0
- package/dist/core/atlas-jbmono14.d.ts +34 -0
- package/dist/core/atlas-jbmono14.js +71 -0
- package/dist/core/atlas.d.ts +34 -0
- package/dist/core/atlas.js +71 -0
- package/dist/core/baseline.d.ts +121 -0
- package/dist/core/baseline.js +200 -0
- package/dist/core/calibration.d.ts +86 -0
- package/dist/core/calibration.js +547 -0
- package/dist/core/casi-delta.d.ts +63 -0
- package/dist/core/casi-delta.js +1271 -0
- package/dist/core/claude-model-profiles.d.ts +53 -0
- package/dist/core/claude-model-profiles.js +160 -0
- package/dist/core/client-tool-round.d.ts +31 -0
- package/dist/core/client-tool-round.js +58 -0
- package/dist/core/codex-cache.d.ts +20 -0
- package/dist/core/codex-cache.js +59 -0
- package/dist/core/context-mmu.d.ts +350 -0
- package/dist/core/context-mmu.js +3028 -0
- package/dist/core/cpt-fit.d.ts +70 -0
- package/dist/core/cpt-fit.js +197 -0
- package/dist/core/env.d.ts +8 -0
- package/dist/core/env.js +15 -0
- package/dist/core/export.d.ts +127 -0
- package/dist/core/export.js +385 -0
- package/dist/core/factsheet.d.ts +77 -0
- package/dist/core/factsheet.js +494 -0
- package/dist/core/gemini-model-profiles.d.ts +20 -0
- package/dist/core/gemini-model-profiles.js +134 -0
- package/dist/core/google.d.ts +76 -0
- package/dist/core/google.js +1380 -0
- package/dist/core/gpt-model-profiles.d.ts +218 -0
- package/dist/core/gpt-model-profiles.js +570 -0
- package/dist/core/gpt-tokens.d.ts +14 -0
- package/dist/core/gpt-tokens.js +165 -0
- package/dist/core/history.d.ts +197 -0
- package/dist/core/history.js +1003 -0
- package/dist/core/index.d.ts +16 -0
- package/dist/core/index.js +16 -0
- package/dist/core/library.d.ts +80 -0
- package/dist/core/library.js +131 -0
- package/dist/core/measurement.d.ts +34 -0
- package/dist/core/measurement.js +280 -0
- package/dist/core/messages-chat-bridge.d.ts +23 -0
- package/dist/core/messages-chat-bridge.js +747 -0
- package/dist/core/messages-responses-bridge.d.ts +11 -0
- package/dist/core/messages-responses-bridge.js +893 -0
- package/dist/core/openai-history.d.ts +184 -0
- package/dist/core/openai-history.js +1279 -0
- package/dist/core/openai-savings.d.ts +57 -0
- package/dist/core/openai-savings.js +116 -0
- package/dist/core/openai.d.ts +68 -0
- package/dist/core/openai.js +2523 -0
- package/dist/core/pin.d.ts +199 -0
- package/dist/core/pin.js +1353 -0
- package/dist/core/png.d.ts +14 -0
- package/dist/core/png.js +188 -0
- package/dist/core/prefix-tape.d.ts +102 -0
- package/dist/core/prefix-tape.js +315 -0
- package/dist/core/price-id.d.ts +10 -0
- package/dist/core/price-id.js +26 -0
- package/dist/core/prices.generated.d.ts +36 -0
- package/dist/core/prices.generated.js +369 -0
- package/dist/core/pricing.d.ts +134 -0
- package/dist/core/pricing.js +335 -0
- package/dist/core/profile-base.d.ts +30 -0
- package/dist/core/profile-base.js +67 -0
- package/dist/core/provider-router.d.ts +51 -0
- package/dist/core/provider-router.js +121 -0
- package/dist/core/proxy.d.ts +252 -0
- package/dist/core/proxy.js +2929 -0
- package/dist/core/reader-tier.d.ts +24 -0
- package/dist/core/reader-tier.js +118 -0
- package/dist/core/render.d.ts +280 -0
- package/dist/core/render.js +1302 -0
- package/dist/core/request-guard.d.ts +31 -0
- package/dist/core/request-guard.js +126 -0
- package/dist/core/request-transform.d.ts +43 -0
- package/dist/core/request-transform.js +173 -0
- package/dist/core/schema-compiler.d.ts +64 -0
- package/dist/core/schema-compiler.js +1696 -0
- package/dist/core/schema-strip.d.ts +29 -0
- package/dist/core/schema-strip.js +173 -0
- package/dist/core/session-state.d.ts +219 -0
- package/dist/core/session-state.js +929 -0
- package/dist/core/stage-plugins.d.ts +45 -0
- package/dist/core/stage-plugins.js +205 -0
- package/dist/core/text-history.d.ts +74 -0
- package/dist/core/text-history.js +612 -0
- package/dist/core/text-hygiene.d.ts +160 -0
- package/dist/core/text-hygiene.js +2259 -0
- package/dist/core/toon.d.ts +29 -0
- package/dist/core/toon.js +425 -0
- package/dist/core/tracker.d.ts +223 -0
- package/dist/core/tracker.js +290 -0
- package/dist/core/transform.d.ts +589 -0
- package/dist/core/transform.js +3153 -0
- package/dist/core/types.d.ts +87 -0
- package/dist/core/types.js +8 -0
- package/dist/core/upstream-hosts.d.ts +127 -0
- package/dist/core/upstream-hosts.js +398 -0
- package/dist/core/vision-cost.d.ts +63 -0
- package/dist/core/vision-cost.js +137 -0
- package/dist/dashboard/fragments.d.ts +87 -0
- package/dist/dashboard/fragments.js +1515 -0
- package/dist/dashboard/types.d.ts +217 -0
- package/dist/dashboard/types.js +3 -0
- package/dist/dashboard/vendor.d.ts +3 -0
- package/dist/dashboard/vendor.js +6 -0
- package/dist/dashboard.d.ts +372 -0
- package/dist/dashboard.js +2731 -0
- package/dist/export-collect.d.ts +36 -0
- package/dist/export-collect.js +59 -0
- package/dist/file-tracker.d.ts +42 -0
- package/dist/file-tracker.js +234 -0
- package/dist/kosha-sync.d.ts +74 -0
- package/dist/kosha-sync.js +272 -0
- package/dist/launchd-socket.d.ts +22 -0
- package/dist/launchd-socket.js +210 -0
- package/dist/mcp/cli.d.ts +2 -0
- package/dist/mcp/cli.js +55 -0
- package/dist/mcp/server.d.ts +48 -0
- package/dist/mcp/server.js +987 -0
- package/dist/mmu-store.d.ts +31 -0
- package/dist/mmu-store.js +179 -0
- package/dist/node-fetch.d.ts +22 -0
- package/dist/node-fetch.js +489 -0
- package/dist/node.d.ts +9 -0
- package/dist/node.js +244396 -0
- package/dist/request-decoding.d.ts +30 -0
- package/dist/request-decoding.js +85 -0
- package/dist/sessions.d.ts +179 -0
- package/dist/sessions.js +837 -0
- package/dist/stats.d.ts +114 -0
- package/dist/stats.js +439 -0
- package/dist/turn-report.d.ts +65 -0
- package/dist/turn-report.js +724 -0
- package/dist/warp/app-launch.d.ts +26 -0
- package/dist/warp/app-launch.js +155 -0
- package/dist/warp/ca.d.ts +74 -0
- package/dist/warp/ca.js +416 -0
- package/dist/warp/connect.d.ts +42 -0
- package/dist/warp/connect.js +686 -0
- package/dist/warp/der.d.ts +57 -0
- package/dist/warp/der.js +151 -0
- package/dist/warp/index.d.ts +79 -0
- package/dist/warp/index.js +650 -0
- package/dist/warp/resolve.d.ts +12 -0
- package/dist/warp/resolve.js +49 -0
- package/dist/warp/route.d.ts +71 -0
- package/dist/warp/route.js +134 -0
- package/dist/worker.d.ts +71 -0
- package/dist/worker.js +174 -0
- package/docs/SECURITY_MODEL.md +84 -0
- package/package.json +115 -3
- package/plugins/fiche-companion/README.md +42 -0
- package/plugins/fiche-companion/assets/logo.svg +48 -0
- package/plugins/fiche-companion/hooks.json +11 -0
- package/plugins/fiche-companion/mcp_config.json +8 -0
- package/plugins/fiche-companion/plugin.json +18 -0
- package/plugins/fiche-companion/scripts/claude-statusline.mjs +35 -0
- package/plugins/fiche-companion/scripts/post-invocation.mjs +122 -0
- package/plugins/fiche-companion/scripts/resolve-turn-report.mjs +132 -0
- package/plugins/fiche-companion/skills/fiche/SKILL.md +61 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal PNG encoder (grayscale + RGB, 8-bit, filter=Average, single IDAT).
|
|
3
|
+
* Pure Uint8Array — uses CompressionStream (Node 18+, Workers, browsers); no Buffer/node:zlib.
|
|
4
|
+
*/
|
|
5
|
+
/** Encode a single-channel (grayscale) buffer as PNG bytes. pixels is row-major, length = width × height. */
|
|
6
|
+
export declare function encodeGrayPng(pixels: Uint8Array, width: number, height: number): Promise<Uint8Array>;
|
|
7
|
+
/** Encode an RGB (3 bytes/pixel, R,G,B) buffer as PNG bytes (colorType 2 = truecolor). length = width × height × 3. */
|
|
8
|
+
export declare function encodeRgbPng(pixels: Uint8Array, width: number, height: number): Promise<Uint8Array>;
|
|
9
|
+
/**
|
|
10
|
+
* Base64-encode PNG bytes. Prefers native V8 `Uint8Array.prototype.toBase64` (~100x faster
|
|
11
|
+
* than char-by-char `btoa`) and memoizes the JS fallback on immutable pixel buffers.
|
|
12
|
+
*/
|
|
13
|
+
export declare function bytesToBase64(bytes: Uint8Array): string;
|
|
14
|
+
//# sourceMappingURL=png.d.ts.map
|
package/dist/core/png.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal PNG encoder (grayscale + RGB, 8-bit, filter=Average, single IDAT).
|
|
3
|
+
* Pure Uint8Array — uses CompressionStream (Node 18+, Workers, browsers); no Buffer/node:zlib.
|
|
4
|
+
*/
|
|
5
|
+
// ---- CRC32 ---------------------------------------------------------------
|
|
6
|
+
const CRC_TABLE = (() => {
|
|
7
|
+
const t = new Uint32Array(256);
|
|
8
|
+
for (let n = 0; n < 256; n++) {
|
|
9
|
+
let c = n;
|
|
10
|
+
for (let k = 0; k < 8; k++)
|
|
11
|
+
c = c & 1 ? 0xedb88320 ^ (c >>> 1) : c >>> 1;
|
|
12
|
+
t[n] = c >>> 0;
|
|
13
|
+
}
|
|
14
|
+
return t;
|
|
15
|
+
})();
|
|
16
|
+
function crc32(bytes) {
|
|
17
|
+
let c = 0xffffffff;
|
|
18
|
+
for (let i = 0; i < bytes.length; i++)
|
|
19
|
+
c = CRC_TABLE[(c ^ bytes[i]) & 0xff] ^ (c >>> 8);
|
|
20
|
+
return (c ^ 0xffffffff) >>> 0;
|
|
21
|
+
}
|
|
22
|
+
// ---- Helpers -------------------------------------------------------------
|
|
23
|
+
function concat(parts) {
|
|
24
|
+
let total = 0;
|
|
25
|
+
for (const p of parts)
|
|
26
|
+
total += p.length;
|
|
27
|
+
const out = new Uint8Array(total);
|
|
28
|
+
let off = 0;
|
|
29
|
+
for (const p of parts) {
|
|
30
|
+
out.set(p, off);
|
|
31
|
+
off += p.length;
|
|
32
|
+
}
|
|
33
|
+
return out;
|
|
34
|
+
}
|
|
35
|
+
function u32be(n) {
|
|
36
|
+
const b = new Uint8Array(4);
|
|
37
|
+
new DataView(b.buffer).setUint32(0, n >>> 0, false);
|
|
38
|
+
return b;
|
|
39
|
+
}
|
|
40
|
+
const TYPE_BYTES = (s) => {
|
|
41
|
+
const b = new Uint8Array(s.length);
|
|
42
|
+
for (let i = 0; i < s.length; i++)
|
|
43
|
+
b[i] = s.charCodeAt(i);
|
|
44
|
+
return b;
|
|
45
|
+
};
|
|
46
|
+
function chunk(type, data) {
|
|
47
|
+
const typeB = TYPE_BYTES(type);
|
|
48
|
+
const crcSrc = concat([typeB, data]);
|
|
49
|
+
return concat([u32be(data.length), typeB, data, u32be(crc32(crcSrc))]);
|
|
50
|
+
}
|
|
51
|
+
// ---- Deflate via Web Streams ---------------------------------------------
|
|
52
|
+
async function deflateZlib(input) {
|
|
53
|
+
// 'deflate' = RFC 1950 zlib-wrapped — what PNG IDAT needs. 'deflate-raw' (RFC 1951) would be wrong.
|
|
54
|
+
const cs = new CompressionStream('deflate');
|
|
55
|
+
const writer = cs.writable.getWriter();
|
|
56
|
+
// TS 5.7 narrows Uint8Array<ArrayBufferLike> away from BufferSource; safe since we never use SharedArrayBuffer.
|
|
57
|
+
const writeDone = (async () => {
|
|
58
|
+
await writer.write(input);
|
|
59
|
+
await writer.close();
|
|
60
|
+
})();
|
|
61
|
+
const reader = cs.readable.getReader();
|
|
62
|
+
const readDone = (async () => {
|
|
63
|
+
const chunks = [];
|
|
64
|
+
while (true) {
|
|
65
|
+
const { value, done } = await reader.read();
|
|
66
|
+
if (done)
|
|
67
|
+
break;
|
|
68
|
+
if (value)
|
|
69
|
+
chunks.push(value);
|
|
70
|
+
}
|
|
71
|
+
return concat(chunks);
|
|
72
|
+
})();
|
|
73
|
+
const [, deflated] = await Promise.all([writeDone, readDone]);
|
|
74
|
+
return deflated;
|
|
75
|
+
}
|
|
76
|
+
// ---- Encode --------------------------------------------------------------
|
|
77
|
+
const PNG_SIGNATURE = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
|
|
78
|
+
/**
|
|
79
|
+
* Prepend scanline filter bytes using PNG's Average filter (type 3):
|
|
80
|
+
* Filt(x) = Orig(x) − floor((Recon(a) + Recon(b)) / 2)
|
|
81
|
+
* where `a` is the same channel of the pixel to the left (x − bpp) and `b` the byte directly
|
|
82
|
+
* above. Encoding may read the ORIGINAL bytes for a/b because the decoder reconstructs those
|
|
83
|
+
* positions exactly before it needs them — the transform is bit-exact reversible, so decoded
|
|
84
|
+
* pixels are byte-identical to `pixels`. Nothing about the image the model sees changes.
|
|
85
|
+
*
|
|
86
|
+
* Chosen over filter=None (the previous behavior): residuals of 5×8 bitmap glyphs on a flat
|
|
87
|
+
* background collapse to mostly zeros, which deflate encodes in both less space and less time —
|
|
88
|
+
* ~34% smaller IDAT at roughly half the compression cost on a representative dense page. That
|
|
89
|
+
* matters because every image is re-uploaded on every turn, so IDAT size is a per-request
|
|
90
|
+
* bandwidth cost. Filtering is pure JS ahead of the compressor, so it stays portable to
|
|
91
|
+
* Workers unlike a deflate-level change (see the CompressionStream note above).
|
|
92
|
+
*/
|
|
93
|
+
function filterAverage(pixels, width, height, bpp) {
|
|
94
|
+
const rowBytes = width * bpp;
|
|
95
|
+
const stride = rowBytes + 1;
|
|
96
|
+
const out = new Uint8Array(stride * height);
|
|
97
|
+
if (height === 0 || rowBytes === 0)
|
|
98
|
+
return out;
|
|
99
|
+
// Row 0: upper neighbor `b` is zero everywhere.
|
|
100
|
+
out[0] = 3;
|
|
101
|
+
for (let x = 0; x < bpp; x++) {
|
|
102
|
+
out[1 + x] = pixels[x];
|
|
103
|
+
}
|
|
104
|
+
for (let x = bpp; x < rowBytes; x++) {
|
|
105
|
+
out[1 + x] = (pixels[x] - (pixels[x - bpp] >> 1)) & 0xff;
|
|
106
|
+
}
|
|
107
|
+
// Remaining rows: specialize no-branch inner loop.
|
|
108
|
+
for (let y = 1; y < height; y++) {
|
|
109
|
+
const src = y * rowBytes;
|
|
110
|
+
const prev = src - rowBytes;
|
|
111
|
+
const dst = y * stride;
|
|
112
|
+
out[dst] = 3; // filter: Average
|
|
113
|
+
for (let x = 0; x < bpp; x++) {
|
|
114
|
+
out[dst + 1 + x] = (pixels[src + x] - (pixels[prev + x] >> 1)) & 0xff;
|
|
115
|
+
}
|
|
116
|
+
const dstData = dst + 1;
|
|
117
|
+
for (let x = bpp; x < rowBytes; x++) {
|
|
118
|
+
out[dstData + x] = (pixels[src + x] - ((pixels[src + x - bpp] + pixels[prev + x]) >> 1)) & 0xff;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return out;
|
|
122
|
+
}
|
|
123
|
+
/** Encode a single-channel (grayscale) buffer as PNG bytes. pixels is row-major, length = width × height. */
|
|
124
|
+
export async function encodeGrayPng(pixels, width, height) {
|
|
125
|
+
if (!Number.isInteger(width) || !Number.isInteger(height) || width <= 0 || height <= 0) {
|
|
126
|
+
throw new Error(`encodeGrayPng: invalid dimensions ${width}×${height}`);
|
|
127
|
+
}
|
|
128
|
+
if (pixels.length !== width * height) {
|
|
129
|
+
throw new Error(`encodeGrayPng: pixels.length=${pixels.length} != ${width}×${height}=${width * height}`);
|
|
130
|
+
}
|
|
131
|
+
// IHDR: width(4) height(4) bitDepth=8 colorType=0(gray) compress=0 filter=0 interlace=0
|
|
132
|
+
const ihdr = new Uint8Array(13);
|
|
133
|
+
ihdr.set(u32be(width), 0);
|
|
134
|
+
ihdr.set(u32be(height), 4);
|
|
135
|
+
ihdr[8] = 8;
|
|
136
|
+
ihdr[9] = 0; // colorType 0 = grayscale; bytes 10-12 already zero
|
|
137
|
+
const compressed = await deflateZlib(filterAverage(pixels, width, height, 1));
|
|
138
|
+
return concat([
|
|
139
|
+
PNG_SIGNATURE,
|
|
140
|
+
chunk('IHDR', ihdr),
|
|
141
|
+
chunk('IDAT', compressed),
|
|
142
|
+
chunk('IEND', new Uint8Array(0)),
|
|
143
|
+
]);
|
|
144
|
+
}
|
|
145
|
+
/** Encode an RGB (3 bytes/pixel, R,G,B) buffer as PNG bytes (colorType 2 = truecolor). length = width × height × 3. */
|
|
146
|
+
export async function encodeRgbPng(pixels, width, height) {
|
|
147
|
+
if (!Number.isInteger(width) || !Number.isInteger(height) || width <= 0 || height <= 0) {
|
|
148
|
+
throw new Error(`encodeRgbPng: invalid dimensions ${width}×${height}`);
|
|
149
|
+
}
|
|
150
|
+
if (pixels.length !== width * height * 3) {
|
|
151
|
+
throw new Error(`encodeRgbPng: pixels.length=${pixels.length} != ${width}×${height}×3=${width * height * 3}`);
|
|
152
|
+
}
|
|
153
|
+
const ihdr = new Uint8Array(13);
|
|
154
|
+
ihdr.set(u32be(width), 0);
|
|
155
|
+
ihdr.set(u32be(height), 4);
|
|
156
|
+
ihdr[8] = 8; // bit depth per channel
|
|
157
|
+
ihdr[9] = 2; // colorType 2 = truecolor RGB; bytes 10-12 already zero
|
|
158
|
+
const compressed = await deflateZlib(filterAverage(pixels, width, height, 3));
|
|
159
|
+
return concat([
|
|
160
|
+
PNG_SIGNATURE,
|
|
161
|
+
chunk('IHDR', ihdr),
|
|
162
|
+
chunk('IDAT', compressed),
|
|
163
|
+
chunk('IEND', new Uint8Array(0)),
|
|
164
|
+
]);
|
|
165
|
+
}
|
|
166
|
+
const base64Memo = new WeakMap();
|
|
167
|
+
/**
|
|
168
|
+
* Base64-encode PNG bytes. Prefers native V8 `Uint8Array.prototype.toBase64` (~100x faster
|
|
169
|
+
* than char-by-char `btoa`) and memoizes the JS fallback on immutable pixel buffers.
|
|
170
|
+
*/
|
|
171
|
+
export function bytesToBase64(bytes) {
|
|
172
|
+
const nativeFn = bytes.toBase64;
|
|
173
|
+
if (typeof nativeFn === 'function') {
|
|
174
|
+
return nativeFn.call(bytes);
|
|
175
|
+
}
|
|
176
|
+
const hit = base64Memo.get(bytes);
|
|
177
|
+
if (hit !== undefined)
|
|
178
|
+
return hit;
|
|
179
|
+
let binary = '';
|
|
180
|
+
const CHUNK = 0x8000;
|
|
181
|
+
for (let i = 0; i < bytes.length; i += CHUNK) {
|
|
182
|
+
binary += String.fromCharCode(...bytes.subarray(i, i + CHUNK));
|
|
183
|
+
}
|
|
184
|
+
const b64 = btoa(binary);
|
|
185
|
+
base64Memo.set(bytes, b64);
|
|
186
|
+
return b64;
|
|
187
|
+
}
|
|
188
|
+
//# sourceMappingURL=png.js.map
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure Content-Addressed Prefix-State Memo Tape & Unified Seal Table (`PrefixMemoTape`).
|
|
3
|
+
*
|
|
4
|
+
* Leaf module: ZERO `node:` imports, ZERO `Buffer`, ZERO imports from other `src/` modules.
|
|
5
|
+
*
|
|
6
|
+
* Provides three bounded, prefix-cache-invariant memo subsystems:
|
|
7
|
+
* 1. Stage-2 Cleaned-Slot LRU (`maxStage2Entries = 1024`, `maxStage2Chars = 12 MiB`)
|
|
8
|
+
* 2. Unified Prefix Seal Table (`maxSessions = 512`, `maxSealsPerSession = 512`)
|
|
9
|
+
* 3. Merkle Prefix-State CASI Memo (`maxCasiEntries = 1024`, `maxCasiChars = 8 MiB`)
|
|
10
|
+
*/
|
|
11
|
+
export declare const INITIAL_PREFIX_HASH = "0000000000000000";
|
|
12
|
+
/**
|
|
13
|
+
* Deterministic fast 64-bit dual FNV-1a digest formatted as 16 lowercase hex chars.
|
|
14
|
+
*/
|
|
15
|
+
export declare function tapeHash64Hex(text: string): string;
|
|
16
|
+
export interface Stage2MemoEntry {
|
|
17
|
+
readonly text: string;
|
|
18
|
+
readonly changed: boolean;
|
|
19
|
+
readonly stages: readonly string[];
|
|
20
|
+
}
|
|
21
|
+
export interface CommittedSlotSeal {
|
|
22
|
+
readonly text: string;
|
|
23
|
+
readonly stages: readonly string[];
|
|
24
|
+
readonly kind: 'epoch' | 'markov';
|
|
25
|
+
readonly rawLen: number;
|
|
26
|
+
}
|
|
27
|
+
export interface CasiMemoEntry {
|
|
28
|
+
readonly text: string;
|
|
29
|
+
readonly changed: boolean;
|
|
30
|
+
readonly kind: 'none' | 'exact_dup' | 'delta' | 'slice';
|
|
31
|
+
}
|
|
32
|
+
export interface PrefixTapeStats {
|
|
33
|
+
readonly stage2Entries: number;
|
|
34
|
+
readonly stage2Chars: number;
|
|
35
|
+
readonly stage2Hits: number;
|
|
36
|
+
readonly stage2Misses: number;
|
|
37
|
+
readonly sealSessions: number;
|
|
38
|
+
readonly totalSeals: number;
|
|
39
|
+
readonly sealChars: number;
|
|
40
|
+
readonly sealHits: number;
|
|
41
|
+
readonly casiEntries: number;
|
|
42
|
+
readonly casiChars: number;
|
|
43
|
+
readonly casiHits: number;
|
|
44
|
+
readonly casiMisses: number;
|
|
45
|
+
}
|
|
46
|
+
export interface PrefixMemoTapeOptions {
|
|
47
|
+
readonly maxStage2Entries?: number;
|
|
48
|
+
readonly maxStage2Chars?: number;
|
|
49
|
+
readonly maxSessions?: number;
|
|
50
|
+
readonly maxSealsPerSession?: number;
|
|
51
|
+
readonly maxSealChars?: number;
|
|
52
|
+
readonly maxCasiEntries?: number;
|
|
53
|
+
readonly maxCasiChars?: number;
|
|
54
|
+
}
|
|
55
|
+
export declare class PrefixMemoTape {
|
|
56
|
+
private readonly maxStage2Entries;
|
|
57
|
+
private readonly maxStage2Chars;
|
|
58
|
+
private readonly maxSessions;
|
|
59
|
+
private readonly maxSealsPerSession;
|
|
60
|
+
private readonly maxSealChars;
|
|
61
|
+
private readonly maxCasiEntries;
|
|
62
|
+
private readonly maxCasiChars;
|
|
63
|
+
private readonly stage2Map;
|
|
64
|
+
private stage2Chars;
|
|
65
|
+
private stage2Hits;
|
|
66
|
+
private stage2Misses;
|
|
67
|
+
private readonly sealSessions;
|
|
68
|
+
private totalSeals;
|
|
69
|
+
private sealChars;
|
|
70
|
+
private sealHits;
|
|
71
|
+
private readonly casiMap;
|
|
72
|
+
private casiChars;
|
|
73
|
+
private casiHits;
|
|
74
|
+
private casiMisses;
|
|
75
|
+
constructor(opts?: PrefixMemoTapeOptions);
|
|
76
|
+
private normalizeSession;
|
|
77
|
+
/** Retrieve a Stage-2 memo entry, refreshing LRU recency and cloning `stages`. */
|
|
78
|
+
getStage2(key: string): Stage2MemoEntry | undefined;
|
|
79
|
+
/** Insert or update a Stage-2 memo entry, evicting oldest entries on count or char cap. */
|
|
80
|
+
setStage2(key: string, entry: Stage2MemoEntry): void;
|
|
81
|
+
/** Check whether a session currently holds any committed prefix seals. */
|
|
82
|
+
hasAnySessionSeals(sessionKey: string | undefined): boolean;
|
|
83
|
+
/** Retrieve a committed slot seal for a session, refreshing session LRU recency. */
|
|
84
|
+
getSeal(sessionKey: string | undefined, slotSig: string): CommittedSlotSeal | undefined;
|
|
85
|
+
/** Record a committed slot seal under `sessionKey`, enforcing bounded session, seal & total char caps. */
|
|
86
|
+
setSeal(sessionKey: string | undefined, slotSig: string, seal: CommittedSlotSeal): void;
|
|
87
|
+
/** Remove all committed seals for a single session. */
|
|
88
|
+
clearSession(sessionKey: string | undefined): void;
|
|
89
|
+
/** Advance a Merkle prefix-state hash deterministically from `prevHash` and `slotSig`. */
|
|
90
|
+
advancePrefixHash(prevHash: string, slotSig: string): string;
|
|
91
|
+
/** Retrieve a CASI prefix-state memo entry, refreshing LRU recency. */
|
|
92
|
+
getCasiMemo(key: string): CasiMemoEntry | undefined;
|
|
93
|
+
/** Insert or update a CASI prefix-state memo entry, evicting oldest entries on count or char cap. */
|
|
94
|
+
setCasiMemo(key: string, entry: CasiMemoEntry): void;
|
|
95
|
+
/** Return exact counters and sizes across all three memo subsystems. */
|
|
96
|
+
getStats(): PrefixTapeStats;
|
|
97
|
+
/** Clear all cached entries, seals, and hit/miss counters. */
|
|
98
|
+
reset(): void;
|
|
99
|
+
}
|
|
100
|
+
export declare function getGlobalPrefixTape(): PrefixMemoTape;
|
|
101
|
+
export declare function resetGlobalPrefixTape(): void;
|
|
102
|
+
//# sourceMappingURL=prefix-tape.d.ts.map
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure Content-Addressed Prefix-State Memo Tape & Unified Seal Table (`PrefixMemoTape`).
|
|
3
|
+
*
|
|
4
|
+
* Leaf module: ZERO `node:` imports, ZERO `Buffer`, ZERO imports from other `src/` modules.
|
|
5
|
+
*
|
|
6
|
+
* Provides three bounded, prefix-cache-invariant memo subsystems:
|
|
7
|
+
* 1. Stage-2 Cleaned-Slot LRU (`maxStage2Entries = 1024`, `maxStage2Chars = 12 MiB`)
|
|
8
|
+
* 2. Unified Prefix Seal Table (`maxSessions = 512`, `maxSealsPerSession = 512`)
|
|
9
|
+
* 3. Merkle Prefix-State CASI Memo (`maxCasiEntries = 1024`, `maxCasiChars = 8 MiB`)
|
|
10
|
+
*/
|
|
11
|
+
const DEFAULT_MAX_STAGE2_ENTRIES = 1024;
|
|
12
|
+
const DEFAULT_MAX_STAGE2_CHARS = 12 * 1024 * 1024;
|
|
13
|
+
const DEFAULT_MAX_SESSIONS = 512;
|
|
14
|
+
const DEFAULT_MAX_SEALS_PER_SESSION = 512;
|
|
15
|
+
const DEFAULT_MAX_SEAL_CHARS = 16 * 1024 * 1024;
|
|
16
|
+
const DEFAULT_MAX_CASI_ENTRIES = 1024;
|
|
17
|
+
const DEFAULT_MAX_CASI_CHARS = 8 * 1024 * 1024;
|
|
18
|
+
export const INITIAL_PREFIX_HASH = '0000000000000000';
|
|
19
|
+
/**
|
|
20
|
+
* Deterministic fast 64-bit dual FNV-1a digest formatted as 16 lowercase hex chars.
|
|
21
|
+
*/
|
|
22
|
+
export function tapeHash64Hex(text) {
|
|
23
|
+
let h1 = 0x811c9dc5 >>> 0;
|
|
24
|
+
let h2 = 0x9e3779b1 >>> 0;
|
|
25
|
+
for (let i = 0; i < text.length; i++) {
|
|
26
|
+
const c = text.charCodeAt(i);
|
|
27
|
+
h1 ^= c;
|
|
28
|
+
h1 = Math.imul(h1, 0x01000193);
|
|
29
|
+
h2 ^= (c ^ (i & 0xff)) >>> 0;
|
|
30
|
+
h2 = Math.imul(h2, 0x01000193);
|
|
31
|
+
}
|
|
32
|
+
return (h1 >>> 0).toString(16).padStart(8, '0') + (h2 >>> 0).toString(16).padStart(8, '0');
|
|
33
|
+
}
|
|
34
|
+
export class PrefixMemoTape {
|
|
35
|
+
maxStage2Entries;
|
|
36
|
+
maxStage2Chars;
|
|
37
|
+
maxSessions;
|
|
38
|
+
maxSealsPerSession;
|
|
39
|
+
maxSealChars;
|
|
40
|
+
maxCasiEntries;
|
|
41
|
+
maxCasiChars;
|
|
42
|
+
stage2Map = new Map();
|
|
43
|
+
stage2Chars = 0;
|
|
44
|
+
stage2Hits = 0;
|
|
45
|
+
stage2Misses = 0;
|
|
46
|
+
sealSessions = new Map();
|
|
47
|
+
totalSeals = 0;
|
|
48
|
+
sealChars = 0;
|
|
49
|
+
sealHits = 0;
|
|
50
|
+
casiMap = new Map();
|
|
51
|
+
casiChars = 0;
|
|
52
|
+
casiHits = 0;
|
|
53
|
+
casiMisses = 0;
|
|
54
|
+
constructor(opts = {}) {
|
|
55
|
+
this.maxStage2Entries = Math.max(1, opts.maxStage2Entries ?? DEFAULT_MAX_STAGE2_ENTRIES);
|
|
56
|
+
this.maxStage2Chars = Math.max(0, opts.maxStage2Chars ?? DEFAULT_MAX_STAGE2_CHARS);
|
|
57
|
+
this.maxSessions = Math.max(1, opts.maxSessions ?? DEFAULT_MAX_SESSIONS);
|
|
58
|
+
this.maxSealsPerSession = Math.max(1, opts.maxSealsPerSession ?? DEFAULT_MAX_SEALS_PER_SESSION);
|
|
59
|
+
this.maxSealChars = Math.max(0, opts.maxSealChars ?? DEFAULT_MAX_SEAL_CHARS);
|
|
60
|
+
this.maxCasiEntries = Math.max(1, opts.maxCasiEntries ?? DEFAULT_MAX_CASI_ENTRIES);
|
|
61
|
+
this.maxCasiChars = Math.max(0, opts.maxCasiChars ?? DEFAULT_MAX_CASI_CHARS);
|
|
62
|
+
}
|
|
63
|
+
normalizeSession(rawSession) {
|
|
64
|
+
const trimmed = rawSession?.trim();
|
|
65
|
+
return trimmed && trimmed.length > 0 ? trimmed : 'default';
|
|
66
|
+
}
|
|
67
|
+
/** Retrieve a Stage-2 memo entry, refreshing LRU recency and cloning `stages`. */
|
|
68
|
+
getStage2(key) {
|
|
69
|
+
const entry = this.stage2Map.get(key);
|
|
70
|
+
if (!entry) {
|
|
71
|
+
this.stage2Misses++;
|
|
72
|
+
return undefined;
|
|
73
|
+
}
|
|
74
|
+
this.stage2Hits++;
|
|
75
|
+
this.stage2Map.delete(key);
|
|
76
|
+
this.stage2Map.set(key, entry);
|
|
77
|
+
return {
|
|
78
|
+
text: entry.text,
|
|
79
|
+
changed: entry.changed,
|
|
80
|
+
stages: [...entry.stages],
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/** Insert or update a Stage-2 memo entry, evicting oldest entries on count or char cap. */
|
|
84
|
+
setStage2(key, entry) {
|
|
85
|
+
const existing = this.stage2Map.get(key);
|
|
86
|
+
if (existing !== undefined) {
|
|
87
|
+
this.stage2Chars -= existing.text.length;
|
|
88
|
+
this.stage2Map.delete(key);
|
|
89
|
+
}
|
|
90
|
+
if (entry.text.length > this.maxStage2Chars) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const stored = {
|
|
94
|
+
text: entry.text,
|
|
95
|
+
changed: entry.changed,
|
|
96
|
+
stages: [...entry.stages],
|
|
97
|
+
};
|
|
98
|
+
this.stage2Map.set(key, stored);
|
|
99
|
+
this.stage2Chars += stored.text.length;
|
|
100
|
+
while (this.stage2Map.size > this.maxStage2Entries || this.stage2Chars > this.maxStage2Chars) {
|
|
101
|
+
const oldestKey = this.stage2Map.keys().next().value;
|
|
102
|
+
if (oldestKey === undefined)
|
|
103
|
+
break;
|
|
104
|
+
const oldestEntry = this.stage2Map.get(oldestKey);
|
|
105
|
+
if (oldestEntry) {
|
|
106
|
+
this.stage2Chars -= oldestEntry.text.length;
|
|
107
|
+
}
|
|
108
|
+
this.stage2Map.delete(oldestKey);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/** Check whether a session currently holds any committed prefix seals. */
|
|
112
|
+
hasAnySessionSeals(sessionKey) {
|
|
113
|
+
const sess = this.sealSessions.get(this.normalizeSession(sessionKey));
|
|
114
|
+
return sess !== undefined && sess.size > 0;
|
|
115
|
+
}
|
|
116
|
+
/** Retrieve a committed slot seal for a session, refreshing session LRU recency. */
|
|
117
|
+
getSeal(sessionKey, slotSig) {
|
|
118
|
+
const norm = this.normalizeSession(sessionKey);
|
|
119
|
+
const sess = this.sealSessions.get(norm);
|
|
120
|
+
if (!sess)
|
|
121
|
+
return undefined;
|
|
122
|
+
const seal = sess.get(slotSig);
|
|
123
|
+
if (!seal)
|
|
124
|
+
return undefined;
|
|
125
|
+
this.sealSessions.delete(norm);
|
|
126
|
+
this.sealSessions.set(norm, sess);
|
|
127
|
+
this.sealHits++;
|
|
128
|
+
return {
|
|
129
|
+
text: seal.text,
|
|
130
|
+
stages: [...seal.stages],
|
|
131
|
+
kind: seal.kind,
|
|
132
|
+
rawLen: seal.rawLen,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
/** Record a committed slot seal under `sessionKey`, enforcing bounded session, seal & total char caps. */
|
|
136
|
+
setSeal(sessionKey, slotSig, seal) {
|
|
137
|
+
if (seal.text.length > this.maxSealChars)
|
|
138
|
+
return;
|
|
139
|
+
const norm = this.normalizeSession(sessionKey);
|
|
140
|
+
let sess = this.sealSessions.get(norm);
|
|
141
|
+
if (sess) {
|
|
142
|
+
this.sealSessions.delete(norm);
|
|
143
|
+
this.sealSessions.set(norm, sess);
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
sess = new Map();
|
|
147
|
+
this.sealSessions.set(norm, sess);
|
|
148
|
+
while (this.sealSessions.size > this.maxSessions) {
|
|
149
|
+
const oldestSession = this.sealSessions.keys().next().value;
|
|
150
|
+
if (oldestSession === undefined)
|
|
151
|
+
break;
|
|
152
|
+
const oldestMap = this.sealSessions.get(oldestSession);
|
|
153
|
+
if (oldestMap) {
|
|
154
|
+
this.totalSeals -= oldestMap.size;
|
|
155
|
+
for (const entry of oldestMap.values())
|
|
156
|
+
this.sealChars -= entry.text.length;
|
|
157
|
+
}
|
|
158
|
+
this.sealSessions.delete(oldestSession);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const stored = {
|
|
162
|
+
text: seal.text,
|
|
163
|
+
stages: [...seal.stages],
|
|
164
|
+
kind: seal.kind,
|
|
165
|
+
rawLen: seal.rawLen,
|
|
166
|
+
};
|
|
167
|
+
const existing = sess.get(slotSig);
|
|
168
|
+
if (existing) {
|
|
169
|
+
this.sealChars -= existing.text.length;
|
|
170
|
+
sess.delete(slotSig);
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
this.totalSeals++;
|
|
174
|
+
}
|
|
175
|
+
sess.set(slotSig, stored);
|
|
176
|
+
this.sealChars += stored.text.length;
|
|
177
|
+
while (sess.size > this.maxSealsPerSession) {
|
|
178
|
+
const oldestSig = sess.keys().next().value;
|
|
179
|
+
if (oldestSig === undefined)
|
|
180
|
+
break;
|
|
181
|
+
const oldestSeal = sess.get(oldestSig);
|
|
182
|
+
if (oldestSeal)
|
|
183
|
+
this.sealChars -= oldestSeal.text.length;
|
|
184
|
+
sess.delete(oldestSig);
|
|
185
|
+
this.totalSeals--;
|
|
186
|
+
}
|
|
187
|
+
while (this.sealChars > this.maxSealChars && this.sealSessions.size > 0) {
|
|
188
|
+
const oldestSession = this.sealSessions.keys().next().value;
|
|
189
|
+
if (oldestSession === undefined)
|
|
190
|
+
break;
|
|
191
|
+
if (oldestSession === norm && sess.size > 1) {
|
|
192
|
+
const oldestSig = sess.keys().next().value;
|
|
193
|
+
if (oldestSig === undefined)
|
|
194
|
+
break;
|
|
195
|
+
const oldestSeal = sess.get(oldestSig);
|
|
196
|
+
if (oldestSeal)
|
|
197
|
+
this.sealChars -= oldestSeal.text.length;
|
|
198
|
+
sess.delete(oldestSig);
|
|
199
|
+
this.totalSeals--;
|
|
200
|
+
}
|
|
201
|
+
else {
|
|
202
|
+
const oldestMap = this.sealSessions.get(oldestSession);
|
|
203
|
+
if (oldestMap) {
|
|
204
|
+
this.totalSeals -= oldestMap.size;
|
|
205
|
+
for (const entry of oldestMap.values())
|
|
206
|
+
this.sealChars -= entry.text.length;
|
|
207
|
+
}
|
|
208
|
+
this.sealSessions.delete(oldestSession);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
/** Remove all committed seals for a single session. */
|
|
213
|
+
clearSession(sessionKey) {
|
|
214
|
+
const norm = this.normalizeSession(sessionKey);
|
|
215
|
+
const sess = this.sealSessions.get(norm);
|
|
216
|
+
if (!sess)
|
|
217
|
+
return;
|
|
218
|
+
this.totalSeals -= sess.size;
|
|
219
|
+
for (const entry of sess.values())
|
|
220
|
+
this.sealChars -= entry.text.length;
|
|
221
|
+
this.sealSessions.delete(norm);
|
|
222
|
+
}
|
|
223
|
+
/** Advance a Merkle prefix-state hash deterministically from `prevHash` and `slotSig`. */
|
|
224
|
+
advancePrefixHash(prevHash, slotSig) {
|
|
225
|
+
const base = prevHash || INITIAL_PREFIX_HASH;
|
|
226
|
+
return tapeHash64Hex(`${base}\x00${slotSig}`);
|
|
227
|
+
}
|
|
228
|
+
/** Retrieve a CASI prefix-state memo entry, refreshing LRU recency. */
|
|
229
|
+
getCasiMemo(key) {
|
|
230
|
+
const entry = this.casiMap.get(key);
|
|
231
|
+
if (!entry) {
|
|
232
|
+
this.casiMisses++;
|
|
233
|
+
return undefined;
|
|
234
|
+
}
|
|
235
|
+
this.casiHits++;
|
|
236
|
+
this.casiMap.delete(key);
|
|
237
|
+
this.casiMap.set(key, entry);
|
|
238
|
+
return {
|
|
239
|
+
text: entry.text,
|
|
240
|
+
changed: entry.changed,
|
|
241
|
+
kind: entry.kind,
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/** Insert or update a CASI prefix-state memo entry, evicting oldest entries on count or char cap. */
|
|
245
|
+
setCasiMemo(key, entry) {
|
|
246
|
+
const existing = this.casiMap.get(key);
|
|
247
|
+
if (existing !== undefined) {
|
|
248
|
+
this.casiChars -= existing.text.length;
|
|
249
|
+
this.casiMap.delete(key);
|
|
250
|
+
}
|
|
251
|
+
if (entry.text.length > this.maxCasiChars) {
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
const stored = {
|
|
255
|
+
text: entry.text,
|
|
256
|
+
changed: entry.changed,
|
|
257
|
+
kind: entry.kind,
|
|
258
|
+
};
|
|
259
|
+
this.casiMap.set(key, stored);
|
|
260
|
+
this.casiChars += stored.text.length;
|
|
261
|
+
while (this.casiMap.size > this.maxCasiEntries || this.casiChars > this.maxCasiChars) {
|
|
262
|
+
const oldestKey = this.casiMap.keys().next().value;
|
|
263
|
+
if (oldestKey === undefined)
|
|
264
|
+
break;
|
|
265
|
+
const oldestEntry = this.casiMap.get(oldestKey);
|
|
266
|
+
if (oldestEntry) {
|
|
267
|
+
this.casiChars -= oldestEntry.text.length;
|
|
268
|
+
}
|
|
269
|
+
this.casiMap.delete(oldestKey);
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
/** Return exact counters and sizes across all three memo subsystems. */
|
|
273
|
+
getStats() {
|
|
274
|
+
return {
|
|
275
|
+
stage2Entries: this.stage2Map.size,
|
|
276
|
+
stage2Chars: this.stage2Chars,
|
|
277
|
+
stage2Hits: this.stage2Hits,
|
|
278
|
+
stage2Misses: this.stage2Misses,
|
|
279
|
+
sealSessions: this.sealSessions.size,
|
|
280
|
+
totalSeals: this.totalSeals,
|
|
281
|
+
sealChars: this.sealChars,
|
|
282
|
+
sealHits: this.sealHits,
|
|
283
|
+
casiEntries: this.casiMap.size,
|
|
284
|
+
casiChars: this.casiChars,
|
|
285
|
+
casiHits: this.casiHits,
|
|
286
|
+
casiMisses: this.casiMisses,
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
/** Clear all cached entries, seals, and hit/miss counters. */
|
|
290
|
+
reset() {
|
|
291
|
+
this.stage2Map.clear();
|
|
292
|
+
this.stage2Chars = 0;
|
|
293
|
+
this.stage2Hits = 0;
|
|
294
|
+
this.stage2Misses = 0;
|
|
295
|
+
this.sealSessions.clear();
|
|
296
|
+
this.totalSeals = 0;
|
|
297
|
+
this.sealChars = 0;
|
|
298
|
+
this.sealHits = 0;
|
|
299
|
+
this.casiMap.clear();
|
|
300
|
+
this.casiChars = 0;
|
|
301
|
+
this.casiHits = 0;
|
|
302
|
+
this.casiMisses = 0;
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
let globalPrefixTape;
|
|
306
|
+
export function getGlobalPrefixTape() {
|
|
307
|
+
if (!globalPrefixTape) {
|
|
308
|
+
globalPrefixTape = new PrefixMemoTape();
|
|
309
|
+
}
|
|
310
|
+
return globalPrefixTape;
|
|
311
|
+
}
|
|
312
|
+
export function resetGlobalPrefixTape() {
|
|
313
|
+
globalPrefixTape?.reset();
|
|
314
|
+
}
|
|
315
|
+
//# sourceMappingURL=prefix-tape.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model id normalisation for price lookup. Shared by the resolver and by
|
|
3
|
+
* scripts/gen-prices.ts, so a snapshot key and a request's model id are
|
|
4
|
+
* spelled the same way. Workers-safe.
|
|
5
|
+
*/
|
|
6
|
+
/** Lowercase; drop bracketed transport tags (`[1m]`), a vendor path
|
|
7
|
+
* (`anthropic/`, `moonshotai/`), a `:variant` suffix (`:free`, `:thinking`)
|
|
8
|
+
* and a trailing release date (`-20250929`, `-2026-05-20`, `@20250514`). */
|
|
9
|
+
export declare function normalizeModelId(model: string | null | undefined): string;
|
|
10
|
+
//# sourceMappingURL=price-id.d.ts.map
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Model id normalisation for price lookup. Shared by the resolver and by
|
|
3
|
+
* scripts/gen-prices.ts, so a snapshot key and a request's model id are
|
|
4
|
+
* spelled the same way. Workers-safe.
|
|
5
|
+
*/
|
|
6
|
+
/** Lowercase; drop bracketed transport tags (`[1m]`), a vendor path
|
|
7
|
+
* (`anthropic/`, `moonshotai/`), a `:variant` suffix (`:free`, `:thinking`)
|
|
8
|
+
* and a trailing release date (`-20250929`, `-2026-05-20`, `@20250514`). */
|
|
9
|
+
export function normalizeModelId(model) {
|
|
10
|
+
let m = (model ?? '').trim().toLowerCase().replace(/\[[^\]]*\]/g, '');
|
|
11
|
+
const slash = m.lastIndexOf('/');
|
|
12
|
+
if (slash >= 0)
|
|
13
|
+
m = m.slice(slash + 1);
|
|
14
|
+
const colon = m.indexOf(':');
|
|
15
|
+
if (colon >= 0)
|
|
16
|
+
m = m.slice(0, colon);
|
|
17
|
+
m = m
|
|
18
|
+
.replace(/^(?:[a-z]{2}\.)?anthropic\./, '')
|
|
19
|
+
.replace(/-v\d+$/, '')
|
|
20
|
+
.replace(/@\d{8}$/, '')
|
|
21
|
+
.replace(/-\d{4}-\d{2}-\d{2}$/, '')
|
|
22
|
+
.replace(/-\d{8}$/, '');
|
|
23
|
+
m = m.replace(/^(claude-(?:[a-z-]+-)?)(\d+)\.(\d+)(.*)$/, '$1$2-$3$4');
|
|
24
|
+
return m;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=price-id.js.map
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
export interface PriceBand {
|
|
2
|
+
at: number;
|
|
3
|
+
incl?: true;
|
|
4
|
+
in: number;
|
|
5
|
+
out?: number;
|
|
6
|
+
cr?: number;
|
|
7
|
+
cwt?: Array<[number, number]>;
|
|
8
|
+
}
|
|
9
|
+
export interface PriceChange {
|
|
10
|
+
at: number;
|
|
11
|
+
in?: number;
|
|
12
|
+
out?: number;
|
|
13
|
+
cr?: number;
|
|
14
|
+
cw?: number;
|
|
15
|
+
cw1h?: number;
|
|
16
|
+
}
|
|
17
|
+
export interface PriceRow {
|
|
18
|
+
p: string;
|
|
19
|
+
in: number;
|
|
20
|
+
out?: number;
|
|
21
|
+
cr?: number;
|
|
22
|
+
cw?: number;
|
|
23
|
+
cw1h?: number;
|
|
24
|
+
lcIn?: number;
|
|
25
|
+
lcOut?: number;
|
|
26
|
+
lcAt?: number;
|
|
27
|
+
lcCr?: number;
|
|
28
|
+
cwt?: Array<[number, number]>;
|
|
29
|
+
cwb?: 'as-input';
|
|
30
|
+
bands?: PriceBand[];
|
|
31
|
+
chg?: PriceChange[];
|
|
32
|
+
}
|
|
33
|
+
export declare const PRICE_SNAPSHOT = "kosha schema 1 discovered 2026-11-17T21:37:37.905Z";
|
|
34
|
+
export declare const PRICES: Readonly<Record<string, PriceRow>>;
|
|
35
|
+
export declare const PRICE_ALIASES: Readonly<Record<string, string>>;
|
|
36
|
+
//# sourceMappingURL=prices.generated.d.ts.map
|