@dev-fastn-ai/ucl-sdk
Version:
Fastn UCL SDK - A robust TypeScript SDK for integrating AI agents with Fastn UCL
79 lines (67 loc) • 3.03 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.PromptBuilder = void 0;
const misc_1 = require("../utils/misc");
class PromptBuilder {
static buildGenerateParametersPrompt(message, tool) {
return `
You are an expert assistant responsible for translating a user's natural language message into structured input for a specific tool.
User message:
${message}
Tool name:
${tool.function.name}
Tool description:
${tool.function.description}
Tool input schema (JSON Schema format):
${tool.function.parameters}
Your task:
- Carefully extract all available parameters from the user message that match the tool's input schema.
- Identify any **required** parameters from the schema that are **missing** in the message.
- Return a JSON object in the **exact format** described below.
Output format:
\`\`\`json
{
"parameters": {
// All parameters successfully extracted from the user message
},
"missingParameters": [
// Names of required parameters not found in the message
]
}
\`\`\`
Important rules:
- The \`parameters\` object must include only valid key-value pairs that conform to the tool’s schema.
- The \`missingParameters\` array must include names of any **required** parameters not found or not inferable from the message.
- If all required parameters are found, return an empty \`missingParameters\` array.
- If no parameters can be extracted, return an empty \`parameters\` object.
- The response must be a **valid JSON object** and contain **no additional commentary, explanation, or text**.
- Strictly follow the schema for parameter types and names — no deviations are allowed.
This task requires high precision. Output only the JSON object in the specified structure — nothing more, nothing less.
`.trim();
}
static prettifyExecuteToolResponse(message, response, tool, connector) {
return `
You are a conversational assistant.
Your job is to generate a natural, friendly, and helpful message that will be shown to the user in chat, based on the outcome of a tool execution.
Context:
- The user asked: "${message}"
- The tool used: "${tool.function.name}" — ${tool.function.description}
- The connector used: "${connector.name}"
- Tool execution result:
\`\`\`json
${(0, misc_1.safeStringify)(response)}
\`\`\`
Instructions:
- Write a clear, concise response that explains to the user what happened.
- If the tool executed successfully, summarize the result in a friendly tone.
- If there was an error, explain what went wrong in simple, polite language.
- Do **not** repeat the tool name or technical details unless necessary.
- Do **not** include any markdown, formatting, or additional explanation — just the plain message the user should see.
- Assume the user is non-technical, so keep the language simple and user-oriented.
Output:
Only return the final message that should be shown to the user in chat.
`.trim();
}
}
exports.PromptBuilder = PromptBuilder;
//# sourceMappingURL=prompt-builder.js.map