@dbx-tools/model 0.3.23 → 0.3.25
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/package.json +4 -4
- package/src/invoke.ts +60 -7
package/package.json
CHANGED
|
@@ -13,16 +13,16 @@
|
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"@databricks/appkit": "^0.43.0",
|
|
15
15
|
"fuse.js": "^7.4.2",
|
|
16
|
-
"@dbx-tools/
|
|
17
|
-
"@dbx-tools/shared-model": "0.3.
|
|
18
|
-
"@dbx-tools/
|
|
16
|
+
"@dbx-tools/appkit": "0.3.25",
|
|
17
|
+
"@dbx-tools/shared-model": "0.3.25",
|
|
18
|
+
"@dbx-tools/shared-core": "0.3.25"
|
|
19
19
|
},
|
|
20
20
|
"main": "index.ts",
|
|
21
21
|
"license": "UNLICENSED",
|
|
22
22
|
"publishConfig": {
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
|
-
"version": "0.3.
|
|
25
|
+
"version": "0.3.25",
|
|
26
26
|
"types": "index.ts",
|
|
27
27
|
"type": "module",
|
|
28
28
|
"exports": {
|
package/src/invoke.ts
CHANGED
|
@@ -3,10 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* The SDK's `servingEndpoints.query` covers the typed request shapes, but an
|
|
5
5
|
* OpenAI-compatible caller (a proxy, a passthrough route, a streaming client)
|
|
6
|
-
* needs to issue its own `fetch` against
|
|
6
|
+
* needs to issue its own `fetch` against Databricks' OpenAI-shaped URLs with
|
|
7
7
|
* an OpenAI body. That needs exactly two things the SDK doesn't hand out
|
|
8
|
-
* directly: the URL ({@link invocationsUrl}
|
|
9
|
-
*
|
|
8
|
+
* directly: the URL ({@link invocationsUrl} / {@link responsesUrl} /
|
|
9
|
+
* {@link openResponsesUrl}) and a currently-valid set of auth headers
|
|
10
|
+
* ({@link authHeaders}).
|
|
10
11
|
*
|
|
11
12
|
* Auth is delegated entirely to the Databricks SDK: `config.authenticate`
|
|
12
13
|
* re-runs the configured credential provider on every call and refreshes the
|
|
@@ -18,14 +19,27 @@
|
|
|
18
19
|
*/
|
|
19
20
|
|
|
20
21
|
/**
|
|
21
|
-
* Path segment appended to a serving endpoint for OpenAI-compatible
|
|
22
|
-
* Databricks routes `/serving-endpoints/<name>/invocations` to the
|
|
23
|
-
*
|
|
22
|
+
* Path segment appended to a serving endpoint for OpenAI-compatible chat
|
|
23
|
+
* requests. Databricks routes `/serving-endpoints/<name>/invocations` to the
|
|
24
|
+
* endpoint's Chat Completions surface (`messages` in, `choices` out). Some
|
|
25
|
+
* models (notably Codex) reject this path and require {@link responsesUrl}.
|
|
24
26
|
*/
|
|
25
27
|
export const INVOCATIONS_SUFFIX = "invocations";
|
|
26
28
|
|
|
27
29
|
/**
|
|
28
|
-
*
|
|
30
|
+
* Workspace-level OpenAI Responses API path. Body carries `model` (endpoint
|
|
31
|
+
* id); used by GPT / Codex models that speak Responses natively.
|
|
32
|
+
*/
|
|
33
|
+
export const RESPONSES_PATH = "serving-endpoints/responses";
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Workspace-level Open Responses API path - the cross-provider Responses
|
|
37
|
+
* surface (Claude, Gemini, …) that OpenAI `/responses` does not cover.
|
|
38
|
+
*/
|
|
39
|
+
export const OPEN_RESPONSES_PATH = "serving-endpoints/open-responses";
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The OpenAI-compatible chat-completions invocations URL for an endpoint id.
|
|
29
43
|
*
|
|
30
44
|
* @param host - Workspace host, e.g. `https://my-workspace.cloud.databricks.com/`.
|
|
31
45
|
* Pass the value resolved from `client.config.getHost()`.
|
|
@@ -38,6 +52,45 @@ export function invocationsUrl(host: string, endpoint: string): string {
|
|
|
38
52
|
).toString();
|
|
39
53
|
}
|
|
40
54
|
|
|
55
|
+
/** Workspace OpenAI Responses API URL (`POST`, model in the body). */
|
|
56
|
+
export function responsesUrl(host: string): string {
|
|
57
|
+
return new URL(RESPONSES_PATH, host).toString();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Workspace Open Responses API URL (`POST`, model in the body). */
|
|
61
|
+
export function openResponsesUrl(host: string): string {
|
|
62
|
+
return new URL(OPEN_RESPONSES_PATH, host).toString();
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* True when the endpoint is known to reject Chat Completions `/invocations`
|
|
67
|
+
* and require the Responses API (Codex models today). Callers should route
|
|
68
|
+
* those to {@link responsesUrl} instead of {@link invocationsUrl}.
|
|
69
|
+
*/
|
|
70
|
+
export function isResponsesOnly(endpoint: string): boolean {
|
|
71
|
+
return /codex/i.test(endpoint);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Pick the Databricks Responses upstream for an endpoint id: OpenAI-family
|
|
76
|
+
* models use `/serving-endpoints/responses`; everything else uses the
|
|
77
|
+
* cross-provider `/serving-endpoints/open-responses`.
|
|
78
|
+
*/
|
|
79
|
+
export function responsesUpstreamUrl(host: string, endpoint: string): string {
|
|
80
|
+
return isOpenAiFamily(endpoint) ? responsesUrl(host) : openResponsesUrl(host);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** GPT / Codex / o-series style endpoint names that speak OpenAI Responses. */
|
|
84
|
+
function isOpenAiFamily(endpoint: string): boolean {
|
|
85
|
+
const n = endpoint.toLowerCase();
|
|
86
|
+
return (
|
|
87
|
+
n.includes("gpt") ||
|
|
88
|
+
n.includes("codex") ||
|
|
89
|
+
/(^|[^a-z])o[1-9]([^a-z]|$)/.test(n) ||
|
|
90
|
+
n.includes("openai")
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
41
94
|
/**
|
|
42
95
|
* Minimal structural shape {@link authHeaders} needs. Declared narrowly rather
|
|
43
96
|
* than as a full `WorkspaceClientLike` so a caller holding its own
|