const OPENCODE_HOST = "opencode.ai";
function matchesHost(baseUrl, expectedHost) {
    try {
        return new URL(baseUrl).hostname === expectedHost;
    }
    catch {
        return false;
    }
}
function getDefaultAttributionHeaders(_model, _settingsManager) {
    return undefined;
}
function getSessionHeaders(model, sessionId) {
    if (!sessionId)
        return undefined;
    if (model.provider !== "opencode" &&
        model.provider !== "opencode-go" &&
        !matchesHost(model.baseUrl, OPENCODE_HOST)) {
        return undefined;
    }
    return { "x-opencode-session": sessionId, "x-opencode-client": "pi" };
}
export function mergeProviderAttributionHeaders(model, settingsManager, sessionId, ...headerSources) {
    const merged = {
        ...getSessionHeaders(model, sessionId),
        ...getDefaultAttributionHeaders(model, settingsManager),
    };
    for (const headers of headerSources) {
        if (headers) {
            Object.assign(merged, headers);
        }
    }
    return Object.keys(merged).length > 0 ? merged : undefined;
}
//# sourceMappingURL=provider-attribution.js.map