@revojs/ai 0.2.22 → 0.2.23

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/index.d.ts CHANGED
@@ -761,6 +761,7 @@ export declare function useModelsDev(id: string, resolve: (model: ModelsDevModel
761
761
  textStream: Record<string, Protocol<LanguageModelCallOptions<string>, LanguageModelStreamResult>>;
762
762
  }>;
763
763
  export declare function modelsDevProtocol(model: ModelsDevModel, provider: ModelsDevProvider): ModelsDevProtocol | undefined;
764
+ export declare function toToolInput(value: string | undefined): string;
764
765
  export declare function mergeHeaders(...headers: Array<Record<string, string | undefined> | undefined>): Record<string, string>;
765
766
  export declare function postJson(url: string, body: unknown, options?: {
766
767
  headers?: Record<string, string | undefined>;
package/dist/index.js CHANGED
@@ -371,6 +371,9 @@ function modelsDevProtocol(model, provider) {
371
371
  if (npm === "@ai-sdk/openai") return model.provider?.shape === "completions" ? "chat-completions" : "responses";
372
372
  if (npm === "@ai-sdk/openai-compatible") return "chat-completions";
373
373
  }
374
+ function toToolInput(value) {
375
+ return value === void 0 || value.trim() === "" ? "{}" : value;
376
+ }
374
377
  function mergeHeaders(...headers) {
375
378
  const merged = {};
376
379
  for (const record of headers) for (const [name, value] of Object.entries(record ?? {})) if (value !== void 0) merged[name] = value;
@@ -421,4 +424,4 @@ function toStream(read) {
421
424
  }
422
425
  var modelsDevCache = { loadedAt: 0 };
423
426
  //#endregion
424
- export { ModelContextProtocolConnection, defineProvider, defineTool, handleModelContextProtocol, mergeHeaders, modelsDevProtocol, postJson, readDataFrames, toStream, useAi, useModelContextProtocol, useModelsDev, useTools };
427
+ export { ModelContextProtocolConnection, defineProvider, defineTool, handleModelContextProtocol, mergeHeaders, modelsDevProtocol, postJson, readDataFrames, toStream, toToolInput, useAi, useModelContextProtocol, useModelsDev, useTools };
@@ -1,4 +1,4 @@
1
- import { mergeHeaders, postJson, readDataFrames, toStream } from "../index.js";
1
+ import { mergeHeaders, postJson, readDataFrames, toStream, toToolInput } from "../index.js";
2
2
  import { toJsonSchema } from "revojs/shared";
3
3
  //#region src/protocols/anthropic-messages.ts
4
4
  function toUsage(inputTokens, cacheRead, cacheWrite, outputTokens) {
@@ -299,7 +299,7 @@ async function* readParts(response, warnings) {
299
299
  type: "tool-call",
300
300
  toolCallId: record.callId,
301
301
  toolName: record.name,
302
- input: record.json
302
+ input: toToolInput(record.json)
303
303
  };
304
304
  yield {
305
305
  type: "finish",
@@ -1,4 +1,4 @@
1
- import { mergeHeaders, postJson, readDataFrames, toStream } from "../index.js";
1
+ import { mergeHeaders, postJson, readDataFrames, toStream, toToolInput } from "../index.js";
2
2
  import { toJsonSchema } from "revojs/shared";
3
3
  //#region src/protocols/openai-chat-completions.ts
4
4
  function toMessages(prompt) {
@@ -256,7 +256,7 @@ async function* readParts(response, warnings) {
256
256
  type: "tool-call",
257
257
  toolCallId: accumulator.callId.length > 0 ? accumulator.callId : accumulator.streamId,
258
258
  toolName: accumulator.name,
259
- input: accumulator.arguments
259
+ input: toToolInput(accumulator.arguments)
260
260
  };
261
261
  }
262
262
  yield {
@@ -289,7 +289,7 @@ function chatCompletionsGenerateProtocol(config) {
289
289
  type: "tool-call",
290
290
  toolCallId: call.id ?? "",
291
291
  toolName: call.function?.name ?? "",
292
- input: call.function?.arguments ?? ""
292
+ input: toToolInput(call.function?.arguments)
293
293
  });
294
294
  return {
295
295
  content,
@@ -1,4 +1,4 @@
1
- import { mergeHeaders, postJson, readDataFrames, toStream } from "../index.js";
1
+ import { mergeHeaders, postJson, readDataFrames, toStream, toToolInput } from "../index.js";
2
2
  import { toJsonSchema } from "revojs/shared";
3
3
  //#region src/protocols/openai-responses.ts
4
4
  function toUsage(usage) {
@@ -276,7 +276,7 @@ async function* readParts(response, warnings) {
276
276
  type: "tool-call",
277
277
  toolCallId: event.item.call_id ?? streamId,
278
278
  toolName: event.item.name ?? record?.name ?? "",
279
- input: event.item.arguments ?? record?.arguments ?? ""
279
+ input: toToolInput(event.item.arguments ?? record?.arguments)
280
280
  };
281
281
  continue;
282
282
  }
@@ -318,7 +318,7 @@ async function* readParts(response, warnings) {
318
318
  type: "tool-call",
319
319
  toolCallId: record.callId || id,
320
320
  toolName: record.name,
321
- input: record.arguments
321
+ input: toToolInput(record.arguments)
322
322
  };
323
323
  }
324
324
  yield {
@@ -359,7 +359,7 @@ function responsesGenerateProtocol(config) {
359
359
  type: "tool-call",
360
360
  toolCallId: item.call_id ?? "",
361
361
  toolName: item.name ?? "",
362
- input: item.arguments ?? ""
362
+ input: toToolInput(item.arguments)
363
363
  });
364
364
  continue;
365
365
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revojs/ai",
3
- "version": "0.2.22",
3
+ "version": "0.2.23",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",