/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 * @generated-id: cb0c57ebeaea
 */
import { valueToBase64 } from "./shared.js";
// Optional function to assist with formatting tool results
export async function formatResult(response, uri, init) {
    let contents = [];
    const mimeType = init?.mimeType ?? response.headers.get("content-type") ?? "";
    if (mimeType.startsWith("image/") || mimeType.startsWith("audio/")) {
        const blob = await valueToBase64(await response.arrayBuffer());
        contents = blob == null ? [] : [{ uri: uri.toString(), blob, mimeType }];
    }
    else {
        const text = await response.text();
        contents = [{ uri: uri.toString(), mimeType, text }];
    }
    return { contents };
}
export function createRegisterResource(logger, server, getSDK, allowedScopes) {
    return (resource) => {
        const scopes = resource.scopes ?? [];
        if (allowedScopes.size > 0 && scopes.length === 0) {
            return;
        }
        if (allowedScopes.size > 0
            && !scopes.every((s) => allowedScopes.has(s))) {
            return;
        }
        const metadata = {
            ...resource.metadata,
            description: resource.description,
        };
        server.resource(resource.name, resource.resource, metadata, async (uri, ctx) => resource.read(getSDK(), uri, ctx));
        logger.debug("Registered resource", { name: resource.name });
    };
}
export function createRegisterResourceTemplate(logger, server, getSDK, allowedScopes) {
    return (resource) => {
        const scopes = resource.scopes ?? [];
        if (allowedScopes.size > 0 && scopes.length === 0) {
            return;
        }
        if (allowedScopes.size > 0
            && !scopes.every((s) => allowedScopes.has(s))) {
            return;
        }
        const metadata = {
            ...resource.metadata,
            description: resource.description,
        };
        server.resource(resource.name, resource.resource, metadata, async (uri, vars, ctx) => resource.read(getSDK(), uri, vars, ctx));
        logger.debug("Registered resource template", { name: resource.name });
    };
}
//# sourceMappingURL=resources.js.map