@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,57 @@
|
|
|
1
|
+
import { type PriceContext } from './pricing.js';
|
|
2
|
+
/** Cached-input ÷ uncached-input list-price ratio for the model serving this
|
|
3
|
+
* request. The ratio is a PROFILE field (`cacheReadRate`), so a new family is
|
|
4
|
+
* a profile entry or a INKLING_GPT_PROFILES override — not a regex added here,
|
|
5
|
+
* which is how the gate and the savings math previously drifted apart. */
|
|
6
|
+
export declare function openAICacheReadRate(model: string | undefined, ctx?: PriceContext): number;
|
|
7
|
+
/** Output ÷ uncached-input list-price ratio, from the same profile. */
|
|
8
|
+
export declare function openAIOutputRate(model: string | undefined, ctx?: PriceContext): number;
|
|
9
|
+
/** Weighted input tokens actually paid to OpenAI this turn. `cachedTokens` is a
|
|
10
|
+
* subset of `inputTokens`, not an additive bucket. */
|
|
11
|
+
export declare function computeOpenAIActualInputEff(inputTokens: number, cachedTokens: number, model?: string, cacheWriteTokens?: number, ctx?: PriceContext): number;
|
|
12
|
+
export declare function computeOpenAICollapsePaybackReads(nativeTokens: number, collapsedTokens: number, model?: string, ctx?: PriceContext): number;
|
|
13
|
+
/** Raw token count for the unproxied GPT counterfactual: replace the rendered
|
|
14
|
+
* images with the o200k text they stood in for (plus any text hygiene delta). */
|
|
15
|
+
export declare function computeOpenAIBaselineRawTokens(inputTokens: number, imageTokens: number, baselineImagedTokens: number, nativeInjectedTokens?: number, textHygieneSavedTokens?: number): number;
|
|
16
|
+
export declare function computeOpenAIBaselineInputEff(inputTokens: number, cachedTokens: number, imageTokens: number, baselineImagedTokens: number, model?: string, nativeInjectedTokens?: number, cacheWriteTokens?: number, ctx?: PriceContext): number;
|
|
17
|
+
export interface OpenAIWarmthPrev {
|
|
18
|
+
ts: number;
|
|
19
|
+
cachedOrPrefixTokens: number;
|
|
20
|
+
prefixSha?: string;
|
|
21
|
+
pxPrefixSha?: string;
|
|
22
|
+
model?: string;
|
|
23
|
+
}
|
|
24
|
+
export declare const OPENAI_CACHE_TTL_SEC = 300;
|
|
25
|
+
/**
|
|
26
|
+
* Determine whether the unproxied OpenAI/Codex/compat baseline prefix would have
|
|
27
|
+
* read warm on this turn, and detect when a transform busted an active prefix
|
|
28
|
+
* cache (warm prior within TTL + same prefix/model + changed outbound pxPrefixSha followed by cached_tokens === 0).
|
|
29
|
+
*/
|
|
30
|
+
export declare function deriveOpenAIBaselineWarmth(prev: OpenAIWarmthPrev | undefined, requestStartSec: number, cachedTokens: number, prefixSha?: string, model?: string, ttlSec?: number, pxPrefixSha?: string): {
|
|
31
|
+
warm: boolean;
|
|
32
|
+
selfBusted: boolean;
|
|
33
|
+
prevPrefixTokens: number;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Session- and hygiene-aware OpenAI/Codex/compat baseline input-equivalent cost.
|
|
37
|
+
* Credits both image replacement and deterministic text-hygiene token deltas,
|
|
38
|
+
* and surfaces negative savings when a turn busts a live prefix cache.
|
|
39
|
+
*/
|
|
40
|
+
export declare function computeOpenAISessionBaselineInputEff(args: {
|
|
41
|
+
inputTokens: number;
|
|
42
|
+
cachedTokens: number;
|
|
43
|
+
imageTokens: number;
|
|
44
|
+
baselineImagedTokens: number;
|
|
45
|
+
nativeInjectedTokens?: number;
|
|
46
|
+
textHygieneSavedTokens?: number;
|
|
47
|
+
prevHygieneSavedTokens?: number;
|
|
48
|
+
cacheWriteTokens?: number;
|
|
49
|
+
ttlSec?: number;
|
|
50
|
+
model?: string;
|
|
51
|
+
warmth?: {
|
|
52
|
+
warm: boolean;
|
|
53
|
+
selfBusted: boolean;
|
|
54
|
+
prevPrefixTokens: number;
|
|
55
|
+
};
|
|
56
|
+
}): number;
|
|
57
|
+
//# sourceMappingURL=openai-savings.d.ts.map
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { resolvePriceRates } from './pricing.js';
|
|
2
|
+
/** Cached-input ÷ uncached-input list-price ratio for the model serving this
|
|
3
|
+
* request. The ratio is a PROFILE field (`cacheReadRate`), so a new family is
|
|
4
|
+
* a profile entry or a INKLING_GPT_PROFILES override — not a regex added here,
|
|
5
|
+
* which is how the gate and the savings math previously drifted apart. */
|
|
6
|
+
export function openAICacheReadRate(model, ctx) {
|
|
7
|
+
return resolvePriceRates(model, ctx).read;
|
|
8
|
+
}
|
|
9
|
+
/** Output ÷ uncached-input list-price ratio, from the same profile. */
|
|
10
|
+
export function openAIOutputRate(model, ctx) {
|
|
11
|
+
return resolvePriceRates(model, ctx).output;
|
|
12
|
+
}
|
|
13
|
+
/** Weighted input tokens actually paid to OpenAI this turn. `cachedTokens` is a
|
|
14
|
+
* subset of `inputTokens`, not an additive bucket. */
|
|
15
|
+
export function computeOpenAIActualInputEff(inputTokens, cachedTokens, model, cacheWriteTokens = 0, ctx) {
|
|
16
|
+
if (inputTokens <= 0)
|
|
17
|
+
return 0;
|
|
18
|
+
const cached = Math.max(0, Math.min(cachedTokens || 0, inputTokens));
|
|
19
|
+
const written = Math.max(0, Math.min(cacheWriteTokens || 0, inputTokens - cached));
|
|
20
|
+
const uncached = inputTokens - cached - written;
|
|
21
|
+
const rates = resolvePriceRates(model, ctx ?? { promptTokens: inputTokens });
|
|
22
|
+
return uncached + cached * rates.read + written * rates.write;
|
|
23
|
+
}
|
|
24
|
+
export function computeOpenAICollapsePaybackReads(nativeTokens, collapsedTokens, model, ctx) {
|
|
25
|
+
const rates = resolvePriceRates(model, ctx);
|
|
26
|
+
const savedPerRead = (nativeTokens - collapsedTokens) * rates.read;
|
|
27
|
+
if (!(savedPerRead > 0))
|
|
28
|
+
return Infinity;
|
|
29
|
+
const transitionCost = collapsedTokens * rates.write
|
|
30
|
+
- nativeTokens * rates.read;
|
|
31
|
+
return Math.ceil(Math.max(0, transitionCost) / savedPerRead);
|
|
32
|
+
}
|
|
33
|
+
/** Raw token count for the unproxied GPT counterfactual: replace the rendered
|
|
34
|
+
* images with the o200k text they stood in for (plus any text hygiene delta). */
|
|
35
|
+
export function computeOpenAIBaselineRawTokens(inputTokens, imageTokens, baselineImagedTokens, nativeInjectedTokens = 0, textHygieneSavedTokens = 0) {
|
|
36
|
+
if (inputTokens <= 0)
|
|
37
|
+
return 0;
|
|
38
|
+
const delta = (baselineImagedTokens || 0) - (imageTokens || 0);
|
|
39
|
+
return Math.max(0, inputTokens + delta - Math.max(0, nativeInjectedTokens || 0) + Math.max(0, textHygieneSavedTokens || 0));
|
|
40
|
+
}
|
|
41
|
+
export function computeOpenAIBaselineInputEff(inputTokens, cachedTokens, imageTokens, baselineImagedTokens, model, nativeInjectedTokens = 0, cacheWriteTokens = 0, ctx) {
|
|
42
|
+
const priceCtx = ctx ?? { promptTokens: inputTokens };
|
|
43
|
+
const actual = computeOpenAIActualInputEff(inputTokens, cachedTokens, model, cacheWriteTokens, priceCtx);
|
|
44
|
+
if (inputTokens <= 0 || imageTokens <= 0 || baselineImagedTokens <= 0)
|
|
45
|
+
return actual;
|
|
46
|
+
const delta = baselineImagedTokens - imageTokens;
|
|
47
|
+
const rates = resolvePriceRates(model, priceCtx);
|
|
48
|
+
const deltaWeight = (cachedTokens || 0) > 0 ? rates.read
|
|
49
|
+
: cacheWriteTokens > 0 ? rates.write : 1;
|
|
50
|
+
// Synthetic native text occupies the same stable prefix as the images, so
|
|
51
|
+
// apply the same observed cache weight as the replacement delta.
|
|
52
|
+
return actual + (delta - Math.max(0, nativeInjectedTokens || 0)) * deltaWeight;
|
|
53
|
+
}
|
|
54
|
+
export const OPENAI_CACHE_TTL_SEC = 300;
|
|
55
|
+
/**
|
|
56
|
+
* Determine whether the unproxied OpenAI/Codex/compat baseline prefix would have
|
|
57
|
+
* read warm on this turn, and detect when a transform busted an active prefix
|
|
58
|
+
* cache (warm prior within TTL + same prefix/model + changed outbound pxPrefixSha followed by cached_tokens === 0).
|
|
59
|
+
*/
|
|
60
|
+
export function deriveOpenAIBaselineWarmth(prev, requestStartSec, cachedTokens, prefixSha, model, ttlSec = OPENAI_CACHE_TTL_SEC, pxPrefixSha) {
|
|
61
|
+
if (cachedTokens > 0) {
|
|
62
|
+
return { warm: true, selfBusted: false, prevPrefixTokens: prev?.cachedOrPrefixTokens ?? 0 };
|
|
63
|
+
}
|
|
64
|
+
const ageSec = prev ? requestStartSec - prev.ts : Infinity;
|
|
65
|
+
const samePrefix = !prefixSha || !prev?.prefixSha || prefixSha === prev.prefixSha;
|
|
66
|
+
const sameModel = !model || !prev?.model || model === prev.model;
|
|
67
|
+
// When outbound prefix digests are supplied on both turns, require an actual
|
|
68
|
+
// byte-level change before attributing a cache miss to proxy self-busting.
|
|
69
|
+
const pxPrefixChanged = prev?.pxPrefixSha !== undefined && pxPrefixSha !== undefined
|
|
70
|
+
? prev.pxPrefixSha !== pxPrefixSha
|
|
71
|
+
: true;
|
|
72
|
+
if (prev &&
|
|
73
|
+
ageSec >= 0 &&
|
|
74
|
+
ageSec <= ttlSec &&
|
|
75
|
+
prev.cachedOrPrefixTokens > 0 &&
|
|
76
|
+
samePrefix &&
|
|
77
|
+
sameModel &&
|
|
78
|
+
pxPrefixChanged) {
|
|
79
|
+
return { warm: true, selfBusted: true, prevPrefixTokens: prev.cachedOrPrefixTokens };
|
|
80
|
+
}
|
|
81
|
+
return { warm: false, selfBusted: false, prevPrefixTokens: 0 };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Session- and hygiene-aware OpenAI/Codex/compat baseline input-equivalent cost.
|
|
85
|
+
* Credits both image replacement and deterministic text-hygiene token deltas,
|
|
86
|
+
* and surfaces negative savings when a turn busts a live prefix cache.
|
|
87
|
+
*/
|
|
88
|
+
export function computeOpenAISessionBaselineInputEff(args) {
|
|
89
|
+
const { inputTokens, cachedTokens, imageTokens, baselineImagedTokens, nativeInjectedTokens = 0, textHygieneSavedTokens = 0, prevHygieneSavedTokens, cacheWriteTokens = 0, ttlSec, model, warmth, } = args;
|
|
90
|
+
const priceCtx = { promptTokens: inputTokens, ...(ttlSec !== undefined ? { ttlSec } : {}) };
|
|
91
|
+
const actual = computeOpenAIActualInputEff(inputTokens, cachedTokens, model, cacheWriteTokens, priceCtx);
|
|
92
|
+
const imagedDelta = imageTokens > 0 && baselineImagedTokens > 0
|
|
93
|
+
? baselineImagedTokens - imageTokens - Math.max(0, nativeInjectedTokens || 0)
|
|
94
|
+
: 0;
|
|
95
|
+
const hygieneDelta = Math.max(0, textHygieneSavedTokens || 0);
|
|
96
|
+
if (inputTokens <= 0 || (imagedDelta === 0 && hygieneDelta === 0 && !warmth?.selfBusted)) {
|
|
97
|
+
return Math.max(0, actual);
|
|
98
|
+
}
|
|
99
|
+
const rates = resolvePriceRates(model, priceCtx);
|
|
100
|
+
const readRate = rates.read;
|
|
101
|
+
const writeRate = rates.write;
|
|
102
|
+
const newTurnRate = cacheWriteTokens > 0 ? writeRate : 1;
|
|
103
|
+
if (warmth?.selfBusted) {
|
|
104
|
+
const unproxiedRaw = Math.max(0, inputTokens + imagedDelta + hygieneDelta);
|
|
105
|
+
const reused = Math.min(unproxiedRaw, warmth.prevPrefixTokens);
|
|
106
|
+
return Math.max(0, reused * readRate + (unproxiedRaw - reused) * newTurnRate);
|
|
107
|
+
}
|
|
108
|
+
if (prevHygieneSavedTokens !== undefined && cachedTokens > 0) {
|
|
109
|
+
const cachedHygiene = Math.min(hygieneDelta, Math.max(0, prevHygieneSavedTokens));
|
|
110
|
+
const uncachedHygiene = hygieneDelta - cachedHygiene;
|
|
111
|
+
return Math.max(0, actual + (imagedDelta + cachedHygiene) * readRate + uncachedHygiene * newTurnRate);
|
|
112
|
+
}
|
|
113
|
+
const deltaWeight = cachedTokens > 0 ? readRate : newTurnRate;
|
|
114
|
+
return Math.max(0, actual + (imagedDelta + hygieneDelta) * deltaWeight);
|
|
115
|
+
}
|
|
116
|
+
//# sourceMappingURL=openai-savings.js.map
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OpenAI Chat Completions + Responses API transformer for the GPT-5 family.
|
|
3
|
+
* Separate from the Anthropic path: no cache-control breakpoints,
|
|
4
|
+
* images as image_url/input_image parts, system/developer messages in messages[]/input[].
|
|
5
|
+
* OpenAI tools keep native names/descriptions/schema shape; verbose schema prose
|
|
6
|
+
* is also rendered into images for token savings so calls do not depend only on OCR.
|
|
7
|
+
*/
|
|
8
|
+
import { type GptModelProfile, type GptVisionCost } from './gpt-model-profiles.js';
|
|
9
|
+
import { type TransformInfo, type TransformOptions } from './transform.js';
|
|
10
|
+
type VisionCost = GptVisionCost;
|
|
11
|
+
export declare function resolveVisionCost(model: string): VisionCost;
|
|
12
|
+
export declare const HISTORY_TRANSCRIPT_INTRO = "[Earlier turns of THIS conversation, transcribed in the image(s) below. Each turn is wrapped in <user t=\"N\">...</user> or <assistant t=\"N\">...</assistant> tags, where N is an absolute turn index (larger N = more recent); attribute every turn strictly by its tag, and treat the highest-N turns as the most recent prior context, NOT the low-N opening turns. Earlier turns may contain questions or tasks that were already answered later in this same history; do not reopen low-N turns unless the live text after this block asks you to. For exact identifiers, hashes, version strings, and numbers from the transcript, rely on the exact-value factsheet or re-read the source; do not guess an exact value seen only in the image. This is prior context, NOT the current request.]";
|
|
13
|
+
export declare const HISTORY_TRANSCRIPT_OUTRO = "[End of earlier conversation. The current request is the live text that follows below.]";
|
|
14
|
+
export declare const COMPACT_HISTORY_TRANSCRIPT_INTRO = "[Earlier turns in image(s): follow <user t=N>/<assistant t=N> tags in increasing N. Prior context\u2014not the current request.]";
|
|
15
|
+
export declare const COMPACT_HISTORY_TRANSCRIPT_OUTRO = "[End earlier conversation.]";
|
|
16
|
+
export declare function pinnedRequestBlock(text: string): string;
|
|
17
|
+
export declare function buildLiveRequestGuard(pinText?: string): string;
|
|
18
|
+
/** Alias of `visionTokensForModel`, kept for OpenAI-path call sites and tests.
|
|
19
|
+
* There is no separate OpenAI formula: the model's profile carries its regime. */
|
|
20
|
+
export declare function openAIVisionTokens(model: string, w: number, h: number): number;
|
|
21
|
+
/** True when this Responses/Chat request is actually served by a Claude model.
|
|
22
|
+
* Codex-style clients speak OpenAI Responses while some models are Anthropic,
|
|
23
|
+
* so routing must agree with pricing: this re-exports the SAME predicate the
|
|
24
|
+
* profile table uses to route an id to the Anthropic profile. A second, subtly
|
|
25
|
+
* different copy here would route a request one way and price it the other. */
|
|
26
|
+
export { isClaudeModel } from './claude-model-profiles.js';
|
|
27
|
+
/** Per-image vision-token cost for the model actually serving the request.
|
|
28
|
+
* Model-based, not endpoint-based, and family-agnostic: the profile's `vision`
|
|
29
|
+
* regime decides the formula (Anthropic patches, OpenAI tiles/patches, Grok
|
|
30
|
+
* pixels, Gemini flat), so no provider branch is needed here. This is the exact
|
|
31
|
+
* provider cost; the gate applies its own margin separately. */
|
|
32
|
+
export declare function visionTokensForModel(model: string, w: number, h: number): number;
|
|
33
|
+
/** Profile-controlled native overflow is shared with rendered-content evals. */
|
|
34
|
+
export declare function historyFactSheet(text: string, profile: GptModelProfile, coveredTokens?: ReadonlySet<string>): string;
|
|
35
|
+
/** Bounded to one request. Only extraction is reused; final coverage-dependent
|
|
36
|
+
* output is always recomputed. No cross-request retention of source text. */
|
|
37
|
+
export declare function createHistoryFactSheetRenderer(profile: GptModelProfile, limits?: {
|
|
38
|
+
maxEntries?: number;
|
|
39
|
+
maxChars?: number;
|
|
40
|
+
}): {
|
|
41
|
+
render(text: string, coveredTokens?: ReadonlySet<string>): string;
|
|
42
|
+
beginEmission: () => void;
|
|
43
|
+
stats: () => {
|
|
44
|
+
entries: number;
|
|
45
|
+
chars: number;
|
|
46
|
+
hits: number;
|
|
47
|
+
misses: number;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export declare function prepareImagedRenderText(text: string, reflowEnabled: boolean): string;
|
|
51
|
+
/** Render schema annotations removed from the native tool definition. The full
|
|
52
|
+
* top-level description rides in the same image and is replaced by a short
|
|
53
|
+
* per-tool pointer, matching the Anthropic tool-reference approach. */
|
|
54
|
+
export declare function schemaAnnotationLines(node: unknown, path?: string, depth?: number): string[];
|
|
55
|
+
/** Shared by normal outbound requests and profile-aligned evaluations. */
|
|
56
|
+
export declare function openAIImageDetail(model?: string): 'original' | 'high';
|
|
57
|
+
export declare function droppedCodepointsTop(droppedCodepoints: Map<number, number>): Record<string, number> | undefined;
|
|
58
|
+
export declare const CHAT_HEADER: string;
|
|
59
|
+
export declare const RESPONSES_HEADER: string;
|
|
60
|
+
export declare function transformOpenAIChatCompletions(body: Uint8Array, opts?: TransformOptions): Promise<{
|
|
61
|
+
body: Uint8Array;
|
|
62
|
+
info: TransformInfo;
|
|
63
|
+
}>;
|
|
64
|
+
export declare function transformOpenAIResponses(body: Uint8Array, opts?: TransformOptions): Promise<{
|
|
65
|
+
body: Uint8Array;
|
|
66
|
+
info: TransformInfo;
|
|
67
|
+
}>;
|
|
68
|
+
//# sourceMappingURL=openai.d.ts.map
|