@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,252 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* fiche proxy as a single Web-standard fetch handler.
|
|
3
|
+
* Adapted by src/node.ts and src/worker.ts; uses only Request/Response/URL/fetch.
|
|
4
|
+
*/
|
|
5
|
+
import { type TransformOptions, type TransformInfo } from './transform.js';
|
|
6
|
+
import type { Usage } from './types.js';
|
|
7
|
+
import type { DecodeRequestBodyResult } from '../request-decoding.js';
|
|
8
|
+
import { type ProviderId, type UpstreamRegistry } from './upstream-hosts.js';
|
|
9
|
+
export { parseTrustAdjacentToolRounds, resolveTrustAdjacentToolRoundsEnv, withClientToolRoundShape, } from './client-tool-round.js';
|
|
10
|
+
export interface ProxyConfig {
|
|
11
|
+
/** 'cloudflare-ai-gateway': routes both families through gatewayBaseUrl;
|
|
12
|
+
* OpenAI paths drop the `/v1` prefix to match gateway shape. */
|
|
13
|
+
provider?: 'cloudflare-ai-gateway';
|
|
14
|
+
/** Gateway base URL (account/gateway-scoped). Required when provider is set. */
|
|
15
|
+
gatewayBaseUrl?: string;
|
|
16
|
+
/** Extra headers injected on every upstream request (e.g. gateway auth). */
|
|
17
|
+
gatewayHeaders?: Record<string, string>;
|
|
18
|
+
/** Anthropic API base, no trailing slash. Defaults to api.anthropic.com. */
|
|
19
|
+
upstream?: string;
|
|
20
|
+
/** Optional shared upstream base (FICHE_UPSTREAM) applied across families
|
|
21
|
+
* when family-specific upstreams are not set; kept distinct from `upstream`
|
|
22
|
+
* so `ANTHROPIC_UPSTREAM` never hijacks base-URL Gemini requests. */
|
|
23
|
+
sharedUpstream?: string;
|
|
24
|
+
/** Override or supply an API key. If unset, we forward whatever the client sent. */
|
|
25
|
+
apiKey?: string;
|
|
26
|
+
/** Override the Anthropic `authorization` bearer. Pass a function to re-resolve
|
|
27
|
+
* per request: subscription tokens expire, and a client that froze its bearer
|
|
28
|
+
* at startup (a container env var) cannot renew one mid-run. Resolving here
|
|
29
|
+
* keeps rotation on the host, with a single writer. */
|
|
30
|
+
authToken?: string | (() => string | undefined);
|
|
31
|
+
/** OpenAI API base for GPT chat completions, no trailing slash. */
|
|
32
|
+
openAIUpstream?: string;
|
|
33
|
+
/** Override or supply an OpenAI API key. If unset, we forward Authorization. */
|
|
34
|
+
openAIApiKey?: string;
|
|
35
|
+
/** Google API base for Gemini / CloudCode inference, no trailing slash. */
|
|
36
|
+
googleUpstream?: string;
|
|
37
|
+
/** Cloudflare's OpenAI-compatible Chat Completions endpoint and bearer key. */
|
|
38
|
+
cloudflareUpstream?: string;
|
|
39
|
+
cloudflareApiKey?: string;
|
|
40
|
+
/** Exact model ids routed to each non-default provider. Unlisted Claude
|
|
41
|
+
* models retain normal Anthropic routing. */
|
|
42
|
+
openAIModels?: string[];
|
|
43
|
+
cloudflareModels?: string[];
|
|
44
|
+
/** Pass a function to inject dynamic values per-request (e.g. live charsPerToken);
|
|
45
|
+
* static object for Workers/tests. */
|
|
46
|
+
transform?: TransformOptions | (() => TransformOptions);
|
|
47
|
+
/** Called after every request — useful for logging / metrics in the host. */
|
|
48
|
+
onRequest?: (event: ProxyEvent) => void | Promise<void>;
|
|
49
|
+
/** Persist 4xx diagnostics: the gzipped request body plus the upstream error
|
|
50
|
+
* body. Off by default because either side may contain prompts or secrets. */
|
|
51
|
+
captureErrorReqBody?: boolean;
|
|
52
|
+
/** Abort the upstream request if response headers have not arrived within this
|
|
53
|
+
* many ms. Cleared once headers land, so long generations are unaffected.
|
|
54
|
+
* 0 (default) disables so upstream and client control timeouts. */
|
|
55
|
+
upstreamHeadersTimeoutMs?: number;
|
|
56
|
+
/** Abort the upstream response if no bytes arrive for this many ms.
|
|
57
|
+
* 0 (default) disables so buffered tool-call streams pass through as-is. */
|
|
58
|
+
upstreamIdleTimeoutMs?: number;
|
|
59
|
+
/** How long an in-flight request may reject an identical retry before the dedupe
|
|
60
|
+
* fails open. Prevents one stalled request from permanently 409-ing its retries.
|
|
61
|
+
* 0 disables dedupe entirely. */
|
|
62
|
+
duplicateHoldMs?: number;
|
|
63
|
+
/** Hard ceiling, in bytes, on an inbound request body inkling will hold in
|
|
64
|
+
* memory. Transformable routes have to read the whole body, so without a
|
|
65
|
+
* ceiling one client decides how much the proxy allocates: a Worker or a Node
|
|
66
|
+
* instance bound to anything other than loopback is then one long request away
|
|
67
|
+
* from memory exhaustion. Over-limit bodies get a provider-shaped 413 before
|
|
68
|
+
* any upstream call. Routes inkling only labels are never rejected by this -
|
|
69
|
+
* they carry uploads and audio - but their model sniff is bounded too.
|
|
70
|
+
*
|
|
71
|
+
* Defaults to {@link DEFAULT_MAX_REQUEST_BYTES}. A non-integer, zero or
|
|
72
|
+
* negative value is ignored in favour of that default: an unusable limit must
|
|
73
|
+
* not silently become no limit. */
|
|
74
|
+
maxRequestBytes?: number;
|
|
75
|
+
/** How transformable routes handle an inbound body larger than {@link maxRequestBytes}:
|
|
76
|
+
* - `'reject'` (default): return provider-shaped 413 without calling upstream (Workers / non-loopback).
|
|
77
|
+
* - `'passthrough'`: stop buffering at the ceiling and stream buffered chunks + remainder
|
|
78
|
+
* straight to upstream, logging `body_too_large`. Fails closed with 413 on `/v1/messages`
|
|
79
|
+
* when `openAIModels` / `cloudflareModels` bridging is configured. */
|
|
80
|
+
oversizedBodyPolicy?: 'reject' | 'passthrough';
|
|
81
|
+
/** Undo a request `Content-Encoding` on transformable routes so the body can
|
|
82
|
+
* be read. Codex's built-in provider zstd-compresses its Responses POST; left
|
|
83
|
+
* encoded, the transform silently skips it. Return `undefined` when the coding
|
|
84
|
+
* is unknown, the bytes are corrupt, or the output would pass `maxBytes`: the
|
|
85
|
+
* original bytes and header are then forwarded untouched. A decoded body is
|
|
86
|
+
* forwarded as plain bytes without the header, since chatgpt.com has been seen
|
|
87
|
+
* to refuse zstd on image-heavy bodies. Core stays runtime-neutral, so the Node
|
|
88
|
+
* entry supplies this; without it, encoded bodies pass through as before. */
|
|
89
|
+
decodeRequestBody?: (bytes: Uint8Array, encoding: string, maxBytes: number) => Uint8Array<ArrayBuffer> | DecodeRequestBodyResult | undefined;
|
|
90
|
+
/** "Follow the agent": forward a request whose Host is a registered
|
|
91
|
+
* third-party provider (as under `inkling warp`), or whose path is
|
|
92
|
+
* `/to/<host>/...`, to that host over https instead of the configured
|
|
93
|
+
* upstreams. Only the agent's own credential travels; configured keys,
|
|
94
|
+
* gateway headers, bridges and baseline probes never apply. Off by default:
|
|
95
|
+
* a public Worker with this on would relay anyone's traffic. See
|
|
96
|
+
* core/upstream-hosts.ts. */
|
|
97
|
+
followHosts?: boolean;
|
|
98
|
+
/** Registry for `followHosts`; defaults to the built-in provider list. */
|
|
99
|
+
upstreamRegistry?: UpstreamRegistry;
|
|
100
|
+
/** Opted-in built-in providers (`anthropic`, `openai`, `google`, ...). */
|
|
101
|
+
enabledProviders?: readonly ProviderId[] | (() => readonly ProviderId[]);
|
|
102
|
+
/** Custom `fetch` implementation for upstream requests and token probes (defaults to `globalThis.fetch`).
|
|
103
|
+
* Node callers pass a keep-alive HTTP/1.1 transport to avoid Node 26 undici HTTP/2 idle-reaper crashes. */
|
|
104
|
+
fetch?: typeof globalThis.fetch;
|
|
105
|
+
/** Optional Edge Runtime hook (`ctx.waitUntil`) to keep async telemetry alive past response return. */
|
|
106
|
+
waitUntil?: (promise: Promise<unknown>) => void;
|
|
107
|
+
}
|
|
108
|
+
export interface ProxyEvent {
|
|
109
|
+
method: string;
|
|
110
|
+
path: string;
|
|
111
|
+
/** Top-level request model when present. Used for telemetry/dashboard labels only. */
|
|
112
|
+
model?: string;
|
|
113
|
+
/** Provider cost/usage semantics after any internal wire bridge. Unlike
|
|
114
|
+
* `path`, this describes the upstream that actually billed the request. */
|
|
115
|
+
accountingProvider?: 'anthropic' | 'openai' | 'google';
|
|
116
|
+
status: number;
|
|
117
|
+
/** Wall-clock ms from request start to event fire (≈ end of upstream body). */
|
|
118
|
+
durationMs: number;
|
|
119
|
+
/** Wall-clock ms from request start to upstream response headers. */
|
|
120
|
+
firstByteMs?: number;
|
|
121
|
+
/** Wall-clock ms spent in the local transform (render + encode), excluding any
|
|
122
|
+
* upstream probe. `durationMs - transformMs` is the upstream half, so a slow
|
|
123
|
+
* request can be attributed to our own CPU vs the provider without guessing. */
|
|
124
|
+
transformMs?: number;
|
|
125
|
+
info?: TransformInfo;
|
|
126
|
+
/** Usage block from Anthropic's response — input/output/cache tokens. */
|
|
127
|
+
usage?: Usage;
|
|
128
|
+
/** Model stop reason from the response ("end_turn", "tool_use", "max_tokens",
|
|
129
|
+
* "refusal", …). "refusal" = safety classifier fired on the transformed request —
|
|
130
|
+
* scorers must fail cost comparisons on refusal rows (refusals emit almost no
|
|
131
|
+
* output and would otherwise look "cheaper"). OpenAI finish_reason ("stop",
|
|
132
|
+
* "length", "content_filter", …) is normalized into the same field. */
|
|
133
|
+
stopReason?: string;
|
|
134
|
+
error?: string;
|
|
135
|
+
/** First ~2 KiB of the upstream 4xx body (not captured on 2xx or 5xx). */
|
|
136
|
+
errorBody?: string;
|
|
137
|
+
/** sha256[0..8] of the transformed outgoing body — set on every /v1/messages POST for correlation. */
|
|
138
|
+
reqBodySha8?: string;
|
|
139
|
+
/** Gzipped transformed body, populated only on 4xx. Node may write to sidecar (see reqBodySamplePath). */
|
|
140
|
+
reqBodyGz?: Uint8Array;
|
|
141
|
+
/** Set by the Node host instead of reqBodyGz when the body was written to a sidecar file. */
|
|
142
|
+
reqBodySamplePath?: string;
|
|
143
|
+
/** Ground-truth char counts from the response stream, independent of usage.output_tokens.
|
|
144
|
+
* Absent when the body couldn't be scanned (5xx, unknown content-type). See OutputMeasurement. */
|
|
145
|
+
measurement?: OutputMeasurement;
|
|
146
|
+
/** Upstream response media/encoding metadata for scanner diagnostics. */
|
|
147
|
+
responseContentType?: string;
|
|
148
|
+
responseContentEncoding?: string;
|
|
149
|
+
}
|
|
150
|
+
/** Default ceiling on a buffered inbound body: 16 MiB.
|
|
151
|
+
*
|
|
152
|
+
* Chosen against what the transform actually has to hold, not against what a
|
|
153
|
+
* provider accepts. Real Claude Code requests measured on production traffic sit
|
|
154
|
+
* far below this even with a 400k system slab and a long tool-heavy history, so
|
|
155
|
+
* the limit is not reachable by ordinary use. Hosts that genuinely need more can
|
|
156
|
+
* raise it explicitly; nothing raises it implicitly. */
|
|
157
|
+
export declare const DEFAULT_MAX_REQUEST_BYTES: number;
|
|
158
|
+
/**
|
|
159
|
+
* Ground-truth char counts from the response stream, independent of usage.output_tokens.
|
|
160
|
+
* redactedBlockCount blocks are opaque server bytes — no char count available for those.
|
|
161
|
+
*/
|
|
162
|
+
export interface OutputMeasurement {
|
|
163
|
+
textChars: number;
|
|
164
|
+
thinkingChars: number;
|
|
165
|
+
toolUseChars: number;
|
|
166
|
+
redactedBlockCount: number;
|
|
167
|
+
}
|
|
168
|
+
/** What the client presented, by shape only.
|
|
169
|
+
*
|
|
170
|
+
* Classification never inspects a credential's contents beyond its prefix and
|
|
171
|
+
* segment structure, and never reads a local token store: inkling does not know
|
|
172
|
+
* or want to know which account a token belongs to. Shape is enough to decide
|
|
173
|
+
* routing, and it is the only thing safe to decide it on. */
|
|
174
|
+
export type InboundCredential = 'none'
|
|
175
|
+
/** `x-api-key`, which only Anthropic uses. */
|
|
176
|
+
| 'anthropic-key'
|
|
177
|
+
/** `Bearer sk-ant-…`: an Anthropic key or subscription token. */
|
|
178
|
+
| 'anthropic-bearer'
|
|
179
|
+
/** `Bearer <jwt>`: how Codex and ChatGPT subscription auth arrive. */
|
|
180
|
+
| 'oauth-jwt'
|
|
181
|
+
/** `Bearer sk-…` that is not Anthropic: an OpenAI-style API key. */
|
|
182
|
+
| 'api-key-bearer'
|
|
183
|
+
/** A bearer of unrecognised shape. Gateways and self-hosted upstreams use these. */
|
|
184
|
+
| 'opaque-bearer';
|
|
185
|
+
export declare function classifyInboundCredential(headers: Headers): InboundCredential;
|
|
186
|
+
/** The decision for the outgoing `authorization` header. */
|
|
187
|
+
export type OutboundAuth =
|
|
188
|
+
/** Forward what the client sent, unchanged. */
|
|
189
|
+
{
|
|
190
|
+
action: 'keep-inbound';
|
|
191
|
+
reason: string;
|
|
192
|
+
}
|
|
193
|
+
/** Install the host's configured key in its place. */
|
|
194
|
+
| {
|
|
195
|
+
action: 'replace';
|
|
196
|
+
reason: string;
|
|
197
|
+
}
|
|
198
|
+
/** Send no authorization at all. */
|
|
199
|
+
| {
|
|
200
|
+
action: 'drop';
|
|
201
|
+
reason: string;
|
|
202
|
+
};
|
|
203
|
+
/**
|
|
204
|
+
* Credential policy for a direct OpenAI-family route: `/v1/responses`,
|
|
205
|
+
* `/v1/chat/completions`, `/v1/models` and the provider-prefixed equivalents,
|
|
206
|
+
* where the client speaks to the OpenAI upstream itself rather than through a
|
|
207
|
+
* Messages bridge.
|
|
208
|
+
*
|
|
209
|
+
* Three rules, in priority order:
|
|
210
|
+
*
|
|
211
|
+
* 1. An Anthropic-shaped credential never reaches an OpenAI upstream. That is a
|
|
212
|
+
* cross-provider credential disclosure, and a guaranteed 401 on top. The
|
|
213
|
+
* route classifier already refuses this for the ambiguous `/v1/models` path;
|
|
214
|
+
* this applies the same rule to every OpenAI route.
|
|
215
|
+
* 2. Subscription OAuth is preserved even when the host has an API key
|
|
216
|
+
* configured. A Codex user proxying through inkling means to spend their own
|
|
217
|
+
* subscription; silently substituting the host key bills the wrong account
|
|
218
|
+
* and usually fails, and the user has no way to see why.
|
|
219
|
+
* 3. Otherwise a configured key replaces whatever arrived, and is used as the
|
|
220
|
+
* fallback when nothing arrived. This is the documented "host supplies the
|
|
221
|
+
* credential" mode.
|
|
222
|
+
*/
|
|
223
|
+
export declare function resolveOpenAIRouteAuth(inbound: InboundCredential, hasConfiguredKey: boolean): OutboundAuth;
|
|
224
|
+
/** Extract beta names a count_tokens 400 complained about (backtick-quoted). */
|
|
225
|
+
export declare function parseRejectedBetas(errorBody: string): string[];
|
|
226
|
+
/** Test hook. */
|
|
227
|
+
export declare function resetCountTokensRejectedBetasForTests(): void;
|
|
228
|
+
export declare function resetGoogleCountShapePreferenceForTests(): void;
|
|
229
|
+
/**
|
|
230
|
+
* Resolve upstream URLs from config. Pure — unit-testable.
|
|
231
|
+
*
|
|
232
|
+
* Every env-derived input is trimmed of leading/trailing whitespace before
|
|
233
|
+
* URL construction, and trailing slashes are stripped so `base + path` joins
|
|
234
|
+
* cleanly. The trim is defensive: a stray space in OPENAI_UPSTREAM /
|
|
235
|
+
* ANTHROPIC_UPSTREAM / INKLING_GATEWAY_BASE_URL (commonly introduced by
|
|
236
|
+
* cmd.exe `set VAR=...`, a copy-paste with a trailing space, or a shell
|
|
237
|
+
* quoting bug in a launcher script) would otherwise build URLs like
|
|
238
|
+
* "https://api.openai.com /v1/..." — fetch() then throws
|
|
239
|
+
* "Failed to parse URL" with no actionable log line, and the operator is
|
|
240
|
+
* left guessing. Trimming at the URL boundary keeps the failure mode loud
|
|
241
|
+
* (the proxy still returns a real 401/502 from upstream) instead of silent.
|
|
242
|
+
*/
|
|
243
|
+
export declare function resolveUpstreams(config: ProxyConfig): {
|
|
244
|
+
anthropic: string;
|
|
245
|
+
openai: string;
|
|
246
|
+
stripOpenAIV1: boolean;
|
|
247
|
+
};
|
|
248
|
+
/** Parse INKLING_GATEWAY_HEADERS — JSON object or `k=v;k2=v2`. */
|
|
249
|
+
export declare function parseGatewayHeaders(spec: string | undefined): Record<string, string>;
|
|
250
|
+
/** Build the proxy fetch handler. */
|
|
251
|
+
export declare function createProxy(config?: ProxyConfig): (req: Request) => Promise<Response>;
|
|
252
|
+
//# sourceMappingURL=proxy.d.ts.map
|