/**
 * Shared utilities for building API prompts in a consistent XML format.
 * Used by both the runtime prompt construction and example formatting.
 */
/**
 * Formats available integrations as a list
 */
function formatAvailableIntegrations(integrations) {
    if (integrations.length === 0) {
        return "";
    }
    return integrations
        .map((i) => `- ${i.displayName || i.name} (id: ${i.id}, type: ${i.type})`)
        .join("\n");
}
/**
 * Formats integration metadata as XML with JSON content.
 * This represents what the grepMetadata tool would return.
 */
function formatIntegrationMetadata(metadataList) {
    if (metadataList.length === 0) {
        return "";
    }
    return metadataList
        .map(({ integrationId, metadata, }) => `<integration_metadata integration_id="${integrationId}">
${JSON.stringify(metadata, null, 2)}
</integration_metadata>`)
        .join("\n\n");
}
/**
 * Builds the API prompt in standardized XML format.
 * This format is used consistently for both examples and runtime prompts.
 */
export function buildApiPrompt(input) {
    const { apiName, userPrompt, availableIntegrations = [], integrationMetadata = [], existingApiSource, missingIntegrationIds = [], isEdit = false, } = input;
    // Start with context about the task
    let prompt = isEdit
        ? "Edit the existing API based on the following requirements.\n\n"
        : "Create an API based on the following requirements.\n\n";
    prompt += `<api_request>
<api_name>${apiName}</api_name>

<inputs>If you need external inputs or parameters for dynamic behavior, the user will supply them when calling this API at runtime.</inputs>`;
    // Add available integrations if any
    if (availableIntegrations.length > 0) {
        prompt += `
<available_integrations>
The following integration configurations were provided explicitly by the user:
${formatAvailableIntegrations(availableIntegrations)}
</available_integrations>`;
    }
    // Add user prompt
    prompt += `
<user_prompt>
${userPrompt}
</user_prompt>`;
    // Add existing API source if editing
    if (existingApiSource) {
        prompt += `
<existing_api_source>
\`\`\`typescript
${existingApiSource}
\`\`\`
</existing_api_source>`;
    }
    // Add missing integrations warning if any
    if (missingIntegrationIds.length > 0) {
        prompt += `
<missing_integration_configurations>
The existing API references the following integration configurations by ID, but they are missing from the context provided by the user:
${missingIntegrationIds.map((id) => `- id: ${id}`).join("\n")}
</missing_integration_configurations>`;
    }
    prompt += `
</api_request>`;
    // Add additional context with integration metadata if available
    if (integrationMetadata.length > 0) {
        prompt += `

<additional_context>
The following integration metadata is available (as would be returned by the grepMetadata tool):

${formatIntegrationMetadata(integrationMetadata)}
</additional_context>`;
    }
    prompt += `

CRITICAL: DO NOT ADD COMMENTS TO THE API SOURCE CODE.`;
    if (existingApiSource) {
        prompt += `\nCRITICAL: You must NOT change the API name when editing an existing API.`;
    }
    return prompt;
}
//# sourceMappingURL=prompt-builder.js.map