ai 3.1.15 → 3.1.17

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.
@@ -500,6 +500,33 @@ function convertZodToJSONSchema(zodSchema) {
500
500
  return zodToJsonSchema(zodSchema);
501
501
  }
502
502
 
503
+ // core/util/is-non-empty-object.ts
504
+ function isNonEmptyObject(object) {
505
+ return object != null && Object.keys(object).length > 0;
506
+ }
507
+
508
+ // core/prompt/prepare-tools-and-tool-choice.ts
509
+ function prepareToolsAndToolChoice({
510
+ tools,
511
+ toolChoice
512
+ }) {
513
+ if (!isNonEmptyObject(tools)) {
514
+ return {
515
+ tools: void 0,
516
+ toolChoice: void 0
517
+ };
518
+ }
519
+ return {
520
+ tools: Object.entries(tools).map(([name, tool]) => ({
521
+ type: "function",
522
+ name,
523
+ description: tool.description,
524
+ parameters: convertZodToJSONSchema(tool.parameters)
525
+ })),
526
+ toolChoice: toolChoice == null ? { type: "auto" } : typeof toolChoice === "string" ? { type: toolChoice } : { type: "tool", toolName: toolChoice.toolName }
527
+ };
528
+ }
529
+
503
530
  // shared/stream-parts.ts
504
531
  var textStreamPart = {
505
532
  code: "0",
@@ -1641,6 +1668,7 @@ var defaultTextRenderer = ({ content }) => content;
1641
1668
  async function streamUI({
1642
1669
  model,
1643
1670
  tools,
1671
+ toolChoice,
1644
1672
  system,
1645
1673
  prompt,
1646
1674
  messages,
@@ -1720,12 +1748,7 @@ async function streamUI({
1720
1748
  () => model.doStream({
1721
1749
  mode: {
1722
1750
  type: "regular",
1723
- tools: tools == null ? void 0 : Object.entries(tools).map(([name, tool]) => ({
1724
- type: "function",
1725
- name,
1726
- description: tool.description,
1727
- parameters: convertZodToJSONSchema(tool.parameters)
1728
- }))
1751
+ ...prepareToolsAndToolChoice({ tools, toolChoice })
1729
1752
  },
1730
1753
  ...prepareCallSettings(settings),
1731
1754
  inputFormat: validatedPrompt.type,