@bman654/clodex 2.8.2 → 2.8.3

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/dist/cli.js CHANGED
@@ -382,7 +382,7 @@ import { join } from "path";
382
382
  // package.json
383
383
  var package_default = {
384
384
  name: "@bman654/clodex",
385
- version: "2.8.2",
385
+ version: "2.8.3",
386
386
  publishConfig: {
387
387
  access: "public"
388
388
  },
@@ -7775,6 +7775,7 @@ function sanitizeMessage(message) {
7775
7775
 
7776
7776
  // src/tool-input-sanitize.ts
7777
7777
  function sanitizeToolInput(input, requiredProps) {
7778
+ if (!input || typeof input !== "object" || Array.isArray(input)) return input;
7778
7779
  const out = /* @__PURE__ */ Object.create(null);
7779
7780
  for (const [k, v] of Object.entries(input)) {
7780
7781
  if (v === null) continue;
@@ -10959,6 +10960,22 @@ function translateMessages(messages, npm, openAiPromptCacheBreakpoints = false)
10959
10960
  }
10960
10961
  return out;
10961
10962
  }
10963
+ function isPlainObject(value) {
10964
+ return value !== null && typeof value === "object" && !Array.isArray(value);
10965
+ }
10966
+ function parsesAsJson(text5) {
10967
+ if (text5.trim() === "") return true;
10968
+ try {
10969
+ JSON.parse(text5);
10970
+ return true;
10971
+ } catch {
10972
+ return false;
10973
+ }
10974
+ }
10975
+ function representableToolInput(input) {
10976
+ if (typeof input === "string") return input;
10977
+ return isPlainObject(input) || Array.isArray(input) ? input : {};
10978
+ }
10962
10979
  function toolRequiredProps(tools) {
10963
10980
  const map = /* @__PURE__ */ new Map();
10964
10981
  for (const [name, t] of Object.entries(tools ?? {})) {
@@ -10968,12 +10985,16 @@ function toolRequiredProps(tools) {
10968
10985
  }
10969
10986
  return map;
10970
10987
  }
10971
- function translateTools(anthropicTools) {
10988
+ function translateTools(anthropicTools, npm) {
10972
10989
  if (!anthropicTools?.length) return void 0;
10973
10990
  const tools = {};
10974
10991
  for (const t of anthropicTools) {
10975
10992
  if (!t.name || !t.input_schema) continue;
10976
- tools[t.name] = tool({ description: t.description ?? "", inputSchema: jsonSchema(t.input_schema) });
10993
+ tools[t.name] = tool({
10994
+ description: t.description ?? "",
10995
+ inputSchema: jsonSchema(t.input_schema),
10996
+ strict: npm === "@ai-sdk/openai" ? false : void 0
10997
+ });
10977
10998
  }
10978
10999
  return Object.keys(tools).length ? tools : void 0;
10979
11000
  }
@@ -11037,7 +11058,7 @@ function translateRequest(body, npm, options) {
11037
11058
  ...translateMessages(messages, npm, supportsExplicitOpenAiCaching)
11038
11059
  ],
11039
11060
  allowSystemInMessages: true,
11040
- tools: translateTools(upstreamTools.length ? upstreamTools : void 0),
11061
+ tools: translateTools(upstreamTools.length ? upstreamTools : void 0, npm),
11041
11062
  toolChoice: compactRequest ? "none" : translateToolChoice(body.tool_choice),
11042
11063
  maxOutputTokens: options?.openAiOAuth ? void 0 : body.max_tokens,
11043
11064
  temperature: body.temperature,
@@ -11254,7 +11275,8 @@ async function writeAnthropicStream(stream, modelId, write, log12, observer, too
11254
11275
  const id = part.toolCallId ?? "";
11255
11276
  if (idToBlock.has(id)) {
11256
11277
  if (!flushedTools.has(id)) {
11257
- const json = part.input !== void 0 && part.input !== null ? JSON.stringify(sanitizeToolInput(part.input, requiredProps.get(part.toolName ?? ""))) : toolJsonBuffer.get(id) ?? "";
11278
+ const buffered = toolJsonBuffer.get(id);
11279
+ const json = buffered !== void 0 && !isPlainObject(part.input) && !parsesAsJson(buffered) ? buffered : part.input !== void 0 && part.input !== null ? JSON.stringify(sanitizeToolInput(part.input, requiredProps.get(part.toolName ?? ""))) : buffered ?? "";
11258
11280
  if (json) {
11259
11281
  emit("content_block_delta", {
11260
11282
  type: "content_block_delta",
@@ -11459,7 +11481,7 @@ async function generateAnthropicResponse(model, params, modelId, options) {
11459
11481
  type: "tool_use",
11460
11482
  id: encodeToolUseId(tc.toolCallId, grabRoundTripSignature(tc)),
11461
11483
  name: tc.toolName,
11462
- input: sanitizeToolInput(tc.input ?? {}, requiredProps.get(tc.toolName))
11484
+ input: representableToolInput(sanitizeToolInput(tc.input ?? {}, requiredProps.get(tc.toolName)))
11463
11485
  }))
11464
11486
  ],
11465
11487
  stop_reason: finishReason === "tool-calls" ? "tool_use" : "end_turn",