@zenmux/rosetta-ai 1.0.13 → 1.0.14
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.
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ResponsesToChatCompletionConverter = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
4
5
|
class ResponsesToChatCompletionConverter {
|
|
5
6
|
streamState;
|
|
6
7
|
/**
|
|
@@ -253,7 +254,7 @@ class ResponsesToChatCompletionConverter {
|
|
|
253
254
|
truncation: "disabled",
|
|
254
255
|
};
|
|
255
256
|
}
|
|
256
|
-
const tools = (params.tools ?? [])
|
|
257
|
+
const tools = ((0, utils_1.expandNamespaceTools)(params.tools) ?? [])
|
|
257
258
|
.map(t => this.toRespTool(t))
|
|
258
259
|
.filter(Boolean);
|
|
259
260
|
return {
|
|
@@ -949,6 +950,7 @@ class ResponsesToChatCompletionConverter {
|
|
|
949
950
|
return parts.length ? parts : "";
|
|
950
951
|
}
|
|
951
952
|
convertTools(tools) {
|
|
953
|
+
tools = (0, utils_1.expandNamespaceTools)(tools);
|
|
952
954
|
if (!tools)
|
|
953
955
|
return { tools: [] };
|
|
954
956
|
const ccTools = [];
|
package/dist/responses/gemini.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ResponsesToGeminiConverter = void 0;
|
|
4
|
+
const utils_1 = require("./utils");
|
|
4
5
|
class ResponsesToGeminiConverter {
|
|
5
6
|
streamState;
|
|
6
7
|
constructor() {
|
|
@@ -492,6 +493,7 @@ class ResponsesToGeminiConverter {
|
|
|
492
493
|
return parts.length > 0 ? parts : [{ text: "" }];
|
|
493
494
|
}
|
|
494
495
|
convertTools(tools) {
|
|
496
|
+
tools = (0, utils_1.expandNamespaceTools)(tools);
|
|
495
497
|
if (!tools)
|
|
496
498
|
return { tools: [], hasGoogleSearch: false };
|
|
497
499
|
const functionTools = [];
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ResponsesToMessagesConverter = void 0;
|
|
4
4
|
const sdk_1 = require("@anthropic-ai/sdk");
|
|
5
|
+
const utils_1 = require("./utils");
|
|
5
6
|
const DEFAULT_MAX_TOKENS = 4096;
|
|
6
7
|
class ResponsesToMessagesConverter {
|
|
7
8
|
streamState;
|
|
@@ -892,6 +893,7 @@ class ResponsesToMessagesConverter {
|
|
|
892
893
|
};
|
|
893
894
|
}
|
|
894
895
|
convertTools(tools) {
|
|
896
|
+
tools = (0, utils_1.expandNamespaceTools)(tools);
|
|
895
897
|
if (!tools)
|
|
896
898
|
return [];
|
|
897
899
|
const result = [];
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type OpenAI from "openai";
|
|
2
|
+
/**
|
|
3
|
+
* Expand Responses "namespace" tools into individual "function" tools.
|
|
4
|
+
*
|
|
5
|
+
* A namespace tool groups related function tools under a shared name:
|
|
6
|
+
*
|
|
7
|
+
* {
|
|
8
|
+
* type: "namespace",
|
|
9
|
+
* name: "agents",
|
|
10
|
+
* description: "Multi-agent collaboration tools.",
|
|
11
|
+
* tools: [{ type: "function", name: "spawn_agent", parameters: {...} }]
|
|
12
|
+
* }
|
|
13
|
+
*
|
|
14
|
+
* Downstream provider protocols (chat-completions / messages / gemini) do not
|
|
15
|
+
* understand the `namespace` tool type, so each inner tool is flattened into a
|
|
16
|
+
* top-level function tool whose name is namespaced as `<namespace>.<tool>`
|
|
17
|
+
* (e.g. `agents.spawn_agent`) — matching how the model is prompted to call it.
|
|
18
|
+
*
|
|
19
|
+
* Non-namespace tools pass through untouched and the original order is
|
|
20
|
+
* preserved (a namespace expands in place). When no namespace tool is present
|
|
21
|
+
* the original array is returned by reference, so this is a no-op for the
|
|
22
|
+
* common case.
|
|
23
|
+
*/
|
|
24
|
+
export declare function expandNamespaceTools(tools: OpenAI.Responses.ResponseCreateParams["tools"]): OpenAI.Responses.ResponseCreateParams["tools"];
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expandNamespaceTools = expandNamespaceTools;
|
|
4
|
+
/**
|
|
5
|
+
* Expand Responses "namespace" tools into individual "function" tools.
|
|
6
|
+
*
|
|
7
|
+
* A namespace tool groups related function tools under a shared name:
|
|
8
|
+
*
|
|
9
|
+
* {
|
|
10
|
+
* type: "namespace",
|
|
11
|
+
* name: "agents",
|
|
12
|
+
* description: "Multi-agent collaboration tools.",
|
|
13
|
+
* tools: [{ type: "function", name: "spawn_agent", parameters: {...} }]
|
|
14
|
+
* }
|
|
15
|
+
*
|
|
16
|
+
* Downstream provider protocols (chat-completions / messages / gemini) do not
|
|
17
|
+
* understand the `namespace` tool type, so each inner tool is flattened into a
|
|
18
|
+
* top-level function tool whose name is namespaced as `<namespace>.<tool>`
|
|
19
|
+
* (e.g. `agents.spawn_agent`) — matching how the model is prompted to call it.
|
|
20
|
+
*
|
|
21
|
+
* Non-namespace tools pass through untouched and the original order is
|
|
22
|
+
* preserved (a namespace expands in place). When no namespace tool is present
|
|
23
|
+
* the original array is returned by reference, so this is a no-op for the
|
|
24
|
+
* common case.
|
|
25
|
+
*/
|
|
26
|
+
function expandNamespaceTools(tools) {
|
|
27
|
+
if (!Array.isArray(tools))
|
|
28
|
+
return tools;
|
|
29
|
+
let hasNamespace = false;
|
|
30
|
+
const expanded = [];
|
|
31
|
+
for (const tool of tools) {
|
|
32
|
+
if (tool && typeof tool === "object" && tool.type === "namespace") {
|
|
33
|
+
hasNamespace = true;
|
|
34
|
+
const ns = tool;
|
|
35
|
+
const nsName = typeof ns.name === "string" ? ns.name : undefined;
|
|
36
|
+
const innerTools = Array.isArray(ns.tools) ? ns.tools : [];
|
|
37
|
+
for (const inner of innerTools) {
|
|
38
|
+
if (!inner || typeof inner !== "object")
|
|
39
|
+
continue;
|
|
40
|
+
const innerName = inner.name;
|
|
41
|
+
if (typeof innerName !== "string" || innerName === "")
|
|
42
|
+
continue;
|
|
43
|
+
expanded.push({
|
|
44
|
+
...inner,
|
|
45
|
+
type: "function",
|
|
46
|
+
name: nsName ? `${nsName}.${innerName}` : innerName,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
continue;
|
|
50
|
+
}
|
|
51
|
+
expanded.push(tool);
|
|
52
|
+
}
|
|
53
|
+
return (hasNamespace ? expanded : tools);
|
|
54
|
+
}
|