@sriinnu/fiche 0.0.0-stage → 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 +288 -2
- 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 +122 -4
- 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,53 @@
|
|
|
1
|
+
import type { GptModelProfile } from './gpt-model-profiles.js';
|
|
2
|
+
/**
|
|
3
|
+
* Claude rendering + vision-cost profiles.
|
|
4
|
+
*
|
|
5
|
+
* Anthropic geometry (dense 312-col strips, 728 px height) and pixel billing
|
|
6
|
+
* differ from GPT's 152-col / 1932 px profile: using the GPT defaults overstates
|
|
7
|
+
* image cost and flips the slab gate to not_profitable, so an enabled Claude
|
|
8
|
+
* model would stay text-only and the dashboard would leave As text / Saved
|
|
9
|
+
* blank. resolveGptProfile therefore routes every Claude id here BEFORE the GPT
|
|
10
|
+
* rule table, so no Claude model can land on a GPT or Gemini profile.
|
|
11
|
+
*/
|
|
12
|
+
/** Claude 4.7+. Billed by Anthropic's 28-px patch grid after the high-res
|
|
13
|
+
* tier downscale; `visionTier` below is the only knob that varies by release. */
|
|
14
|
+
export declare const CLAUDE_PROFILE: GptModelProfile;
|
|
15
|
+
/** Pre-4.7 Claude: same render geometry, standard image-resolution tier. */
|
|
16
|
+
export declare const CLAUDE_LEGACY_PROFILE: GptModelProfile;
|
|
17
|
+
export declare const CLAUDE_SPACED_PROFILE: GptModelProfile;
|
|
18
|
+
export declare const CLAUDE_LEGACY_SPACED_PROFILE: GptModelProfile;
|
|
19
|
+
/**
|
|
20
|
+
* True only for the original Fable 5, the one Claude release measured accurate
|
|
21
|
+
* at bare dense geometry. Its point releases are not: dense hex
|
|
22
|
+
* (eval/verbatim-15, N=15, same needles) on claude-fable-5-2 reads
|
|
23
|
+
*
|
|
24
|
+
* dense 5x8 7/15
|
|
25
|
+
* 5x8 +2px rows 13/15 (what Fable 5 scores unspaced)
|
|
26
|
+
*
|
|
27
|
+
* so 5.1+ and any unrecognised Fable get spaced rows. `\d{1,2}(?!\d)` keeps a
|
|
28
|
+
* trailing date stamp (`claude-fable-5-20260601`) from reading as a minor.
|
|
29
|
+
*/
|
|
30
|
+
export declare function isBareDenseFable(model: string): boolean;
|
|
31
|
+
/** Every id that must be priced and rendered as Claude. */
|
|
32
|
+
export declare function isClaudeModel(model: string | null | undefined): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* True for Claude releases older than 4.7. Anthropic's vision docs tier the
|
|
35
|
+
* pre-billing downscale by VERSION, not by model family or an enumerated list:
|
|
36
|
+
*
|
|
37
|
+
* | High-resolution | Claude 4.7 and later models | 2576 px | 4784 |
|
|
38
|
+
* | Standard | All other models | 1568 px | 1568 |
|
|
39
|
+
*
|
|
40
|
+
* Reads the first version number in the id, tolerating both id orderings
|
|
41
|
+
* (`claude-opus-4-8` -> 4.8, `claude-3-5-sonnet` -> 3.5) and trailing date
|
|
42
|
+
* stamps. An unrecognised Claude id is treated as new: an unreleased model is
|
|
43
|
+
* far likelier to be 4.7+, and high-res is the safe guess for the gate because
|
|
44
|
+
* it over-estimates cost, whereas standard under-estimates it by assuming a
|
|
45
|
+
* downscale the server will not perform.
|
|
46
|
+
*/
|
|
47
|
+
export declare function isPre47Claude(m: string): boolean;
|
|
48
|
+
/** Pick the Claude profile for an id. Billing geometry is identical across
|
|
49
|
+
* opus/sonnet/haiku/fable; HISTORY geometry is not, because verbatim recall
|
|
50
|
+
* at dense geometry is a per-model property (see CLAUDE_SPACED_PROFILE).
|
|
51
|
+
* Fable 5 keeps bare dense; every other Claude id gets spaced rows. */
|
|
52
|
+
export declare function resolveClaudeProfile(m: string): GptModelProfile;
|
|
53
|
+
//# sourceMappingURL=claude-model-profiles.d.ts.map
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { MAX_HEIGHT_PX as ANTHROPIC_MAX_HEIGHT_PX, ANTHROPIC_SLAB_COLS as ANTHROPIC_STRIP_COLS, } from './render.js';
|
|
2
|
+
import { BASE_HISTORY, BASE_STYLE } from './profile-base.js';
|
|
3
|
+
/**
|
|
4
|
+
* Claude rendering + vision-cost profiles.
|
|
5
|
+
*
|
|
6
|
+
* Anthropic geometry (dense 312-col strips, 728 px height) and pixel billing
|
|
7
|
+
* differ from GPT's 152-col / 1932 px profile: using the GPT defaults overstates
|
|
8
|
+
* image cost and flips the slab gate to not_profitable, so an enabled Claude
|
|
9
|
+
* model would stay text-only and the dashboard would leave As text / Saved
|
|
10
|
+
* blank. resolveGptProfile therefore routes every Claude id here BEFORE the GPT
|
|
11
|
+
* rule table, so no Claude model can land on a GPT or Gemini profile.
|
|
12
|
+
*/
|
|
13
|
+
/** Claude 4.7+. Billed by Anthropic's 28-px patch grid after the high-res
|
|
14
|
+
* tier downscale; `visionTier` below is the only knob that varies by release. */
|
|
15
|
+
export const CLAUDE_PROFILE = {
|
|
16
|
+
vision: { regime: 'patch28' },
|
|
17
|
+
// Anthropic list prices: cache read $0.10 / 5m write $1.25 / input $1.00; output $5.00 / input.
|
|
18
|
+
cacheReadRate: 0.1,
|
|
19
|
+
cacheWriteRate: 1.25,
|
|
20
|
+
outputRate: 5,
|
|
21
|
+
stripCols: ANTHROPIC_STRIP_COLS,
|
|
22
|
+
maxHeightPx: ANTHROPIC_MAX_HEIGHT_PX,
|
|
23
|
+
visionTier: 'high-res',
|
|
24
|
+
factSheetFormat: 'full',
|
|
25
|
+
// BASE_HISTORY.maxImages is a page count, and a page is not a fixed amount of
|
|
26
|
+
// text: at GPT geometry (84 cols x 1954 px) a page holds ~660 chars, at
|
|
27
|
+
// Anthropic geometry (312 cols x 728 px) it holds ~2750. The shared 32 was
|
|
28
|
+
// tuned as a latency budget against the former, so on Claude it stopped being
|
|
29
|
+
// a latency budget and became a coverage limit: live Opus traffic pinned at
|
|
30
|
+
// 32 images on 70% of requests with collapsed text flatlined at ~97k chars
|
|
31
|
+
// while untouched history kept growing past 250k.
|
|
32
|
+
//
|
|
33
|
+
// Re-derived against the same latency signal on Claude pages (first-byte p50
|
|
34
|
+
// / p95, n=11k): 32 -> 5.2s/10.9s, 64 -> 8.3s/15.3s, 96 -> 11.4s/18.5s,
|
|
35
|
+
// 128 -> 12.5s/27.0s. Upstream 502s stay ~0.2% through 96 images and jump to
|
|
36
|
+
// 2.2-3.9% at 112+. 96 is the last point that is both cheap and clean.
|
|
37
|
+
//
|
|
38
|
+
// The same page-count-vs-geometry mismatch applies to the per-image framing.
|
|
39
|
+
// BASE_HISTORY pairs `framing: 'full'` with `factSheetScope: 'per-segment'`,
|
|
40
|
+
// which costs a 221-token intro + 25-token outro + a ~158-token fact sheet on
|
|
41
|
+
// EVERY segment. At GPT's 32-page ceiling that is a rounding error; at 96
|
|
42
|
+
// Claude pages it measured 425 tokens/image, 25.2k tokens/request, eating 57%
|
|
43
|
+
// of the gross saving the higher cap unlocked. Compact framing (36 + 8) with a
|
|
44
|
+
// single combined sheet carries the same attribution wording the transcript
|
|
45
|
+
// needs and projects 2.8k tokens/request on the same traffic.
|
|
46
|
+
//
|
|
47
|
+
// responsesMode: BASE_HISTORY's 'pairs' planner only groups tool rounds that
|
|
48
|
+
// are INDEX-CONTIGUOUS. Codex emits an assistant message between rounds, so
|
|
49
|
+
// every round lands in its own run and every run renders its own image. Live
|
|
50
|
+
// Claude-on-Responses traffic averaged 2,921 chars/image (10% of the 28,080
|
|
51
|
+
// a page holds) at 2.4 turns/image, against 10,456 (37%) for gpt-5.6-sol on
|
|
52
|
+
// the same endpoint — the only difference being that GPT already runs
|
|
53
|
+
// 'mixed'. Replaying a 60-round transcript through both planners isolates it
|
|
54
|
+
// to the interleaving, not the volume:
|
|
55
|
+
// pairs, no interleave -> 1 segment, 6 images, 27,653 chars/image
|
|
56
|
+
// pairs, interleaved -> 54 segments, 54 images, 3,073 chars/image
|
|
57
|
+
// mixed, interleaved -> 2 segments, 8 images, 21,109 chars/image
|
|
58
|
+
// 'mixed' treats safe textual messages as groupable instead of as barriers;
|
|
59
|
+
// every non-message item stays a hard barrier, so protocol order and open
|
|
60
|
+
// call/output state are preserved exactly as in 'pairs'.
|
|
61
|
+
history: {
|
|
62
|
+
...BASE_HISTORY,
|
|
63
|
+
maxImages: 96,
|
|
64
|
+
framing: 'compact',
|
|
65
|
+
factSheetScope: 'combined',
|
|
66
|
+
responsesMode: 'mixed',
|
|
67
|
+
},
|
|
68
|
+
style: { ...BASE_STYLE },
|
|
69
|
+
// No maxSerializedRequestBytes: no Anthropic request-size limit has ever been
|
|
70
|
+
// sourced. The 768 KiB entry that used to sit here was a guess, and live
|
|
71
|
+
// traffic contradicted it outright (thousands of clean 200s well above it).
|
|
72
|
+
};
|
|
73
|
+
/** Pre-4.7 Claude: same render geometry, standard image-resolution tier. */
|
|
74
|
+
export const CLAUDE_LEGACY_PROFILE = {
|
|
75
|
+
...CLAUDE_PROFILE,
|
|
76
|
+
visionTier: 'standard',
|
|
77
|
+
style: { ...BASE_STYLE },
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* Spaced geometry, DEFAULT for every Claude model except the original Fable 5:
|
|
81
|
+
* the same 312-col spleen-5x8 cell with 2 px of extra row height.
|
|
82
|
+
*
|
|
83
|
+
* Opus 5.5 gist recall (eval/gist-recall, 98 answerable, image arm):
|
|
84
|
+
*
|
|
85
|
+
* dense 5x8 84/98 2.31x cheaper than text
|
|
86
|
+
* 5x8 +2px rows 93/98 1.85x
|
|
87
|
+
* jetbrains-mono-14 -- 0.54-0.92x (costs MORE than text on this corpus)
|
|
88
|
+
*
|
|
89
|
+
* 0/16 confabulations at every geometry. Bare 5x8 glyphs are not the problem
|
|
90
|
+
* (sparse ids 99.9% per char); misses came from crowded rows. The 14px profile
|
|
91
|
+
* this replaces was legible but no longer saved tokens, so it was dropped.
|
|
92
|
+
*/
|
|
93
|
+
const CLAUDE_SPACED_STYLE = {
|
|
94
|
+
...BASE_STYLE,
|
|
95
|
+
cellHBonus: 2,
|
|
96
|
+
};
|
|
97
|
+
export const CLAUDE_SPACED_PROFILE = {
|
|
98
|
+
...CLAUDE_PROFILE,
|
|
99
|
+
style: { ...CLAUDE_SPACED_STYLE },
|
|
100
|
+
historyStyle: { ...CLAUDE_SPACED_STYLE },
|
|
101
|
+
};
|
|
102
|
+
export const CLAUDE_LEGACY_SPACED_PROFILE = {
|
|
103
|
+
...CLAUDE_LEGACY_PROFILE,
|
|
104
|
+
style: { ...CLAUDE_SPACED_STYLE },
|
|
105
|
+
historyStyle: { ...CLAUDE_SPACED_STYLE },
|
|
106
|
+
};
|
|
107
|
+
/**
|
|
108
|
+
* True only for the original Fable 5, the one Claude release measured accurate
|
|
109
|
+
* at bare dense geometry. Its point releases are not: dense hex
|
|
110
|
+
* (eval/verbatim-15, N=15, same needles) on claude-fable-5-2 reads
|
|
111
|
+
*
|
|
112
|
+
* dense 5x8 7/15
|
|
113
|
+
* 5x8 +2px rows 13/15 (what Fable 5 scores unspaced)
|
|
114
|
+
*
|
|
115
|
+
* so 5.1+ and any unrecognised Fable get spaced rows. `\d{1,2}(?!\d)` keeps a
|
|
116
|
+
* trailing date stamp (`claude-fable-5-20260601`) from reading as a minor.
|
|
117
|
+
*/
|
|
118
|
+
export function isBareDenseFable(model) {
|
|
119
|
+
const v = /fable-(\d+)(?:[-.](\d{1,2})(?!\d))?/.exec(model.toLowerCase());
|
|
120
|
+
return v !== null && Number(v[1]) === 5 && Number(v[2] ?? '0') === 0;
|
|
121
|
+
}
|
|
122
|
+
/** Every id that must be priced and rendered as Claude. */
|
|
123
|
+
export function isClaudeModel(model) {
|
|
124
|
+
const m = (model ?? '').toLowerCase();
|
|
125
|
+
// `includes`, not `startsWith`: gateway ids carry a vendor prefix
|
|
126
|
+
// (`anthropic/claude-opus-5`, `us.anthropic.claude-3-5-sonnet-v1:0`).
|
|
127
|
+
return m.includes('claude') || m.includes('anthropic');
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* True for Claude releases older than 4.7. Anthropic's vision docs tier the
|
|
131
|
+
* pre-billing downscale by VERSION, not by model family or an enumerated list:
|
|
132
|
+
*
|
|
133
|
+
* | High-resolution | Claude 4.7 and later models | 2576 px | 4784 |
|
|
134
|
+
* | Standard | All other models | 1568 px | 1568 |
|
|
135
|
+
*
|
|
136
|
+
* Reads the first version number in the id, tolerating both id orderings
|
|
137
|
+
* (`claude-opus-4-8` -> 4.8, `claude-3-5-sonnet` -> 3.5) and trailing date
|
|
138
|
+
* stamps. An unrecognised Claude id is treated as new: an unreleased model is
|
|
139
|
+
* far likelier to be 4.7+, and high-res is the safe guess for the gate because
|
|
140
|
+
* it over-estimates cost, whereas standard under-estimates it by assuming a
|
|
141
|
+
* downscale the server will not perform.
|
|
142
|
+
*/
|
|
143
|
+
export function isPre47Claude(m) {
|
|
144
|
+
const v = /claude-(?:[a-z]+-)?(\d+)(?:[-.](\d{1,2})(?!\d))?/.exec(m);
|
|
145
|
+
if (!v)
|
|
146
|
+
return false;
|
|
147
|
+
const [major, minor] = [Number(v[1]), Number(v[2] ?? '0')];
|
|
148
|
+
return major < 4 || (major === 4 && minor < 7);
|
|
149
|
+
}
|
|
150
|
+
/** Pick the Claude profile for an id. Billing geometry is identical across
|
|
151
|
+
* opus/sonnet/haiku/fable; HISTORY geometry is not, because verbatim recall
|
|
152
|
+
* at dense geometry is a per-model property (see CLAUDE_SPACED_PROFILE).
|
|
153
|
+
* Fable 5 keeps bare dense; every other Claude id gets spaced rows. */
|
|
154
|
+
export function resolveClaudeProfile(m) {
|
|
155
|
+
if (isBareDenseFable(m)) {
|
|
156
|
+
return isPre47Claude(m) ? CLAUDE_LEGACY_PROFILE : CLAUDE_PROFILE;
|
|
157
|
+
}
|
|
158
|
+
return isPre47Claude(m) ? CLAUDE_LEGACY_SPACED_PROFILE : CLAUDE_SPACED_PROFILE;
|
|
159
|
+
}
|
|
160
|
+
//# sourceMappingURL=claude-model-profiles.js.map
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client detection for the history-collapse round shape. Kept free of proxy
|
|
3
|
+
* dependencies so the proxy and the Worker apply the same rule.
|
|
4
|
+
*/
|
|
5
|
+
/** Anything with a case-insensitive `get`, e.g. the Fetch `Headers` class. */
|
|
6
|
+
export interface HeaderReader {
|
|
7
|
+
get(name: string): string | null;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Claude Code sends a parallel tool batch as ONE assistant message, so each
|
|
11
|
+
* closed call/result pair is a safe history boundary even across pure tool
|
|
12
|
+
* loops with no text-only assistant turn. An explicit option from the host
|
|
13
|
+
* (`FICHE_TRUST_ADJACENT_TOOL_ROUNDS`) wins over header detection.
|
|
14
|
+
*/
|
|
15
|
+
export declare function withClientToolRoundShape<T extends {
|
|
16
|
+
separateAdjacentToolPairs?: boolean;
|
|
17
|
+
}>(opts: T | undefined, headers: HeaderReader | null | undefined): T | undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Resolve `FICHE_TRUST_ADJACENT_TOOL_ROUNDS` for a host (Node or Worker).
|
|
20
|
+
* Returns `value` (`undefined` = decide from client headers) and, for an
|
|
21
|
+
* unrecognized value, the warning string the host should log.
|
|
22
|
+
*/
|
|
23
|
+
export declare function resolveTrustAdjacentToolRoundsEnv(raw: string | undefined): {
|
|
24
|
+
value: boolean | undefined;
|
|
25
|
+
warning?: string;
|
|
26
|
+
};
|
|
27
|
+
export declare function parseTrustAdjacentToolRounds(raw: string | undefined): {
|
|
28
|
+
value: boolean | undefined;
|
|
29
|
+
invalid: boolean;
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=client-tool-round.d.ts.map
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client detection for the history-collapse round shape. Kept free of proxy
|
|
3
|
+
* dependencies so the proxy and the Worker apply the same rule.
|
|
4
|
+
*/
|
|
5
|
+
/** `x-app` values Claude Code sends (foreground and background sessions). */
|
|
6
|
+
const CLAUDE_CODE_X_APP = new Set(['cli', 'cli-bg']);
|
|
7
|
+
/**
|
|
8
|
+
* True only when both Claude Code identity headers are present: the
|
|
9
|
+
* `claude-cli/` User-Agent prefix AND an `x-app: cli|cli-bg` header. A tool
|
|
10
|
+
* that only copies the User-Agent string does not match, so it keeps the
|
|
11
|
+
* conservative round-level boundaries.
|
|
12
|
+
*/
|
|
13
|
+
function isClaudeCodeClient(headers) {
|
|
14
|
+
if (!headers)
|
|
15
|
+
return false;
|
|
16
|
+
const userAgent = headers.get('user-agent') ?? '';
|
|
17
|
+
const xApp = (headers.get('x-app') ?? '').trim().toLowerCase();
|
|
18
|
+
return userAgent.startsWith('claude-cli/') && CLAUDE_CODE_X_APP.has(xApp);
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Claude Code sends a parallel tool batch as ONE assistant message, so each
|
|
22
|
+
* closed call/result pair is a safe history boundary even across pure tool
|
|
23
|
+
* loops with no text-only assistant turn. An explicit option from the host
|
|
24
|
+
* (`FICHE_TRUST_ADJACENT_TOOL_ROUNDS`) wins over header detection.
|
|
25
|
+
*/
|
|
26
|
+
export function withClientToolRoundShape(opts, headers) {
|
|
27
|
+
if (opts?.separateAdjacentToolPairs !== undefined)
|
|
28
|
+
return opts;
|
|
29
|
+
if (!isClaudeCodeClient(headers))
|
|
30
|
+
return opts;
|
|
31
|
+
return { ...opts, separateAdjacentToolPairs: true };
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Resolve `FICHE_TRUST_ADJACENT_TOOL_ROUNDS` for a host (Node or Worker).
|
|
35
|
+
* Returns `value` (`undefined` = decide from client headers) and, for an
|
|
36
|
+
* unrecognized value, the warning string the host should log.
|
|
37
|
+
*/
|
|
38
|
+
export function resolveTrustAdjacentToolRoundsEnv(raw) {
|
|
39
|
+
const parsed = parseTrustAdjacentToolRounds(raw);
|
|
40
|
+
if (!parsed.invalid)
|
|
41
|
+
return { value: parsed.value };
|
|
42
|
+
return {
|
|
43
|
+
value: undefined,
|
|
44
|
+
warning: `[fiche] FICHE_TRUST_ADJACENT_TOOL_ROUNDS=${JSON.stringify(raw)} not recognized ` +
|
|
45
|
+
'(use 1/0) — falling back to client-header detection',
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export function parseTrustAdjacentToolRounds(raw) {
|
|
49
|
+
const s = (raw ?? '').trim();
|
|
50
|
+
if (s === '')
|
|
51
|
+
return { value: undefined, invalid: false };
|
|
52
|
+
if (/^(1|true|yes|on)$/i.test(s))
|
|
53
|
+
return { value: true, invalid: false };
|
|
54
|
+
if (/^(0|false|no|off)$/i.test(s))
|
|
55
|
+
return { value: false, invalid: false };
|
|
56
|
+
return { value: undefined, invalid: true };
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=client-tool-round.js.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChatGPT Codex (`https://chatgpt.com/backend-api/codex/responses`) rejects
|
|
3
|
+
* `prompt_cache_breakpoint` with HTTP 400. api.openai.com still accepts the
|
|
4
|
+
* explicit breakpoint on GPT-5.6 / GPT-6 profiles. The decision is the
|
|
5
|
+
* upstream, not the model id.
|
|
6
|
+
*/
|
|
7
|
+
export interface PromptCacheRoute {
|
|
8
|
+
pathname?: string | null;
|
|
9
|
+
upstream?: string | null;
|
|
10
|
+
}
|
|
11
|
+
/** True when this route may receive an explicit prompt_cache_breakpoint. */
|
|
12
|
+
export declare function supportsExplicitPromptCacheBreakpoint(route?: PromptCacheRoute): boolean;
|
|
13
|
+
/** Drop breakpoint objects of the injected shape, editing the text in place.
|
|
14
|
+
* Nothing else is reserialized, so large integers, number spellings and
|
|
15
|
+
* key order survive, and a tool schema with a property of the same name is
|
|
16
|
+
* left alone. Bodies without the key are returned unchanged, so a Codex
|
|
17
|
+
* passthrough stays byte-identical. */
|
|
18
|
+
export declare function scrubPromptCacheBreakpoint(body: Uint8Array): Uint8Array;
|
|
19
|
+
export declare function bodyHasPromptCacheBreakpoint(body: Uint8Array | string): boolean;
|
|
20
|
+
//# sourceMappingURL=codex-cache.d.ts.map
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ChatGPT Codex (`https://chatgpt.com/backend-api/codex/responses`) rejects
|
|
3
|
+
* `prompt_cache_breakpoint` with HTTP 400. api.openai.com still accepts the
|
|
4
|
+
* explicit breakpoint on GPT-5.6 / GPT-6 profiles. The decision is the
|
|
5
|
+
* upstream, not the model id.
|
|
6
|
+
*/
|
|
7
|
+
function hostOf(upstream) {
|
|
8
|
+
const trimmed = upstream.trim();
|
|
9
|
+
if (!trimmed)
|
|
10
|
+
return '';
|
|
11
|
+
try {
|
|
12
|
+
return new URL(trimmed.includes('://') ? trimmed : `https://${trimmed}`).hostname.toLowerCase();
|
|
13
|
+
}
|
|
14
|
+
catch {
|
|
15
|
+
return trimmed.toLowerCase();
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** True when this route may receive an explicit prompt_cache_breakpoint. */
|
|
19
|
+
export function supportsExplicitPromptCacheBreakpoint(route = {}) {
|
|
20
|
+
const path = route.pathname ?? '';
|
|
21
|
+
// Every Codex path (/responses, /responses/compact, ...), bare or prefixed.
|
|
22
|
+
if (/(^|\/)backend-api\/codex(\/|$)/.test(path))
|
|
23
|
+
return false;
|
|
24
|
+
const host = hostOf(route.upstream ?? '');
|
|
25
|
+
if (host === 'chatgpt.com' || host.endsWith('.chatgpt.com'))
|
|
26
|
+
return false;
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
// The only breakpoint this proxy injects is `{ mode: 'explicit' }` on a
|
|
30
|
+
// content part (openai.ts). Match that object as a key/value pair: after a
|
|
31
|
+
// comma, or right after `{`. Inside a JSON string the quotes are escaped, so
|
|
32
|
+
// `,"` and `{"` cannot match there.
|
|
33
|
+
const AFTER_COMMA = /,\s*"prompt_cache_breakpoint"\s*:\s*\{\s*"mode"\s*:\s*"explicit"\s*\}/g;
|
|
34
|
+
const AFTER_BRACE = /(?<=\{)\s*"prompt_cache_breakpoint"\s*:\s*\{\s*"mode"\s*:\s*"explicit"\s*\}\s*,?/g;
|
|
35
|
+
/** Drop breakpoint objects of the injected shape, editing the text in place.
|
|
36
|
+
* Nothing else is reserialized, so large integers, number spellings and
|
|
37
|
+
* key order survive, and a tool schema with a property of the same name is
|
|
38
|
+
* left alone. Bodies without the key are returned unchanged, so a Codex
|
|
39
|
+
* passthrough stays byte-identical. */
|
|
40
|
+
export function scrubPromptCacheBreakpoint(body) {
|
|
41
|
+
const text = new TextDecoder().decode(body);
|
|
42
|
+
if (!text.includes('"prompt_cache_breakpoint"'))
|
|
43
|
+
return body;
|
|
44
|
+
const next = text.replace(AFTER_COMMA, '').replace(AFTER_BRACE, '');
|
|
45
|
+
if (next === text)
|
|
46
|
+
return body;
|
|
47
|
+
try {
|
|
48
|
+
JSON.parse(next);
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return body;
|
|
52
|
+
}
|
|
53
|
+
return new TextEncoder().encode(next);
|
|
54
|
+
}
|
|
55
|
+
export function bodyHasPromptCacheBreakpoint(body) {
|
|
56
|
+
const text = typeof body === 'string' ? body : new TextDecoder().decode(body);
|
|
57
|
+
return text.includes('"prompt_cache_breakpoint"');
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=codex-cache.js.map
|