@ai-sdk-tool/parser 4.1.1 → 4.1.2

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/community.js CHANGED
@@ -3,7 +3,7 @@ import {
3
3
  morphFormatToolResponseAsXml,
4
4
  morphXmlProtocol,
5
5
  uiTarsXmlProtocol
6
- } from "./chunk-722D5BGD.js";
6
+ } from "./chunk-X3NZ2YHV.js";
7
7
  import "./chunk-D4YULTAO.js";
8
8
  import "./chunk-QBZNMO5C.js";
9
9
  import "./chunk-GMTE7BY5.js";
package/dist/index.cjs CHANGED
@@ -9748,6 +9748,7 @@ For each function call return a json object with function name and arguments wit
9748
9748
  var import_dedent = __toESM(require("dedent"), 1);
9749
9749
  function morphXmlSystemPromptTemplate(tools) {
9750
9750
  const toolsText = renderToolsForXmlPrompt(tools);
9751
+ const inputExamplesText = renderInputExamplesForXmlPrompt(tools);
9751
9752
  const header = import_dedent.default`
9752
9753
  # Tools
9753
9754
  You may call one or more functions to assist with the user query.
@@ -9762,7 +9763,7 @@ function morphXmlSystemPromptTemplate(tools) {
9762
9763
  <rules>
9763
9764
  - Use exactly one XML element whose tag name is the function name.
9764
9765
  - Put each parameter as a child element.
9765
- - Values must follow the schema exactly (numbers, arrays, objects, enums copy as-is).
9766
+ - Values must follow the schema exactly (numbers, arrays, objects, enums -> copy as-is).
9766
9767
  - Do not add or remove functions or parameters.
9767
9768
  - Each required parameter must appear once.
9768
9769
  - Output nothing before or after the function call.
@@ -9778,7 +9779,7 @@ function morphXmlSystemPromptTemplate(tools) {
9778
9779
  multiple lines</example_parameter_2>
9779
9780
  </example_function_name>
9780
9781
  `;
9781
- return [header, definitions, rules, examples].join("\n\n");
9782
+ return [header, definitions, rules, examples, inputExamplesText].filter((section) => section.trim().length > 0).join("\n\n");
9782
9783
  }
9783
9784
  var INDENT = " ";
9784
9785
  function renderToolsForXmlPrompt(tools) {
@@ -9798,6 +9799,67 @@ function renderToolForXmlPrompt(tool) {
9798
9799
  lines.push(`schema: ${stringifySchema(normalizedSchema)}`);
9799
9800
  return lines.join("\n");
9800
9801
  }
9802
+ function getToolInputExamples(tool) {
9803
+ const inputExamples = tool.inputExamples;
9804
+ if (!Array.isArray(inputExamples)) {
9805
+ return [];
9806
+ }
9807
+ return inputExamples.filter(
9808
+ (example) => typeof example === "object" && example !== null && "input" in example && example.input !== void 0
9809
+ );
9810
+ }
9811
+ function safeStringifyInputExample(input, sourceError) {
9812
+ try {
9813
+ const serialized = JSON.stringify(input);
9814
+ return serialized != null ? serialized : "null";
9815
+ } catch (stringifyError) {
9816
+ let reason = "";
9817
+ if (sourceError instanceof Error) {
9818
+ reason = sourceError.message;
9819
+ } else if (stringifyError instanceof Error) {
9820
+ reason = stringifyError.message;
9821
+ }
9822
+ return reason.length > 0 ? `[unserializable input: ${reason}]` : "[unserializable input]";
9823
+ }
9824
+ }
9825
+ function renderMorphXmlInputExample(toolName, input) {
9826
+ try {
9827
+ return stringify2(toolName, input, {
9828
+ suppressEmptyNode: false,
9829
+ format: true,
9830
+ minimalEscaping: true
9831
+ });
9832
+ } catch (error) {
9833
+ const fallbackContent = safeStringifyInputExample(input, error);
9834
+ const escapedFallback = escapeXmlMinimalText(fallbackContent);
9835
+ return `<${toolName}>${escapedFallback}</${toolName}>`;
9836
+ }
9837
+ }
9838
+ function renderInputExamplesForXmlPrompt(tools) {
9839
+ const renderedTools = tools.map((tool) => {
9840
+ const inputExamples = getToolInputExamples(tool);
9841
+ if (inputExamples.length === 0) {
9842
+ return "";
9843
+ }
9844
+ const renderedExamples = inputExamples.map((example, index) => {
9845
+ const xml = renderMorphXmlInputExample(tool.name, example.input);
9846
+ return `Example ${index + 1}:
9847
+ ${xml}`;
9848
+ }).join("\n\n");
9849
+ return `Tool: ${tool.name}
9850
+ ${renderedExamples}`;
9851
+ }).filter((text) => text.length > 0).join("\n\n");
9852
+ if (renderedTools.length === 0) {
9853
+ return "";
9854
+ }
9855
+ return [
9856
+ "# Input Examples",
9857
+ "Treat these as canonical tool-call patterns.",
9858
+ "Reuse the closest structure and nesting, change only values, and do not invent parameters.",
9859
+ "Do not copy example values unless they match the user's request.",
9860
+ renderedTools
9861
+ ].join("\n\n");
9862
+ }
9801
9863
  function normalizeSchema(schema) {
9802
9864
  if (typeof schema === "string") {
9803
9865
  try {