@dbx-tools/shared-model 0.3.24 → 0.3.26
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 +2 -2
- package/src/openai-responses.ts +36 -0
package/package.json
CHANGED
|
@@ -12,14 +12,14 @@
|
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
14
|
"zod": "^4.3.6",
|
|
15
|
-
"@dbx-tools/shared-core": "0.3.
|
|
15
|
+
"@dbx-tools/shared-core": "0.3.26"
|
|
16
16
|
},
|
|
17
17
|
"main": "index.ts",
|
|
18
18
|
"license": "UNLICENSED",
|
|
19
19
|
"publishConfig": {
|
|
20
20
|
"access": "public"
|
|
21
21
|
},
|
|
22
|
-
"version": "0.3.
|
|
22
|
+
"version": "0.3.26",
|
|
23
23
|
"types": "index.ts",
|
|
24
24
|
"type": "module",
|
|
25
25
|
"exports": {
|
package/src/openai-responses.ts
CHANGED
|
@@ -26,6 +26,9 @@
|
|
|
26
26
|
* - {@link readResponsesOutput} reads the other direction: pull the answer
|
|
27
27
|
* text and citations out of a `response` object returned by an endpoint
|
|
28
28
|
* that speaks Responses natively (the Databricks native web-search tool).
|
|
29
|
+
* - {@link sanitizeResponsesTools} keeps only `function` tools on a Responses
|
|
30
|
+
* request body (for `/open-responses` / Anthropic, which reject Codex
|
|
31
|
+
* built-ins like `web_search`).
|
|
29
32
|
*
|
|
30
33
|
* Only the surface real clients exercise is translated; unknown fields are
|
|
31
34
|
* ignored rather than rejected, so a newer client degrades instead of breaking.
|
|
@@ -607,3 +610,36 @@ export function readResponsesOutput(payload: Record<string, unknown>): Responses
|
|
|
607
610
|
function str(value: unknown): string {
|
|
608
611
|
return typeof value === "string" ? value.trim() : "";
|
|
609
612
|
}
|
|
613
|
+
|
|
614
|
+
/**
|
|
615
|
+
* Strip tool types the upstream model doesn't support from a Responses request
|
|
616
|
+
* body, returning a shallow copy safe to forward (the input is not mutated).
|
|
617
|
+
*
|
|
618
|
+
* Clients like the Codex CLI include built-in Responses tools (`web_search`,
|
|
619
|
+
* `local_shell`, `custom`, ...) alongside their `function` tools. Databricks'
|
|
620
|
+
* Open Responses surface for Anthropic/Claude (and other non-OpenAI providers)
|
|
621
|
+
* only accepts `function` tools and hard-errors otherwise:
|
|
622
|
+
* "Anthropic does not support tool type 'web_search'. Only 'function' is supported."
|
|
623
|
+
* Call this before forwarding to `/serving-endpoints/open-responses`. The OpenAI
|
|
624
|
+
* `/serving-endpoints/responses` path should keep built-ins (GPT supports them).
|
|
625
|
+
* If filtering empties the list, `tools` / `tool_choice` / `parallel_tool_calls`
|
|
626
|
+
* are dropped so we never send an empty `tools: []`.
|
|
627
|
+
*/
|
|
628
|
+
export function sanitizeResponsesTools(
|
|
629
|
+
body: Record<string, unknown>,
|
|
630
|
+
): Record<string, unknown> {
|
|
631
|
+
if (!Array.isArray(body.tools) || body.tools.length === 0) return body;
|
|
632
|
+
const fnTools = body.tools.filter(
|
|
633
|
+
(t) => t && typeof t === "object" && (t as Record<string, unknown>).type === "function",
|
|
634
|
+
);
|
|
635
|
+
if (fnTools.length === body.tools.length) return body; // nothing to strip
|
|
636
|
+
const next: Record<string, unknown> = { ...body };
|
|
637
|
+
if (fnTools.length > 0) {
|
|
638
|
+
next.tools = fnTools;
|
|
639
|
+
} else {
|
|
640
|
+
delete next.tools;
|
|
641
|
+
delete next.tool_choice;
|
|
642
|
+
delete next.parallel_tool_calls;
|
|
643
|
+
}
|
|
644
|
+
return next;
|
|
645
|
+
}
|