@dbx-tools/cli-model-proxy 0.3.44 → 0.4.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.
@@ -0,0 +1,79 @@
1
+ /**
2
+ * OpenAI-compatible HTTP proxy in front of Databricks Model Serving.
3
+ *
4
+ * Databricks serving endpoints speak OpenAI wire formats, so this server is a
5
+ * thin pass-through: it resolves the request's (possibly fuzzy) `model` to a
6
+ * real endpoint id via the {@link DatabricksBackend}, stamps a fresh auth
7
+ * header, and forwards to the right Databricks URL:
8
+ *
9
+ * - Chat Completions → `/serving-endpoints/<name>/invocations`, except for
10
+ * Responses-only models (Codex) which are translated and sent to
11
+ * `/serving-endpoints/responses`.
12
+ * - Responses → native `/serving-endpoints/responses` (OpenAI-family) or
13
+ * `/serving-endpoints/open-responses` (Claude/Gemini/…), body forwarded
14
+ * as-is. No chat round-trip.
15
+ *
16
+ * Any OpenAI-compatible tool (iTerm, editors, the `openai` SDK, Codex CLI) can
17
+ * point its base URL at this server and use loose model names.
18
+ *
19
+ * Routes:
20
+ * - `GET /health`, `GET /` liveness
21
+ * - `GET /v1/models`, `GET /models` list resolvable endpoints. Emits the
22
+ * OpenAI `{object:"list",data:[…]}` shape by default; when the request
23
+ * looks like the Codex CLI (a `client_version` query param, which Codex
24
+ * always sends) it emits Codex's `{models:[{slug,…}]}` shape instead, so
25
+ * both standard OpenAI clients and Codex can enumerate the catalogue.
26
+ * - `POST /v1/chat/completions` proxy (also `/completions`,
27
+ * `/v1/completions`, `/v1/embeddings`, and the un-prefixed variants)
28
+ * - `POST /v1/responses` OpenAI Responses API, forwarded to
29
+ * Databricks' native Responses / Open Responses surface.
30
+ *
31
+ * @module
32
+ */
33
+ import { type Server } from "node:http";
34
+ import type { DatabricksBackend } from "./backend.js";
35
+ import { type RetryConfig } from "./defaults.js";
36
+ /** Options shared by {@link createProxyServer} and {@link startProxyServer}. */
37
+ export interface ProxyServerOptions {
38
+ /**
39
+ * When set, local clients must present this value as a bearer token
40
+ * (`Authorization: Bearer <key>`). Unset leaves the proxy open, which is fine
41
+ * for a loopback bind but should be paired with a key on a wider one.
42
+ */
43
+ apiKey?: string;
44
+ /**
45
+ * Policy for absorbing upstream 429s. Omitted defaults to {@link
46
+ * DEFAULT_RETRY} (retry on). See {@link RetryConfig}.
47
+ */
48
+ retry?: RetryConfig;
49
+ }
50
+ /** Options for {@link startProxyServer}, adding the listen address. */
51
+ export interface StartProxyOptions extends ProxyServerOptions {
52
+ host?: string;
53
+ port?: number;
54
+ }
55
+ /** Build (but do not start) the proxy HTTP server. */
56
+ export declare function createProxyServer(backend: DatabricksBackend, options?: ProxyServerOptions): Server;
57
+ /**
58
+ * Delay (ms) a `429` response asks us to wait, from its `Retry-After` header,
59
+ * or `undefined` when absent/unparseable. Handles both header forms: an integer
60
+ * count of seconds, and an HTTP date to wait until (clamped to `>= 0`).
61
+ */
62
+ export declare function parseRetryAfterMs(header: string | null, nowMs: number): number | undefined;
63
+ /**
64
+ * Backoff (ms) before retry `attempt` (0-based): exponential from
65
+ * `baseDelayMs`, capped at `maxDelayMs`, with up to +50% jitter so concurrent
66
+ * retries from one agent don't resynchronize into the next burst. A server-sent
67
+ * `Retry-After` wins outright (still capped), since the server knows better
68
+ * than our schedule when it will accept traffic again.
69
+ */
70
+ export declare function backoffDelayMs(attempt: number, retry: RetryConfig, retryAfterMs: number | undefined, jitter: number): number;
71
+ /**
72
+ * Build and start the proxy, resolving once it is accepting connections.
73
+ * Returns the server and its base URL (with the actually-bound port, so a
74
+ * `port: 0` request surfaces the OS-assigned port).
75
+ */
76
+ export declare function startProxyServer(backend: DatabricksBackend, options?: StartProxyOptions): Promise<{
77
+ server: Server;
78
+ url: string;
79
+ }>;