@zenmux/rosetta-ai 1.0.12 → 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
  /**
@@ -135,8 +136,10 @@ class ResponsesToChatCompletionConverter {
135
136
  }
136
137
  }
137
138
  }
138
- // Message
139
- if (msg?.content != null || msg?.refusal != null) {
139
+ // Message — legacy emitted the message item only when content was truthy
140
+ // (empty-string content with e.g. max_output_tokens exhausted was skipped).
141
+ // Refusal is also surfaced as a message when present.
142
+ if (msg?.content || msg?.refusal) {
140
143
  const content = [];
141
144
  if (msg.refusal) {
142
145
  content.push({ type: "refusal", refusal: msg.refusal });
@@ -251,7 +254,7 @@ class ResponsesToChatCompletionConverter {
251
254
  truncation: "disabled",
252
255
  };
253
256
  }
254
- const tools = (params.tools ?? [])
257
+ const tools = ((0, utils_1.expandNamespaceTools)(params.tools) ?? [])
255
258
  .map(t => this.toRespTool(t))
256
259
  .filter(Boolean);
257
260
  return {
@@ -290,7 +293,7 @@ class ResponsesToChatCompletionConverter {
290
293
  properties: t.parameters.properties ?? {},
291
294
  required: t.parameters.required ?? [],
292
295
  },
293
- strict: t.strict,
296
+ strict: t.strict ?? true,
294
297
  };
295
298
  }
296
299
  if (t.type === "web_search" ||
@@ -947,6 +950,7 @@ class ResponsesToChatCompletionConverter {
947
950
  return parts.length ? parts : "";
948
951
  }
949
952
  convertTools(tools) {
953
+ tools = (0, utils_1.expandNamespaceTools)(tools);
950
954
  if (!tools)
951
955
  return { tools: [] };
952
956
  const ccTools = [];
@@ -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
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zenmux/rosetta-ai",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "Universal translator between AI provider protocols",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",