@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.
Files changed (196) hide show
  1. package/CHANGELOG.md +134 -0
  2. package/LICENSE +22 -0
  3. package/NOTICE +13 -0
  4. package/PRIVACY.md +41 -0
  5. package/README.md +289 -0
  6. package/SECURITY.md +53 -0
  7. package/assets/JETBRAINS_MONO_LICENSE.txt +89 -0
  8. package/assets/SPLEEN_LICENSE.txt +24 -0
  9. package/assets/UNIFONT_LICENSE.txt +476 -0
  10. package/assets/fiche-logo-dark.svg +61 -0
  11. package/assets/fiche-logo-light.svg +61 -0
  12. package/assets/fiche-logo.svg +71 -0
  13. package/assets/fiche-mark.svg +48 -0
  14. package/bin/cli.js +7 -0
  15. package/bin/mcp.js +8 -0
  16. package/dist/calibrate.d.ts +30 -0
  17. package/dist/calibrate.js +588 -0
  18. package/dist/core/anthropic-vision.d.ts +28 -0
  19. package/dist/core/anthropic-vision.js +34 -0
  20. package/dist/core/applicability.d.ts +63 -0
  21. package/dist/core/applicability.js +151 -0
  22. package/dist/core/atlas-gray-jbmono10.d.ts +26 -0
  23. package/dist/core/atlas-gray-jbmono10.js +64 -0
  24. package/dist/core/atlas-gray-jbmono12.d.ts +26 -0
  25. package/dist/core/atlas-gray-jbmono12.js +64 -0
  26. package/dist/core/atlas-gray-jbmono14.d.ts +26 -0
  27. package/dist/core/atlas-gray-jbmono14.js +64 -0
  28. package/dist/core/atlas-gray.d.ts +26 -0
  29. package/dist/core/atlas-gray.js +64 -0
  30. package/dist/core/atlas-jbmono10.d.ts +34 -0
  31. package/dist/core/atlas-jbmono10.js +71 -0
  32. package/dist/core/atlas-jbmono12.d.ts +34 -0
  33. package/dist/core/atlas-jbmono12.js +71 -0
  34. package/dist/core/atlas-jbmono14.d.ts +34 -0
  35. package/dist/core/atlas-jbmono14.js +71 -0
  36. package/dist/core/atlas.d.ts +34 -0
  37. package/dist/core/atlas.js +71 -0
  38. package/dist/core/baseline.d.ts +121 -0
  39. package/dist/core/baseline.js +200 -0
  40. package/dist/core/calibration.d.ts +86 -0
  41. package/dist/core/calibration.js +547 -0
  42. package/dist/core/casi-delta.d.ts +63 -0
  43. package/dist/core/casi-delta.js +1271 -0
  44. package/dist/core/claude-model-profiles.d.ts +53 -0
  45. package/dist/core/claude-model-profiles.js +160 -0
  46. package/dist/core/client-tool-round.d.ts +31 -0
  47. package/dist/core/client-tool-round.js +58 -0
  48. package/dist/core/codex-cache.d.ts +20 -0
  49. package/dist/core/codex-cache.js +59 -0
  50. package/dist/core/context-mmu.d.ts +350 -0
  51. package/dist/core/context-mmu.js +3028 -0
  52. package/dist/core/cpt-fit.d.ts +70 -0
  53. package/dist/core/cpt-fit.js +197 -0
  54. package/dist/core/env.d.ts +8 -0
  55. package/dist/core/env.js +15 -0
  56. package/dist/core/export.d.ts +127 -0
  57. package/dist/core/export.js +385 -0
  58. package/dist/core/factsheet.d.ts +77 -0
  59. package/dist/core/factsheet.js +494 -0
  60. package/dist/core/gemini-model-profiles.d.ts +20 -0
  61. package/dist/core/gemini-model-profiles.js +134 -0
  62. package/dist/core/google.d.ts +76 -0
  63. package/dist/core/google.js +1380 -0
  64. package/dist/core/gpt-model-profiles.d.ts +218 -0
  65. package/dist/core/gpt-model-profiles.js +570 -0
  66. package/dist/core/gpt-tokens.d.ts +14 -0
  67. package/dist/core/gpt-tokens.js +165 -0
  68. package/dist/core/history.d.ts +197 -0
  69. package/dist/core/history.js +1003 -0
  70. package/dist/core/index.d.ts +16 -0
  71. package/dist/core/index.js +16 -0
  72. package/dist/core/library.d.ts +80 -0
  73. package/dist/core/library.js +131 -0
  74. package/dist/core/measurement.d.ts +34 -0
  75. package/dist/core/measurement.js +280 -0
  76. package/dist/core/messages-chat-bridge.d.ts +23 -0
  77. package/dist/core/messages-chat-bridge.js +747 -0
  78. package/dist/core/messages-responses-bridge.d.ts +11 -0
  79. package/dist/core/messages-responses-bridge.js +893 -0
  80. package/dist/core/openai-history.d.ts +184 -0
  81. package/dist/core/openai-history.js +1279 -0
  82. package/dist/core/openai-savings.d.ts +57 -0
  83. package/dist/core/openai-savings.js +116 -0
  84. package/dist/core/openai.d.ts +68 -0
  85. package/dist/core/openai.js +2523 -0
  86. package/dist/core/pin.d.ts +199 -0
  87. package/dist/core/pin.js +1353 -0
  88. package/dist/core/png.d.ts +14 -0
  89. package/dist/core/png.js +188 -0
  90. package/dist/core/prefix-tape.d.ts +102 -0
  91. package/dist/core/prefix-tape.js +315 -0
  92. package/dist/core/price-id.d.ts +10 -0
  93. package/dist/core/price-id.js +26 -0
  94. package/dist/core/prices.generated.d.ts +36 -0
  95. package/dist/core/prices.generated.js +369 -0
  96. package/dist/core/pricing.d.ts +134 -0
  97. package/dist/core/pricing.js +335 -0
  98. package/dist/core/profile-base.d.ts +30 -0
  99. package/dist/core/profile-base.js +67 -0
  100. package/dist/core/provider-router.d.ts +51 -0
  101. package/dist/core/provider-router.js +121 -0
  102. package/dist/core/proxy.d.ts +252 -0
  103. package/dist/core/proxy.js +2929 -0
  104. package/dist/core/reader-tier.d.ts +24 -0
  105. package/dist/core/reader-tier.js +118 -0
  106. package/dist/core/render.d.ts +280 -0
  107. package/dist/core/render.js +1302 -0
  108. package/dist/core/request-guard.d.ts +31 -0
  109. package/dist/core/request-guard.js +126 -0
  110. package/dist/core/request-transform.d.ts +43 -0
  111. package/dist/core/request-transform.js +173 -0
  112. package/dist/core/schema-compiler.d.ts +64 -0
  113. package/dist/core/schema-compiler.js +1696 -0
  114. package/dist/core/schema-strip.d.ts +29 -0
  115. package/dist/core/schema-strip.js +173 -0
  116. package/dist/core/session-state.d.ts +219 -0
  117. package/dist/core/session-state.js +929 -0
  118. package/dist/core/stage-plugins.d.ts +45 -0
  119. package/dist/core/stage-plugins.js +205 -0
  120. package/dist/core/text-history.d.ts +74 -0
  121. package/dist/core/text-history.js +612 -0
  122. package/dist/core/text-hygiene.d.ts +160 -0
  123. package/dist/core/text-hygiene.js +2259 -0
  124. package/dist/core/toon.d.ts +29 -0
  125. package/dist/core/toon.js +425 -0
  126. package/dist/core/tracker.d.ts +223 -0
  127. package/dist/core/tracker.js +290 -0
  128. package/dist/core/transform.d.ts +589 -0
  129. package/dist/core/transform.js +3153 -0
  130. package/dist/core/types.d.ts +87 -0
  131. package/dist/core/types.js +8 -0
  132. package/dist/core/upstream-hosts.d.ts +127 -0
  133. package/dist/core/upstream-hosts.js +398 -0
  134. package/dist/core/vision-cost.d.ts +63 -0
  135. package/dist/core/vision-cost.js +137 -0
  136. package/dist/dashboard/fragments.d.ts +87 -0
  137. package/dist/dashboard/fragments.js +1515 -0
  138. package/dist/dashboard/types.d.ts +217 -0
  139. package/dist/dashboard/types.js +3 -0
  140. package/dist/dashboard/vendor.d.ts +3 -0
  141. package/dist/dashboard/vendor.js +6 -0
  142. package/dist/dashboard.d.ts +372 -0
  143. package/dist/dashboard.js +2731 -0
  144. package/dist/export-collect.d.ts +36 -0
  145. package/dist/export-collect.js +59 -0
  146. package/dist/file-tracker.d.ts +42 -0
  147. package/dist/file-tracker.js +234 -0
  148. package/dist/kosha-sync.d.ts +74 -0
  149. package/dist/kosha-sync.js +272 -0
  150. package/dist/launchd-socket.d.ts +22 -0
  151. package/dist/launchd-socket.js +210 -0
  152. package/dist/mcp/cli.d.ts +2 -0
  153. package/dist/mcp/cli.js +55 -0
  154. package/dist/mcp/server.d.ts +48 -0
  155. package/dist/mcp/server.js +987 -0
  156. package/dist/mmu-store.d.ts +31 -0
  157. package/dist/mmu-store.js +179 -0
  158. package/dist/node-fetch.d.ts +22 -0
  159. package/dist/node-fetch.js +489 -0
  160. package/dist/node.d.ts +9 -0
  161. package/dist/node.js +244396 -0
  162. package/dist/request-decoding.d.ts +30 -0
  163. package/dist/request-decoding.js +85 -0
  164. package/dist/sessions.d.ts +179 -0
  165. package/dist/sessions.js +837 -0
  166. package/dist/stats.d.ts +114 -0
  167. package/dist/stats.js +439 -0
  168. package/dist/turn-report.d.ts +65 -0
  169. package/dist/turn-report.js +724 -0
  170. package/dist/warp/app-launch.d.ts +26 -0
  171. package/dist/warp/app-launch.js +155 -0
  172. package/dist/warp/ca.d.ts +74 -0
  173. package/dist/warp/ca.js +416 -0
  174. package/dist/warp/connect.d.ts +42 -0
  175. package/dist/warp/connect.js +686 -0
  176. package/dist/warp/der.d.ts +57 -0
  177. package/dist/warp/der.js +151 -0
  178. package/dist/warp/index.d.ts +79 -0
  179. package/dist/warp/index.js +650 -0
  180. package/dist/warp/resolve.d.ts +12 -0
  181. package/dist/warp/resolve.js +49 -0
  182. package/dist/warp/route.d.ts +71 -0
  183. package/dist/warp/route.js +134 -0
  184. package/dist/worker.d.ts +71 -0
  185. package/dist/worker.js +174 -0
  186. package/docs/SECURITY_MODEL.md +84 -0
  187. package/package.json +115 -3
  188. package/plugins/fiche-companion/README.md +42 -0
  189. package/plugins/fiche-companion/assets/logo.svg +48 -0
  190. package/plugins/fiche-companion/hooks.json +11 -0
  191. package/plugins/fiche-companion/mcp_config.json +8 -0
  192. package/plugins/fiche-companion/plugin.json +18 -0
  193. package/plugins/fiche-companion/scripts/claude-statusline.mjs +35 -0
  194. package/plugins/fiche-companion/scripts/post-invocation.mjs +122 -0
  195. package/plugins/fiche-companion/scripts/resolve-turn-report.mjs +132 -0
  196. package/plugins/fiche-companion/skills/fiche/SKILL.md +61 -0
@@ -0,0 +1,494 @@
1
+ /**
2
+ * Verbatim fact-sheet for imaged content.
3
+ *
4
+ * When inkling renders a block (system slab, history, tool_result, reminder) to a PNG,
5
+ * the precision-critical, hard-to-OCR strings inside it — file paths, URLs, SHAs/UUIDs,
6
+ * version numbers, CLI flags, large numbers, CONST_IDS — are exactly what a model is
7
+ * most likely to misread off the image yet most likely to need quoted verbatim. This
8
+ * module extracts those tokens so they ride next to the image as plain text: the model
9
+ * quotes them without re-reading the PNG, and they stay in the cached prefix.
10
+ *
11
+ * Deterministic by construction (fixed pattern order, length-desc/lexical sort, no
12
+ * Date/random) → the emitted text is byte-stable across turns and never busts the
13
+ * Anthropic prompt cache. Empirically ~5% of source chars on production history
14
+ * (median 4.9%, max 12.1%, N=10), which preserves the imaging token win.
15
+ */
16
+ /** ReDoS-safe extraction patterns (each global). Ordered most- to least-specific so the
17
+ * longest, most-identifying tokens are kept first when the substring filter runs. */
18
+ const PATTERNS = [
19
+ /\b[A-Z][A-Z0-9_]{2,}=[^\s)"'<>]+/g, // semantic LABEL=value pair (preserve association)
20
+ // Same association-preservation for lower/mixed-case `field=value`, which is what logs,
21
+ // CLI output and JSONL actually emit (`dur=4439`, `gold=c9c947f680ec`, `trial=0`). The
22
+ // uppercase pattern above skips those entirely, so only the bare value survives the image
23
+ // and the label↔value binding is lost: a reader keeps `4439` but not what `dur` meant, and
24
+ // silently rebinds it to a plausible wrong field (elapsed time, not the search key). That
25
+ // is a binding error, not a legibility one — the glyphs were never in doubt. Value side is
26
+ // restricted to opaque tokens so prose (`x=y`) and code (`const a=b`) cannot flood the sheet.
27
+ /\b[A-Za-z][A-Za-z0-9_]{2,}=[A-Za-z0-9_.:/+-]{1,64}/g,
28
+ /\bhttps?:\/\/[^\s)"'<>]+/g, // URLs
29
+ /\b[A-Za-z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+\b/g, // email address
30
+ /\b[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\b/g, // UUID
31
+ /\b[A-Z]{2}\d{2}[A-Z0-9]{8,30}\b/g, // IBAN-like account string
32
+ /(?:[$€£¥]|(?:USD|EUR|GBP|CAD|AUD|CHF|JPY))\d(?:[\d,_]*\d)?(?:\.\d{2})?\b/g, // currency amount
33
+ /(?:[\w@~+-]+)?(?:\/[\w.@+-]+)+\.[A-Za-z]\w{0,8}\b/g, // path with a file extension (multi-dot ok: .test.ts)
34
+ /\/[\w.@+-]+(?:\/[\w.@+-]+)+\/?/g, // dir path (>=2 segments)
35
+ /\b(?=[0-9a-f]*\d)[0-9a-f]{7,40}\b/g, // git sha / long hex (must contain a digit)
36
+ /\bv?\d+\.\d+(?:\.\d+)?(?:[-+][\w.]+)?\b/g, // version string
37
+ /(?:^|[^\w-])(--?[A-Za-z][\w-]+)/g, // CLI flag (token in capture group 1)
38
+ /\b\d[\d,_]{3,}\b/g, // large / separated number
39
+ /\b\d+\.\d+\b/g, // decimal
40
+ /\b[A-Z][A-Z0-9]+(?:_[A-Z0-9]+)+\b/g, // CONST_IDS / env var names
41
+ // camelCase / PascalCase with ≥1 lowercase run and ≥1 internal capital
42
+ // (tokenLedgerShard, getUserById). Rejects ALL-CAPS words so history markers
43
+ // like CURRENT/FRONTIER do not flood the sheet.
44
+ /\b(?:[a-z]+|[A-Z][a-z0-9]+)(?:[A-Z][a-z0-9]*)+\b/g,
45
+ // Ticket/advisory-style codes: uppercase hyphenated with ≥1 digit (PROJ-1482,
46
+ // CVE-2024-30078, AUDIT-ZX9). Digit lookahead is bounded → no backtracking blowup.
47
+ /\b(?=[A-Z0-9-]{0,119}\d)[A-Z][A-Z0-9]+(?:-[A-Z0-9]+)+\b/g,
48
+ ];
49
+ const MIN_LEN = 3;
50
+ const MAX_LEN = 120;
51
+ /** Budget cap: highest-priority tokens kept first. Exported so consumers can report drops. */
52
+ export const MAX_TOKENS = 96;
53
+ // At most this many URL exemplars: URLs are long, structured, low OCR-risk, and usually
54
+ // reconstructable, so they must never crowd out short zero-redundancy tokens.
55
+ const MAX_URLS = 8;
56
+ const MAX_SEEN = 2048; // defensive bound on distinct tokens entering substring-collapse
57
+ const MAX_ALL_PAGES_SEEN = 4096;
58
+ const MAX_SCAN = 262_144; // defensive input bound; tool_results are already paged
59
+ const MAX_ALL_PAGES_SCAN_CHARS = 1_048_576;
60
+ const MAX_ALL_PAGES_COUNT = 32;
61
+ // Match render DENSE_CONTENT_CHARS_PER_IMAGE without importing render (cycle-free).
62
+ export const FACTSHEET_PAGE_CHARS = 28_080;
63
+ const MAX_CHUNK = 512; // whitespace-free chunks longer than this are blobs (base64, minified) — skip
64
+ const M_DIGIT = 1 << 0;
65
+ const M_UPPER = 1 << 1;
66
+ const M_LOWER = 1 << 2;
67
+ const M_EQ = 1 << 3;
68
+ const M_SLASH = 1 << 4;
69
+ const M_AT = 1 << 5;
70
+ const M_DASH = 1 << 6;
71
+ const M_DOT = 1 << 7;
72
+ const M_UNDER = 1 << 8;
73
+ const M_CURR = 1 << 9;
74
+ // Required character-class mask per pattern in PATTERNS (same index order 0..16).
75
+ const SAFE_PATTERN_REQ_MASK = [
76
+ M_EQ | M_UPPER,
77
+ M_EQ,
78
+ M_SLASH | M_LOWER,
79
+ M_AT | M_DOT,
80
+ M_DASH,
81
+ M_UPPER | M_DIGIT,
82
+ M_DIGIT,
83
+ M_SLASH | M_DOT,
84
+ M_SLASH,
85
+ M_DIGIT,
86
+ M_DIGIT | M_DOT,
87
+ M_DASH,
88
+ M_DIGIT,
89
+ M_DIGIT | M_DOT,
90
+ M_UPPER | M_UNDER,
91
+ M_UPPER | M_LOWER,
92
+ M_UPPER | M_DASH | M_DIGIT,
93
+ ];
94
+ function chunkCharMask(chunk) {
95
+ let m = 0;
96
+ for (let i = 0; i < chunk.length; i++) {
97
+ const c = chunk.charCodeAt(i);
98
+ if (c >= 48 && c <= 57)
99
+ m |= M_DIGIT;
100
+ else if (c >= 65 && c <= 90)
101
+ m |= M_UPPER;
102
+ else if (c >= 97 && c <= 122)
103
+ m |= M_LOWER;
104
+ else if (c === 61)
105
+ m |= M_EQ;
106
+ else if (c === 47)
107
+ m |= M_SLASH;
108
+ else if (c === 64)
109
+ m |= M_AT;
110
+ else if (c === 45)
111
+ m |= M_DASH;
112
+ else if (c === 46)
113
+ m |= M_DOT;
114
+ else if (c === 95)
115
+ m |= M_UNDER;
116
+ else if (c === 36 || c === 0x20ac || c === 0xa3 || c === 0xa5)
117
+ m |= M_CURR;
118
+ }
119
+ return m;
120
+ }
121
+ const FACTSHEET_CACHE_CAP = 512;
122
+ const factsheetDigestCache = new Map();
123
+ // Key by 128-bit digest + length so the LRU holds zero copies of large slab inputs.
124
+ function factSheetDigestKey(scan) {
125
+ let h1 = 0x811c9dc5 >>> 0;
126
+ let h2 = 0x9e3779b1 >>> 0;
127
+ let h3 = 0x85ebca6b >>> 0;
128
+ let h4 = 0xc2b2ae35 >>> 0;
129
+ for (let i = 0; i < scan.length; i++) {
130
+ const c = scan.charCodeAt(i);
131
+ h1 = Math.imul(h1 ^ c, 0x01000193);
132
+ h2 = Math.imul(h2 ^ ((c + i) & 0xffff), 0x01000193);
133
+ h3 = Math.imul(h3 ^ c, 0x85ebca77);
134
+ h4 = Math.imul(h4 ^ ((c << 3) | (i & 7)), 0xc2b2ae3d);
135
+ }
136
+ return ((h1 >>> 0).toString(16).padStart(8, '0') +
137
+ (h2 >>> 0).toString(16).padStart(8, '0') +
138
+ (h3 >>> 0).toString(16).padStart(8, '0') +
139
+ (h4 >>> 0).toString(16).padStart(8, '0') +
140
+ ':' +
141
+ scan.length);
142
+ }
143
+ /** Test helper: reset bounded digest cache for factsheet extraction. */
144
+ export function clearFactSheetCache() {
145
+ factsheetDigestCache.clear();
146
+ }
147
+ /** Budget priority by token SHAPE, not length — length is anti-correlated with
148
+ * OCR-risk×consequence: a 70-char URL is structured and reconstructable, while a 7-char
149
+ * hex SHA or a port has zero redundancy and fails silently when misread. So short opaque
150
+ * identifiers outrank long URLs when the budget is tight. Pure + total → deterministic →
151
+ * cache-stable. Tiers: 0 = protect always, 1 = paths/versions/misc, 2 = URLs (cap + last). */
152
+ const SHAPE_UUID = /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/;
153
+ const SHAPE_EMAIL = /^[A-Za-z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?(?:\.[A-Za-z0-9](?:[A-Za-z0-9-]{0,61}[A-Za-z0-9])?)+$/;
154
+ const SHAPE_IBAN = /^[A-Z]{2}\d{2}[A-Z0-9]{8,30}$/;
155
+ const SHAPE_CURRENCY = /^(?:[$€£¥]|(?:USD|EUR|GBP|CAD|AUD|CHF|JPY))\d(?:[\d,_]*\d)?(?:\.\d{2})?$/;
156
+ const SHAPE_HEX = /^(?=[0-9a-f]*\d)[0-9a-f]{7,40}$/; // git sha / opaque hex
157
+ const SHAPE_CONST = /^[A-Z][A-Z0-9]+(?:_[A-Z0-9]+)+$/; // CONST_IDS / env vars
158
+ const SHAPE_TICKET = /^(?=[A-Z0-9-]*\d)[A-Z][A-Z0-9]+(?:-[A-Z0-9]+)+$/; // PROJ-1482 / CVE-2024-30078
159
+ const SHAPE_FLAG = /^--?[A-Za-z][\w-]+$/; // CLI flag
160
+ const SHAPE_NUM = /^\d[\d,_]*$|^\d+\.\d+$/; // port / large or separated number / decimal
161
+ const SHAPE_URL = /^https?:\/\//;
162
+ const SHAPE_CAMEL = /^(?:[a-z]+|[A-Z][a-z0-9]+)(?:[A-Z][a-z0-9]*)+$/; // tokenLedgerShard / getUserById
163
+ // Tier-0 assignment is deliberately UPPERCASE-only. Lowercase `field=value` is still
164
+ // captured (see PATTERNS) so the label↔value binding survives, but it stays out of tier 0:
165
+ // log lines carry one on every row, so promoting them floods the top tier, and because the
166
+ // budget fills longest-first the `req=` prefix also inflates an 8-char hex id past a 9-char
167
+ // ticket code — evicting the rare token the sheet exists to preserve. Rarity, not shape, is
168
+ // what makes `dur=4439` worth keeping, and tier 1 is where that trade lands correctly.
169
+ const SHAPE_ASSIGNMENT = /^[A-Z][A-Z0-9_]{2,}=\S+$/; // ACTIVE_MANIFEST=/path
170
+ /** Lower tier = higher keep-priority. Pure function of the token → deterministic. */
171
+ function priorityTier(tok) {
172
+ if (SHAPE_ASSIGNMENT.test(tok) ||
173
+ SHAPE_HEX.test(tok) ||
174
+ SHAPE_UUID.test(tok) ||
175
+ SHAPE_EMAIL.test(tok) ||
176
+ SHAPE_IBAN.test(tok) ||
177
+ SHAPE_CURRENCY.test(tok) ||
178
+ SHAPE_CONST.test(tok) ||
179
+ SHAPE_TICKET.test(tok) ||
180
+ SHAPE_FLAG.test(tok) ||
181
+ SHAPE_NUM.test(tok) ||
182
+ (SHAPE_CAMEL.test(tok) && tok.length >= 8)) {
183
+ return 0;
184
+ }
185
+ if (SHAPE_URL.test(tok))
186
+ return 2;
187
+ return 1;
188
+ }
189
+ /**
190
+ * Extract deduped, precision-critical tokens from `text`. Substrings of a longer kept
191
+ * token are dropped (so `/github.com` inside the full URL, `lib/x.ts` inside
192
+ * `src/lib/x.ts`, etc. collapse to the most specific form); the token budget is then
193
+ * filled by priority tier (see `priorityTier`) so short, high-consequence tokens are never
194
+ * evicted by long low-risk URLs.
195
+ *
196
+ * Every token class is whitespace-free, so we split on whitespace first and skip
197
+ * blob-length chunks. That bounds each regex to a short chunk and keeps extraction
198
+ * strictly O(n) — no quadratic backtracking on delimiter-heavy input like base64 or
199
+ * minified bundles (which embed `/` and would otherwise make the path patterns blow up).
200
+ */
201
+ export function extractFactSheetTokens(text) {
202
+ return extractFactSheetEntries(text).map((e) => e.token);
203
+ }
204
+ /**
205
+ * Like `extractFactSheetTokens`, but each kept token carries its occurrence count.
206
+ * Counts make the fact sheet a *quantitative* index: tally questions over imaged
207
+ * content ("how many lines mention CODE-X?") become answerable from text instead
208
+ * of from counting rows of 5×8 px glyphs — the one operation page images are worst
209
+ * at. The kept-token SET and its order are byte-identical to the pre-count
210
+ * behaviour; only counts are new. Same-token spans matched by two patterns are
211
+ * deduped by offset so a token is never double-counted.
212
+ */
213
+ const TRAILING_PUNCT_RE = /[.,;:!?]+$/;
214
+ function collectRawFactSheetCounts(scan, counts, maxSeen = MAX_SEEN) {
215
+ for (const chunk of scan.split(/\s+/)) {
216
+ if (chunk.length < MIN_LEN || chunk.length > MAX_CHUNK)
217
+ continue;
218
+ const mask = chunkCharMask(chunk);
219
+ // Offset-level dedup WITHIN this chunk: lazily allocate Set only when >= 2 matches occur.
220
+ let firstKey;
221
+ let spanSeen = null;
222
+ for (let pIdx = 0; pIdx < PATTERNS.length; pIdx++) {
223
+ const req = SAFE_PATTERN_REQ_MASK[pIdx];
224
+ if ((mask & req) !== req)
225
+ continue;
226
+ if (pIdx === 6 && !(mask & (M_CURR | M_UPPER)))
227
+ continue;
228
+ const re = PATTERNS[pIdx];
229
+ re.lastIndex = 0;
230
+ let m;
231
+ while ((m = re.exec(chunk)) !== null) {
232
+ // Strip trailing sentence punctuation pulled in from prose (`pull/93.` → `pull/93`);
233
+ // no real identifier we extract ends in these.
234
+ const tok = (m[1] ?? m[0]).trim().replace(TRAILING_PUNCT_RE, '');
235
+ if (tok.length < MIN_LEN || tok.length > MAX_LEN)
236
+ continue;
237
+ const key = `${m.index}\x00${tok}`;
238
+ if (firstKey === undefined) {
239
+ firstKey = key;
240
+ }
241
+ else if (spanSeen === null) {
242
+ if (key === firstKey)
243
+ continue;
244
+ spanSeen = new Set([firstKey, key]);
245
+ }
246
+ else if (spanSeen.has(key)) {
247
+ continue;
248
+ }
249
+ else {
250
+ spanSeen.add(key);
251
+ }
252
+ const prev = counts.get(tok);
253
+ if (prev !== undefined) {
254
+ counts.set(tok, prev + 1);
255
+ }
256
+ else if (counts.size < maxSeen) {
257
+ counts.set(tok, 1);
258
+ }
259
+ }
260
+ }
261
+ }
262
+ }
263
+ function collapseSubstringsTrigram(ordered) {
264
+ const specific = [];
265
+ const triIndex = new Map();
266
+ for (const t of ordered) {
267
+ let shadowed = false;
268
+ if (t.length >= 3) {
269
+ const firstTri = t.slice(0, 3);
270
+ const firstBucket = triIndex.get(firstTri);
271
+ if (firstBucket !== undefined) {
272
+ let bestBucket = firstBucket;
273
+ if (t.length >= 6) {
274
+ const midStart = t.length >> 1;
275
+ const midTri = t.slice(midStart, midStart + 3);
276
+ const midBucket = triIndex.get(midTri);
277
+ if (midBucket === undefined) {
278
+ bestBucket = [];
279
+ }
280
+ else if (midBucket.length < bestBucket.length) {
281
+ bestBucket = midBucket;
282
+ }
283
+ if (bestBucket.length > 0) {
284
+ const lastTri = t.slice(t.length - 3);
285
+ const lastBucket = triIndex.get(lastTri);
286
+ if (lastBucket === undefined)
287
+ bestBucket = [];
288
+ else if (lastBucket.length < bestBucket.length)
289
+ bestBucket = lastBucket;
290
+ }
291
+ }
292
+ for (let i = 0; i < bestBucket.length; i++) {
293
+ if (specific[bestBucket[i]].includes(t)) {
294
+ shadowed = true;
295
+ break;
296
+ }
297
+ }
298
+ }
299
+ }
300
+ if (shadowed)
301
+ continue;
302
+ const idx = specific.length;
303
+ specific.push(t);
304
+ if (t.length >= 3) {
305
+ const seenTri = new Set();
306
+ for (let j = 0; j <= t.length - 3; j++) {
307
+ const tri = t.slice(j, j + 3);
308
+ if (seenTri.has(tri))
309
+ continue;
310
+ seenTri.add(tri);
311
+ let bucket = triIndex.get(tri);
312
+ if (!bucket) {
313
+ bucket = [idx];
314
+ triIndex.set(tri, bucket);
315
+ }
316
+ else {
317
+ bucket.push(idx);
318
+ }
319
+ }
320
+ }
321
+ }
322
+ return specific;
323
+ }
324
+ function collapseAndSelectFactSheet(counts) {
325
+ // Phase 1 — substring collapse (length-desc): keep the most-specific form.
326
+ const ordered = [...counts.keys()].sort((a, b) => b.length - a.length || (a < b ? -1 : a > b ? 1 : 0));
327
+ const specific = collapseSubstringsTrigram(ordered);
328
+ // Phase 2 — allocate the budget by priority tier (shape, not length).
329
+ const ranked = specific
330
+ .map((t) => ({ t, tier: priorityTier(t) }))
331
+ .sort((a, b) => a.tier - b.tier || b.t.length - a.t.length || (a.t < b.t ? -1 : a.t > b.t ? 1 : 0));
332
+ const kept = [];
333
+ let urls = 0;
334
+ for (const { t, tier } of ranked) {
335
+ if (kept.length >= MAX_TOKENS)
336
+ break;
337
+ if (tier === 2 && urls++ >= MAX_URLS)
338
+ continue;
339
+ kept.push({ token: t, count: counts.get(t) ?? 1 });
340
+ }
341
+ return { kept, dropped: specific.length - kept.length };
342
+ }
343
+ export function extractFactSheetEntries(text) {
344
+ const scan = text.length > MAX_SCAN ? text.slice(0, MAX_SCAN) : text;
345
+ const cacheKey = scan.length >= 64 ? factSheetDigestKey(scan) : '';
346
+ if (cacheKey) {
347
+ const cached = factsheetDigestCache.get(cacheKey);
348
+ if (cached !== undefined) {
349
+ factsheetDigestCache.delete(cacheKey);
350
+ factsheetDigestCache.set(cacheKey, cached);
351
+ // Shallow-clone entries so callers never mutate cached arrays/objects in place.
352
+ return cached.map((e) => ({ token: e.token, count: e.count }));
353
+ }
354
+ }
355
+ const counts = new Map();
356
+ collectRawFactSheetCounts(scan, counts, MAX_SEEN);
357
+ const { kept: result } = collapseAndSelectFactSheet(counts);
358
+ if (cacheKey) {
359
+ if (factsheetDigestCache.size >= FACTSHEET_CACHE_CAP) {
360
+ const oldest = factsheetDigestCache.keys().next().value;
361
+ if (oldest !== undefined)
362
+ factsheetDigestCache.delete(oldest);
363
+ }
364
+ factsheetDigestCache.set(cacheKey, result);
365
+ }
366
+ return result;
367
+ }
368
+ /**
369
+ * Page-aware variant of `extractFactSheetTokens` for large source texts.
370
+ *
371
+ * Splits `text` into chunks of `charsPerPage` (use `DENSE_CONTENT_CHARS_PER_IMAGE`
372
+ * from render.ts for the export pipeline), calls `extractFactSheetTokens` on each
373
+ * chunk (each chunk is smaller than MAX_SCAN so no truncation occurs), merges the
374
+ * results across all chunks with first-seen deduplication, then applies a single
375
+ * global priority-budget pass to select the best MAX_TOKENS identifiers.
376
+ *
377
+ * Returns `{ kept, dropped }` where `dropped` is the count of identifiers that
378
+ * survived extraction across all pages but did not fit in the MAX_TOKENS budget.
379
+ *
380
+ * Does NOT mutate the behaviour of `extractFactSheetTokens` or `factSheetText`.
381
+ */
382
+ export function extractFactSheetTokensAllPages(text, charsPerPage) {
383
+ const { kept, dropped } = extractFactSheetEntriesAllPages(text, charsPerPage);
384
+ return { kept: kept.map((e) => e.token), dropped };
385
+ }
386
+ /** Entry-carrying variant of `extractFactSheetTokensAllPages`: accumulates raw
387
+ * counts across bounded head+tail pages before a single global collapse & selection. */
388
+ export function extractFactSheetEntriesAllPages(text, charsPerPage) {
389
+ const counts = new Map();
390
+ const step = Math.max(1, Number.isFinite(charsPerPage) ? Math.floor(charsPerPage) : 1);
391
+ const pageBounds = [];
392
+ let pos = 0;
393
+ while (pos < text.length || pos === 0) {
394
+ let end = Math.min(text.length, pos + step);
395
+ if (end < text.length && !/\s/.test(text[end] ?? '') && !/\s/.test(text[end - 1] ?? '')) {
396
+ let back = end;
397
+ while (back > pos && !/\s/.test(text[back - 1]))
398
+ back--;
399
+ if (back > pos + Math.floor(step / 2)) {
400
+ end = back;
401
+ }
402
+ else {
403
+ let fwd = end;
404
+ while (fwd < text.length && fwd - end < 128 && !/\s/.test(text[fwd]))
405
+ fwd++;
406
+ if (fwd < text.length && /\s/.test(text[fwd]))
407
+ end = fwd + 1;
408
+ }
409
+ }
410
+ pageBounds.push([pos, end]);
411
+ if (end >= text.length)
412
+ break;
413
+ pos = end;
414
+ }
415
+ let selectedBounds;
416
+ if (pageBounds.length <= MAX_ALL_PAGES_COUNT && text.length <= MAX_ALL_PAGES_SCAN_CHARS) {
417
+ selectedBounds = pageBounds;
418
+ }
419
+ else {
420
+ const halfPages = Math.max(1, Math.floor(MAX_ALL_PAGES_COUNT / 2));
421
+ const headEndIdx = Math.min(halfPages, pageBounds.length);
422
+ const tailStartIdx = Math.max(headEndIdx, pageBounds.length - halfPages);
423
+ selectedBounds = [];
424
+ let scannedChars = 0;
425
+ for (let i = 0; i < headEndIdx && scannedChars < MAX_ALL_PAGES_SCAN_CHARS; i++) {
426
+ const b = pageBounds[i];
427
+ selectedBounds.push(b);
428
+ scannedChars += b[1] - b[0];
429
+ }
430
+ for (let i = tailStartIdx; i < pageBounds.length && scannedChars < MAX_ALL_PAGES_SCAN_CHARS; i++) {
431
+ const b = pageBounds[i];
432
+ selectedBounds.push(b);
433
+ scannedChars += b[1] - b[0];
434
+ }
435
+ }
436
+ for (const [start, end] of selectedBounds) {
437
+ const chunk = text.slice(start, end);
438
+ const scan = chunk.length > MAX_SCAN ? chunk.slice(0, MAX_SCAN) : chunk;
439
+ collectRawFactSheetCounts(scan, counts, MAX_ALL_PAGES_SEEN);
440
+ }
441
+ return collapseAndSelectFactSheet(counts);
442
+ }
443
+ const OPEN = '[Exact identifiers from the rendered context above (paths, ids, versions, numbers) — quote these verbatim instead of transcribing them from the image: ';
444
+ /** Variant used when at least one token repeats — explains the ×N annotation so the
445
+ * model can answer tally questions from the sheet instead of counting glyph rows. */
446
+ const OPEN_COUNTS = '[Exact identifiers from the rendered context above (paths, ids, versions, numbers) — quote these verbatim instead of transcribing them from the image; ×N marks a token that occurs N times within the imaged content: ';
447
+ const OPEN_COMPACT = '[Exact rendered identifiers—quote verbatim: ';
448
+ const OPEN_COMPACT_COUNTS = '[Exact rendered identifiers—quote verbatim; ×N=count: ';
449
+ /** Build the one-line fact-sheet string from a pre-extracted token list. */
450
+ export function factSheetTextFromTokens(tokens) {
451
+ return tokens.length > 0 ? OPEN + tokens.join(' · ') + ']' : '';
452
+ }
453
+ /** Build the one-line fact-sheet string from token+count entries. Byte-identical to
454
+ * `factSheetTextFromTokens` when no token repeats, so existing sheets stay cache-stable. */
455
+ export function factSheetTextFromEntries(entries, format = 'full') {
456
+ if (entries.length === 0)
457
+ return '';
458
+ const anyRepeat = entries.some((e) => e.count >= 2);
459
+ const body = entries.map((e) => (e.count >= 2 ? `${e.token} ×${e.count}` : e.token)).join(' · ');
460
+ const opener = format === 'compact'
461
+ ? (anyRepeat ? OPEN_COMPACT_COUNTS : OPEN_COMPACT)
462
+ : (anyRepeat ? OPEN_COUNTS : OPEN);
463
+ return opener + body + ']';
464
+ }
465
+ /** One-line fact-sheet string for `text`, or `''` when nothing notable was found.
466
+ * Single path for slab, history, and tool results: page long text so early-turn
467
+ * ids are not dropped by MAX_SCAN. Short text is one page (same as before). */
468
+ export function factSheetText(text, format = 'full', coveredText) {
469
+ if (!text)
470
+ return '';
471
+ return prepareFactSheet(text, format)(coveredText);
472
+ }
473
+ /** Extract once; coverage remains an emission-time input, never cached state. */
474
+ export function prepareFactSheet(text, format = 'full') {
475
+ if (!text)
476
+ return () => '';
477
+ const entries = text.length <= FACTSHEET_PAGE_CHARS
478
+ ? extractFactSheetEntries(text)
479
+ : extractFactSheetEntriesAllPages(text, FACTSHEET_PAGE_CHARS).kept;
480
+ const full = factSheetTextFromEntries(entries, format);
481
+ return (coveredText) => {
482
+ if (coveredText === undefined || (typeof coveredText === 'string' ? coveredText.length === 0 : coveredText.size === 0))
483
+ return full;
484
+ return factSheetTextFromEntries(entries.filter((entry) => {
485
+ const covered = typeof coveredText === 'string'
486
+ ? coveredText.includes(entry.token)
487
+ : coveredText.has(entry.token);
488
+ if (!covered)
489
+ return true;
490
+ return entry.count >= 2;
491
+ }), format);
492
+ };
493
+ }
494
+ //# sourceMappingURL=factsheet.js.map
@@ -0,0 +1,20 @@
1
+ import { calibratedBandToProfile } from './calibration.js';
2
+ import type { GptModelProfile } from './gpt-model-profiles.js';
3
+ export { calibratedBandToProfile };
4
+ /** Legacy Gemini 3.x Flash profile (1568×728, 312×90 at 5×8 = 49×22 = 1,078 ViT patches). */
5
+ export declare const GEMINI_LEGACY_PROFILE: GptModelProfile;
6
+ export declare const GEMINI_3_6_FLASH_PROFILE: GptModelProfile;
7
+ /** Dedicated Gemini 4+ profile. Shares the validated 1568×728 (49×22 patch)
8
+ * canvas geometry while raising the history page ceiling from the legacy 32-page
9
+ * cap to 96 pages (matching CLAUDE_PROFILE) and using 'mixed' responses grouping
10
+ * so long multi-hundred-turn agent sessions stay collapsed past 32 pages. */
11
+ export declare const GEMINI_PROFILE: GptModelProfile;
12
+ export declare function isGeminiModel(model: string | null | undefined): boolean;
13
+ /** True for Gemini models with a validated or forward-compatible profile.
14
+ * Supports 3.8+, 3.9+, 4+, 5+, Pro, and registered 3.6/3.7/3.1 flash models. */
15
+ export declare function hasGeminiMeasuredProfile(model: string | null | undefined): boolean;
16
+ export declare function resolveGeminiProfile(model?: string | null): GptModelProfile;
17
+ /** Gemini image tokens for any supported Gemini model using the validated
18
+ * flat-regime tile geometry (1,078 image tokens for 1568x728). */
19
+ export declare function geminiVisionTokens(model: string, w: number, h: number): number;
20
+ //# sourceMappingURL=gemini-model-profiles.d.ts.map
@@ -0,0 +1,134 @@
1
+ import { MAX_HEIGHT_PX as ANTHROPIC_MAX_HEIGHT_PX, ANTHROPIC_SLAB_COLS as ANTHROPIC_STRIP_COLS, } from './render.js';
2
+ import { calibratedBandToProfile, getCalibratedProfile } from './calibration.js';
3
+ import { BASE_PRICING } from './profile-base.js';
4
+ import { visionTokens } from './vision-cost.js';
5
+ export { calibratedBandToProfile };
6
+ /** Legacy Gemini 3.x Flash profile (1568×728, 312×90 at 5×8 = 49×22 = 1,078 ViT patches). */
7
+ export const GEMINI_LEGACY_PROFILE = {
8
+ // Flat per-image charge. Live usage measured the exact production canvas at
9
+ // 1,078 IMAGE tokens; other measured shapes ranged up to 1,113 and Google's
10
+ // Gemini 3 docs publish an approximate 1,120-token default/high image budget,
11
+ // so that documented ceiling prices partial pages and width-shrunk slabs.
12
+ vision: { regime: 'flat', tokens: 1120, exact: { widthPx: 1568, heightPx: 728, tokens: 1078 } },
13
+ ...BASE_PRICING,
14
+ cacheReadRate: 0.25,
15
+ stripCols: ANTHROPIC_STRIP_COLS,
16
+ maxHeightPx: ANTHROPIC_MAX_HEIGHT_PX,
17
+ minCompressTokens: 500,
18
+ factSheetFormat: 'compact',
19
+ history: {
20
+ maxImages: 32,
21
+ keepTail: 4,
22
+ keepRecentPairs: 4,
23
+ minCollapseTokens: 2000,
24
+ responsesMode: 'pairs',
25
+ framing: 'compact',
26
+ factSheetScope: 'combined',
27
+ },
28
+ style: {
29
+ font: 'spleen-5x8',
30
+ cellWBonus: 0,
31
+ cellHBonus: 0,
32
+ aa: true,
33
+ grid: false,
34
+ gridCols: 0,
35
+ colorCycle: false,
36
+ markerScale: 1,
37
+ markerRed: false,
38
+ inkDilate: 0,
39
+ },
40
+ };
41
+ export const GEMINI_3_6_FLASH_PROFILE = GEMINI_LEGACY_PROFILE;
42
+ /** Dedicated Gemini 4+ profile. Shares the validated 1568×728 (49×22 patch)
43
+ * canvas geometry while raising the history page ceiling from the legacy 32-page
44
+ * cap to 96 pages (matching CLAUDE_PROFILE) and using 'mixed' responses grouping
45
+ * so long multi-hundred-turn agent sessions stay collapsed past 32 pages. */
46
+ export const GEMINI_PROFILE = {
47
+ ...GEMINI_LEGACY_PROFILE,
48
+ history: {
49
+ ...GEMINI_LEGACY_PROFILE.history,
50
+ maxImages: 96,
51
+ responsesMode: 'mixed',
52
+ },
53
+ style: { ...GEMINI_LEGACY_PROFILE.style },
54
+ };
55
+ const GEMINI_MEASURED_PROFILES = {
56
+ 'gemini-3.6-flash': GEMINI_LEGACY_PROFILE,
57
+ 'gemini-3.7-flash': GEMINI_LEGACY_PROFILE,
58
+ 'gemini-3.8-flash': GEMINI_LEGACY_PROFILE,
59
+ 'gemini-3.8-flash-high': GEMINI_LEGACY_PROFILE,
60
+ 'gemini-3.8-flash-medium': GEMINI_LEGACY_PROFILE,
61
+ 'gemini-3.8-flash-low': GEMINI_LEGACY_PROFILE,
62
+ 'gemini-3.1-flash': GEMINI_LEGACY_PROFILE,
63
+ 'gemini-3.1-flash-lite': GEMINI_LEGACY_PROFILE,
64
+ 'gemini-4': GEMINI_PROFILE,
65
+ 'gemini-4-flash': GEMINI_PROFILE,
66
+ 'gemini-4-pro': GEMINI_PROFILE,
67
+ 'gemini-4-argon': GEMINI_PROFILE,
68
+ 'gemini-4-argon-high': GEMINI_PROFILE,
69
+ 'gemini-4-argon-medium': GEMINI_PROFILE,
70
+ 'gemini-4-argon-low': GEMINI_PROFILE,
71
+ };
72
+ function normalizeGeminiId(model) {
73
+ const id = (model ?? '').trim().toLowerCase().replace(/\[[^\]]*\]/g, '');
74
+ const slash = id.lastIndexOf('/');
75
+ return slash >= 0 ? id.slice(slash + 1) : id;
76
+ }
77
+ export function isGeminiModel(model) {
78
+ const id = normalizeGeminiId(model);
79
+ return id.startsWith('gemini-') || id === 'gemini';
80
+ }
81
+ /** True for Gemini models with a validated or forward-compatible profile.
82
+ * Supports 3.8+, 3.9+, 4+, 5+, Pro, and registered 3.6/3.7/3.1 flash models. */
83
+ export function hasGeminiMeasuredProfile(model) {
84
+ const id = normalizeGeminiId(model);
85
+ if (!id)
86
+ return false;
87
+ if (isGeminiModel(id)) {
88
+ const cal = getCalibratedProfile(model);
89
+ if (cal && cal.scores.passed && cal.band !== 'text-only')
90
+ return true;
91
+ }
92
+ if (id in GEMINI_MEASURED_PROFILES)
93
+ return true;
94
+ if (id === 'gemini-pro' || id === 'gemini-flash' || id === 'gemini')
95
+ return true;
96
+ const m = id.match(/^gemini-(\d+)(?:\.(\d+))?/);
97
+ if (!m)
98
+ return false;
99
+ const major = parseInt(m[1], 10);
100
+ const minor = m[2] !== undefined ? parseInt(m[2], 10) : 0;
101
+ if (major === 3) {
102
+ return minor >= 8;
103
+ }
104
+ return major > 3;
105
+ }
106
+ export function resolveGeminiProfile(model) {
107
+ let base = GEMINI_PROFILE;
108
+ if (model) {
109
+ const id = normalizeGeminiId(model);
110
+ const prof = GEMINI_MEASURED_PROFILES[id];
111
+ if (prof)
112
+ base = prof;
113
+ else if (id.startsWith('gemini-3.') || id === 'gemini-3')
114
+ base = GEMINI_LEGACY_PROFILE;
115
+ }
116
+ const cal = model ? getCalibratedProfile(model) : undefined;
117
+ if (cal && cal.scores.passed && cal.band !== 'text-only') {
118
+ return calibratedBandToProfile(cal.band, base, { cols: cal.cols, maxHeightPx: cal.maxHeightPx });
119
+ }
120
+ return base;
121
+ }
122
+ /** Gemini image tokens for any supported Gemini model using the validated
123
+ * flat-regime tile geometry (1,078 image tokens for 1568x728). */
124
+ export function geminiVisionTokens(model, w, h) {
125
+ if (!Number.isFinite(w) || !Number.isFinite(h) || w <= 0 || h <= 0) {
126
+ throw new Error(`Invalid Gemini image dimensions: ${w}x${h}`);
127
+ }
128
+ if (!hasGeminiMeasuredProfile(model)) {
129
+ throw new Error(`Unsupported Gemini model for image tokens: ${model}`);
130
+ }
131
+ const prof = resolveGeminiProfile(model);
132
+ return visionTokens(prof, w, h);
133
+ }
134
+ //# sourceMappingURL=gemini-model-profiles.js.map