@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/{chunk-722D5BGD.js → chunk-X3NZ2YHV.js} +65 -3
- package/dist/{chunk-722D5BGD.js.map → chunk-X3NZ2YHV.js.map} +1 -1
- package/dist/community.cjs +4611 -4549
- package/dist/community.cjs.map +1 -1
- package/dist/community.js +1 -1
- package/dist/index.cjs +64 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +1 -1
- package/package.json +3 -3
|
@@ -6054,6 +6054,7 @@ For each function call return a json object with function name and arguments wit
|
|
|
6054
6054
|
import dedent from "dedent";
|
|
6055
6055
|
function morphXmlSystemPromptTemplate(tools) {
|
|
6056
6056
|
const toolsText = renderToolsForXmlPrompt(tools);
|
|
6057
|
+
const inputExamplesText = renderInputExamplesForXmlPrompt(tools);
|
|
6057
6058
|
const header = dedent`
|
|
6058
6059
|
# Tools
|
|
6059
6060
|
You may call one or more functions to assist with the user query.
|
|
@@ -6068,7 +6069,7 @@ function morphXmlSystemPromptTemplate(tools) {
|
|
|
6068
6069
|
<rules>
|
|
6069
6070
|
- Use exactly one XML element whose tag name is the function name.
|
|
6070
6071
|
- Put each parameter as a child element.
|
|
6071
|
-
- Values must follow the schema exactly (numbers, arrays, objects, enums
|
|
6072
|
+
- Values must follow the schema exactly (numbers, arrays, objects, enums -> copy as-is).
|
|
6072
6073
|
- Do not add or remove functions or parameters.
|
|
6073
6074
|
- Each required parameter must appear once.
|
|
6074
6075
|
- Output nothing before or after the function call.
|
|
@@ -6084,7 +6085,7 @@ function morphXmlSystemPromptTemplate(tools) {
|
|
|
6084
6085
|
multiple lines</example_parameter_2>
|
|
6085
6086
|
</example_function_name>
|
|
6086
6087
|
`;
|
|
6087
|
-
return [header, definitions, rules, examples].join("\n\n");
|
|
6088
|
+
return [header, definitions, rules, examples, inputExamplesText].filter((section) => section.trim().length > 0).join("\n\n");
|
|
6088
6089
|
}
|
|
6089
6090
|
var INDENT = " ";
|
|
6090
6091
|
function renderToolsForXmlPrompt(tools) {
|
|
@@ -6104,6 +6105,67 @@ function renderToolForXmlPrompt(tool) {
|
|
|
6104
6105
|
lines.push(`schema: ${stringifySchema(normalizedSchema)}`);
|
|
6105
6106
|
return lines.join("\n");
|
|
6106
6107
|
}
|
|
6108
|
+
function getToolInputExamples(tool) {
|
|
6109
|
+
const inputExamples = tool.inputExamples;
|
|
6110
|
+
if (!Array.isArray(inputExamples)) {
|
|
6111
|
+
return [];
|
|
6112
|
+
}
|
|
6113
|
+
return inputExamples.filter(
|
|
6114
|
+
(example) => typeof example === "object" && example !== null && "input" in example && example.input !== void 0
|
|
6115
|
+
);
|
|
6116
|
+
}
|
|
6117
|
+
function safeStringifyInputExample(input, sourceError) {
|
|
6118
|
+
try {
|
|
6119
|
+
const serialized = JSON.stringify(input);
|
|
6120
|
+
return serialized != null ? serialized : "null";
|
|
6121
|
+
} catch (stringifyError) {
|
|
6122
|
+
let reason = "";
|
|
6123
|
+
if (sourceError instanceof Error) {
|
|
6124
|
+
reason = sourceError.message;
|
|
6125
|
+
} else if (stringifyError instanceof Error) {
|
|
6126
|
+
reason = stringifyError.message;
|
|
6127
|
+
}
|
|
6128
|
+
return reason.length > 0 ? `[unserializable input: ${reason}]` : "[unserializable input]";
|
|
6129
|
+
}
|
|
6130
|
+
}
|
|
6131
|
+
function renderMorphXmlInputExample(toolName, input) {
|
|
6132
|
+
try {
|
|
6133
|
+
return stringify(toolName, input, {
|
|
6134
|
+
suppressEmptyNode: false,
|
|
6135
|
+
format: true,
|
|
6136
|
+
minimalEscaping: true
|
|
6137
|
+
});
|
|
6138
|
+
} catch (error) {
|
|
6139
|
+
const fallbackContent = safeStringifyInputExample(input, error);
|
|
6140
|
+
const escapedFallback = escapeXmlMinimalText(fallbackContent);
|
|
6141
|
+
return `<${toolName}>${escapedFallback}</${toolName}>`;
|
|
6142
|
+
}
|
|
6143
|
+
}
|
|
6144
|
+
function renderInputExamplesForXmlPrompt(tools) {
|
|
6145
|
+
const renderedTools = tools.map((tool) => {
|
|
6146
|
+
const inputExamples = getToolInputExamples(tool);
|
|
6147
|
+
if (inputExamples.length === 0) {
|
|
6148
|
+
return "";
|
|
6149
|
+
}
|
|
6150
|
+
const renderedExamples = inputExamples.map((example, index) => {
|
|
6151
|
+
const xml = renderMorphXmlInputExample(tool.name, example.input);
|
|
6152
|
+
return `Example ${index + 1}:
|
|
6153
|
+
${xml}`;
|
|
6154
|
+
}).join("\n\n");
|
|
6155
|
+
return `Tool: ${tool.name}
|
|
6156
|
+
${renderedExamples}`;
|
|
6157
|
+
}).filter((text) => text.length > 0).join("\n\n");
|
|
6158
|
+
if (renderedTools.length === 0) {
|
|
6159
|
+
return "";
|
|
6160
|
+
}
|
|
6161
|
+
return [
|
|
6162
|
+
"# Input Examples",
|
|
6163
|
+
"Treat these as canonical tool-call patterns.",
|
|
6164
|
+
"Reuse the closest structure and nesting, change only values, and do not invent parameters.",
|
|
6165
|
+
"Do not copy example values unless they match the user's request.",
|
|
6166
|
+
renderedTools
|
|
6167
|
+
].join("\n\n");
|
|
6168
|
+
}
|
|
6107
6169
|
function normalizeSchema(schema) {
|
|
6108
6170
|
if (typeof schema === "string") {
|
|
6109
6171
|
try {
|
|
@@ -7155,4 +7217,4 @@ export {
|
|
|
7155
7217
|
morphXmlToolMiddleware,
|
|
7156
7218
|
yamlXmlToolMiddleware
|
|
7157
7219
|
};
|
|
7158
|
-
//# sourceMappingURL=chunk-
|
|
7220
|
+
//# sourceMappingURL=chunk-X3NZ2YHV.js.map
|